
在線導(dǎo)入

image.png

image.png

image.png
工程操作

image.png
新建方法使用

image.png

testNG
GuoyaLogin
package com.guoyasoft.autoUI.guoya_1810;//引入java代碼路徑
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
public class GuoyaLogin extends BaseUI {
//publie 公開的方法 void 無返回 login()方法名
//添加testng注解用來執(zhí)行測試方法
@Test
public void login() {
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
sleep(1000);//添加等待時(shí)間
driver.findElement(By.name("userName")).clear();//查找元素根據(jù)name查找 然后執(zhí)行清除
driver.findElement(By.name("userName")).sendKeys("chen952");//查找元素根據(jù)name查找 然后執(zhí)行輸入
sleep(1000);
driver.findElement(By.id("password")).clear();//查找元素根據(jù)id查找 然后執(zhí)行清除
driver.findElement(By.id("password")).sendKeys("qweasd");//查找元素根據(jù)id查找 然后執(zhí)行輸入
sleep(1000);
driver.findElement(By.xpath("http://input[@id='checkCode']")).sendKeys("12345");//根據(jù)xpath查找元素 執(zhí)行輸入
sleep(1000);
driver.findElement(By.xpath("http://input[@id='loginBtn']")).click();//根據(jù)xpath查找元素 執(zhí)行輸入
}
@Test
public void signup() {
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/signUp.jsp");
sleep(1000);//添加等待時(shí)間
driver.findElement(By.name("userName")).clear();//查找元素根據(jù)name查找 然后執(zhí)行清除
driver.findElement(By.name("userName")).sendKeys("chen952");//查找元素根據(jù)name查找 然后執(zhí)行輸入
sleep(1000);
driver.findElement(By.xpath("http://input[@id='realName']")).sendKeys("比汗");//查找元素根據(jù)name查找 然后執(zhí)行輸入
sleep(1000);
driver.findElement(By.xpath("http://input[@id='password']")).sendKeys("qweasd");
sleep(1000);
//查找元素根據(jù)name查找 然后執(zhí)行輸入
driver.findElement(By.xpath("http://input[@id='password2']")).sendKeys("qweasd");
sleep(1000);
//查找元素根據(jù)name查找 然后執(zhí)行輸入
driver.findElement(By.xpath("http://input[@id='phone']")).sendKeys("15185201479");
sleep(1000);
//查找元素根據(jù)name查找 然后執(zhí)行輸入
driver.findElement(By.xpath("http://input[@id='age']")).sendKeys("22");
sleep(1000);
//查找元素根據(jù)name查找 然后執(zhí)行輸入
driver.findElement(By.xpath("http://input[@id='checkCode']")).sendKeys("1234");
sleep(1000);
//查找元素根據(jù)name查找 然后執(zhí)行輸入
driver.findElement(By.xpath("http://input[@id='submitBtn']")).click();
sleep(1000);
driver.switchTo().alert().accept();
}
}
GuoyaLogin.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="chendj">
<test name="test0" preserve-order="true" enabled="true">
<classes>
<class name="com.guoyasoft.autoUI.guoya_1810.GuoyaLogin">
<methods>
<include name="signup" />
<include name="login" />
</methods>
</class>
</classes>
</test>
</suite>