day21UI自动化.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() 方法名
//添加testng 注解用来执行测试方法
@Test
public void login(){
//打开登录网页
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("guoya888");
//查找元素根据id查找 然后执行清除
driver.findElement(By.id("password")).clear();
//查找元素根据id查找 执行输入
driver.findElement(By.id("password")).sendKeys("qweasd");
//查找元素根据xpath查找验证码 执行输入
driver.findElement(By.xpath("//input[@name='checkCode']")).sendKeys("12345");
//查找元素根据xpath查找 点击注册
driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
}
@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("guoya434");
driver.findElement(By.id("realName")).sendKeys("黄哈哈");
driver.findElement(By.id("password")).sendKeys("qweasd");
driver.findElement(By.id("password2")).sendKeys("qweasd");
driver.findElement(By.id("phone")).sendKeys("18916968152");
driver.findElement(By.id("age")).sendKeys("20");
driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
//点击注册
driver.findElement(By.xpath("//input[@id='submitBtn']")).click();
//弹出弹窗 是否确定
Alert alert=driver.switchTo().alert();
alert.accept();
alert.dismiss();
}
}