1. 数组的方式
package main.java.com.hx.base;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestArray {
private static WebDriver driver;
@DataProvider(name="searchWords")
public static Object[][] words(){
return new Object[][]{{"蝙蝠侠","主演","迈克尔"},{"超人","导演","唐纳"},{"生化危机","编剧","安德森"}};
}
@Test(dataProvider = "searchWords")
public void test(String searchWord1, String searchWord2, String SearchResult){
System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.sogou.com");
driver.findElement(By.id("query")).sendKeys(searchWord1+" "+searchWord2);
driver.findElement(By.id("stb")).click();
try{
Thread.sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}
Assert.assertTrue(driver.getPageSource().contains(SearchResult));
driver.quit();
}
}
2. csv 的格式
本文详细介绍了使用Selenium WebDriver与TestNG框架进行自动化测试的方法,通过实例展示了如何运用动态数据驱动测试策略,特别是针对电影角色信息搜索场景的实现。文章涵盖了配置FirefoxDriver、设置隐式等待、页面元素定位、输入动态搜索词及结果验证等关键步骤。
4072

被折叠的 条评论
为什么被折叠?



