day22UI自动化2.png
package com.guoyasoft.autoUI.guoya_1810;
//引入 java代码路径
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
public class GuoyaLogin extends BaseUI {
//public 公开的方法 void 无返回 login() 方法名
//实例变量/全局变量 或者用private私有的
public String username="guoya698";
public String password="qweasd";
public String realname="黄哈哈";
public String phone="18916968152";
public String age="25";
public String users []={
"ye008",
"ye007",
"ye006",
"ye005",
"ye004",
"ye003",
"ye002",
"ye001",
"ye000",
"ye009"};
//添加testng 注解用来执行测试方法
@Test
public void login(){
//设置循坏 起始值,最大值/最小值 增量,减量
for(int i=9; i>=6;i-- ) {
System.out.println("当前循环次数" + i);
sleep(1000);
//打开登录网页
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
//线程休眠
sleep(1000);
//查找元素根据name查找 然后执行清除
driver.findElement(By.name("userName")).clear();
//查找元素根据name查找 执行输入
driver.findElement(By.name("userName")).sendKeys(users[i]);
//查找元素根据id查找 然后执行清除
driver.findElement(By.id("password")).clear();
//查找元素根据id查找 执行输入
driver.findElement(By.id("password")).sendKeys(password);
//查找元素根据xpath查找验证码 执行输入
driver.findElement(By.xpath("//input[@name='checkCode']")).sendKeys("12345");
//查找元素根据xpath查找 点击注册
driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
//queryalluser();
//调用自定义方法
//queryuser();
//queryage();
}
}
@Test
public void signup(){
//打开注册网页
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/signUp.jsp");
sleep(1000);
WebElement element=driver.findElement(By.id("userName"));
element.clear();
element.sendKeys(username);
driver.findElement(By.id("realName")).sendKeys(realname);
driver.findElement(By.id("password")).sendKeys(password);
boolean result=driver.getPageSource().contains("登录界面");
//如果条件为真 打印注册成功
if(result==true){
System.out.println("用户注册成功");
//否则就是注册失败
}else{
System.out.println("用户注册失败");
}
}
//全部查询
public void queryalluser(){
driver.findElement(By.xpath("//input[@type='submit']")).click();
sleep(3000);
}
public void queryuser(){
driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(username);
driver.findElement(By.xpath("//input[@type='submit']")).click();
sleep(3000);
}
public void queryage(){
driver.findElement(By.xpath("//input[@name='userName']")).clear();
driver.findElement(By.xpath("(//input[@type='number'])[1]")).sendKeys(age);
driver.findElement(By.xpath("(//input[@type='submit'])")).click();
sleep(3000);
}
}