首页 测试 体会 查看内容

Webdriver 自动化测试初试

2014-6-25 14:32| 发布者: tianzc| 查看: 498| 评论: 0

摘要:   之前已经搭建了测试需要的环境,也学习了locateelements的方法,下面我们就来创建第一个简单的自动化测试用例。  测试场景如下:  1.打开百度首页  2.在搜索框输入关键字搜索,比如:webdriverautomationt ...
packagecom.example.tests;importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.testng.Assert;importorg.testng.annotations.AfterMethod;importorg.testng.annotations.BeforeMethod;importorg.testng.annotations.Test;publicclassBaiDuSearchTest{privateWebDriverdriver;privateStringbaseUrl;@BeforeMethodpublicvoidsetUp()throwsException{//LaunchFirefoxbrowserdriver=newFirefoxDriver();baseUrl="http://www.baidu.com";}@TestpublicvoidbaiDuSearchTest()throwsException{StringexResult="WebDriverautomationtesting";//Open百度homepagedriver.get(baseUrl);//Locatesearchboxandinputsearchkeyworddriver.findElement(By.id("kw1")).sendKeys("WebDriverautomationtesting");//Click百度一下buttondriver.findElement(By.id("su1")).click();//在结果页面找到第一个link并验证搜索关键字显示在链接中StringactResult=driver.findElement(By.id("1")).getText();Assert.assertTrue(actResult.contains(exResult));}@AfterMethodpublicvoidtearDown()throwsException{driver.quit();}}  然后直接右击该java文件选择runasTestNGtest,然后可以查看自动化测试用例的执行了。  最简单的一个测试用例就到这里了。是不是很easy?
  之前已经搭建了测试需要的环境,也学习了locateelements的方法,下面我们就来创建第一个简单的自动化测试用例。  测试场景如下:  1.打开百度首页  2.在搜索框输入关键字搜索,比如:webdriverautomationtesting  3.点击百度一下button  4.验证搜索结果是否包含输入的关键字  用例自动化测试代码实例如下:

鲜花

握手

雷人

路过

鸡蛋

扫一扫关注最新动态

毒镜头:老镜头、摄影器材资料库、老镜头样片、摄影
爱评测 aipingce.com  
返回顶部