首页 > Web开发 > 详细

selenium WebDriver:使用TestNG进行数据驱动

时间:2015-12-07 20:26:08      阅读:429      评论:0      收藏:0      [点我收藏+]

如下为结合testNG进行的数据驱动测试

package cn.gloryroad;

import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;

public class DataProviderTest {

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.ie.driver", "D:\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
//设定等待时间10s
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String baseUrl = "http://www.baidu.com/";
Navigation navigation = driver.navigate();
navigation.to("http://www.baidu.com");
driver.findElement(By.id("kw")).sendKeys(searchWord1+""+searchWord2);
driver.findElement(By.id("su")).click();

//等待三秒显示搜索结果
try{
Thread.sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}

//判断搜索结果的页面是否包含测试数据中期望的关键字
Assert.assertTrue(driver.getPageSource().contains(SearchResult));
driver.quit();
}


}

selenium WebDriver:使用TestNG进行数据驱动

原文:http://www.cnblogs.com/Treasa/p/5027106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!