测试实训之UI自动化


一、学习目标

巩固今天实训学习的UI自动化。

二、学习内容

1、工具准备

(1)webDriver的下载(百度搜索,选择下载与谷歌浏览器对应的版本),并解压到如图所示路径即系统的System32下。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
(2)lib包解压。
在这里插入图片描述
(3)打开Eclipse,创建项目,导入lib下的jar包。
在这里插入图片描述

2、基本讲解——自动打开网页

(1)举例:打开百度界面。
在这里插入图片描述

import org.openqa.selenium.chrome.ChromeDriver;;

public class demo1{
	public static void main(String args[]){
		//System.out.print("test!");
		ChromeDriver bs = new ChromeDriver();
		bs.get("https://www.baidu.com");
	}
}

3、元素定位方式

(1)采用id
举例:搜索“福州美食”后关闭网页。
在这里插入图片描述

//20210314测试

import org.openqa.selenium.chrome.ChromeDriver;;

public class demo1{
	public static void main(String args[]) throws InterruptedException{
		//System.out.print("test!");
		ChromeDriver bs = new ChromeDriver();
		bs.get("https://www.baidu.com");
		bs.manage().window().maximize();//窗口最大化
		Thread.sleep(3000);//延迟让自动化更清晰,main后 throws InterruptedException就是增加延时抛出的异常
		bs.findElementById("kw").sendKeys("福州美食");//搜索内容
		bs.findElementById("su").click();//点击一下
		Thread.sleep(3000);
		bs.navigate().back();//回退
	}
}

(2)采用name
举例:同上。

//20210314测试

import org.openqa.selenium.chrome.ChromeDriver;;

public class demo1{
	public static void main(String args[]) throws InterruptedException{
		//System.out.print("test!");
		ChromeDriver bs = new ChromeDriver();
		bs.get("https://www.baidu.com");
		bs.manage().window().maximize();//窗口最大化
		Thread.sleep(3000);//延迟让自动化更清晰,main后 throws InterruptedException就是增加延时抛出的异常
		
		//这里是ByName
		bs.findElementByName("wd").sendKeys("福州美食");//搜索内容
		
		bs.findElementById("su").click();//点击一下
		Thread.sleep(3000);
		bs.navigate().back();//回退
	}
}

(3)采用LinkText
以百度一下的新闻为例,语句如下。
在这里插入图片描述

//通过链接文本获取
bs.findElementByLinkText("新闻").click();

(4)采用ClassName

//语句如下
bs.findElementByClassName("").click();

(5)采用XPath

//语句如下,从网页复制过来的Xpath为//*[@id="J_register_form"]/div/dl[5]/dd/button
//需要给Xpath的id=后加\ 元素id结束后加\ 
bs.findElementByXPath("//*[@id=\"J_register_form\"]/div/dl[5]/dd/button").click();

4、自动化注册、登录测试脚本

前提:结合PHPWind-Wamp-5.0实现,若有安装需求可看第五点。(也可以自己利用类似工具测试自动化脚本。)
(1)登录: 利用开发者工具找到元素(用户名、密码、登录)id;默认用户名admin、密码123456。
在这里插入图片描述

//20210314自动登录脚本

import org.openqa.selenium.chrome.ChromeDriver;;

public class demo2{
	public static void main(String args[]) throws InterruptedException{
		//System.out.print("test!");
		ChromeDriver bs = new ChromeDriver();
		bs.get("http://localhost/phpwind/index.php");
		bs.manage().window().maximize();//窗口最大化
		Thread.sleep(3000);//延迟让自动化更清晰,main后 throws InterruptedException就是增加延时抛出的异常
		
		bs.findElementById("J_username").sendKeys("admin");
		bs.findElementById("J_password").sendKeys("123456");
		Thread.sleep(3000);
		bs.findElementById("J_sidebar_login").click();
	
	}
}

(2)注册:和登录一样的道理。
在这里插入图片描述

//20210314自动注册脚本

import org.openqa.selenium.chrome.ChromeDriver;;

public class demo3{
	public static void main(String args[]) throws InterruptedException{
		//System.out.print("test!");
		ChromeDriver bs = new ChromeDriver();
		bs.get("http://localhost/phpwind/index.php");
		bs.manage().window().maximize();//窗口最大化
		Thread.sleep(3000);//延迟让自动化更清晰,main后 throws InterruptedException就是增加延时抛出的异常
		
		bs.findElementByXPath("//*[@id=\"J_login_form\"]/dl/dd[2]/a").click();
		bs.findElementById("J_reg_username").sendKeys("HTY");
		bs.findElementById("J_reg_password").sendKeys("123456");
		bs.findElementById("J_reg_repassword").sendKeys("123456");
		bs.findElementById("J_reg_email").sendKeys("1751014095@qq.com");
		
		Thread.sleep(3000);
		bs.findElementByXPath("//*[@id=\"J_register_form\"]/div/dl[5]/dd/button").click();
	
	}
}

5、安装PHPWind-Wamp-5.0

在这里插入图片描述
(1)关闭所有与apache、mysql有关的服务。
请添加图片描述
在这里插入图片描述
(2)解压PHPWind-Wamp-5.0,双击运行。或者打开安装路径点击install.bat运行。
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
简单配置: 1、设置phpmyadmin 在WampServer安装完成后,通过http://localhost/打开后可以看到WampServer自带的一个简单的页面,里面有phpinfo、phpmyadmin和sqlitemanager三个工具。 打开phpmyadmin会在下方看到提示,root用户没有设置密码,我们先为root帐户设置密码。点击phpmyadmin页面中部的“权限”,可以看到“用户一览”,这时候应该只有一行用户信息,即root localhost这一行,点击这一行最右侧的编辑权限图标,在新页面找到“更改密码”,为root用户设置密码,并点击“执行”。 然后刷新页面,会看到错误提示,这是因为帐户已经设置密码,到WampServer程序安装目录,在apps目录找到phpmyadmin的目录,打开phpmyadmin目录里面的config.inc.php文件,找到下面这一行: $cfg['Servers'][$i]['password'] = ''; 在等号右面的单引号里面输入刚才设置的密码,重新打开phpmyadmin的页面并刷新,这时候phpmyadmin就可以正常访问了。 好了,我已经用WampServer简单的架设起一个Apache + PHP + MySQL的服务器了。 ----------------------------------------------------------- 2、允许外网访问: wamp 默认是禁止外网访问APACHE的,左键点击右下的wamp图标Apache - httpd.conf ,搜索关键字 "deny from ",会发现一处 "deny from"将其下的一行"Allow from 127.0.0.1" 之前加一个 #号,表示注释掉,新插入一行,手动输入Allow from all 。保存,重新启动下apache 服务就可以允许外网访问了。 3、apache, mysql 服务的开机自动运行 Windows - 开始? - 设置 - 控制面板 - 管理工具 - 服务,找到 wampmysqld, wampapache, 将 "启动类型" 由"手动" 改为"自动" 即可。 4、开启支持rewrite module #LoadModule rewrite_module modules/mod_rewrite.so 去前面掉#,修改为 LoadModule rewrite_module modules/mod_rewrite.so Options FollowSymLinks AllowOverride None # 修改为AllowOverride All # Order deny,allow Deny from all Satisfy all # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # 修改为AllowOverride All # # # Controls who can get stuff from this server. # Order allow,deny Allow
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值