参数化
parameter
-
数据与脚本分离,执行xml文件.
项目变更脚本不需要动,只修改数据即可 - 通过
@paratroopers
注解传参
数据
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suit1">
<test name="test0" enabled="true">
<parameter name="username" value="guoya888"></parameter>
<parameter name="password" value="qweasd"></parameter>
<parameter name="realname" value="狴犴"></parameter>
<parameter name="url" value="http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp"></parameter>
<classes>
<class name="com.guoyasoft.autoUI.guoya_1810.parameter">
<methods>
<include name="parameter" />
</methods>
</class>
</classes>
</test>
</suite>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
脚本
package com.guoyasoft.autoUI.guoya_1810;
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.By;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class parameter extends BaseUI {
@Test
@Parameters({"url","username","password","realname"})
public void parameter(String url,String username,String password,String realname){
//"http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp"
driver.get(url);
driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(username);
driver.findElement(By.xpath("//input[@name='password']")).sendKeys(password);
driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
driver.findElement(By.name("realName")).clear();
driver.findElement(By.name("realName")).sendKeys(realname);
driver.findElement(By.xpath("//input[@value='查询']")).click();
}
}