Webdriver 自動(dòng)化測(cè)試初試
之前已經(jīng)搭建了測(cè)試需要的環(huán)境,也學(xué)習(xí)了locateelements的方法,下面我們就來創(chuàng)建第一個(gè)簡(jiǎn)單的自動(dòng)化測(cè)試用例。
測(cè)試場(chǎng)景如下:
1.打開百度首頁
2.在搜索框輸入關(guān)鍵字搜索,比如:webdriverautomationtesting
3.點(diǎn)擊百度一下button
4.驗(yàn)證搜索結(jié)果是否包含輸入的關(guān)鍵字
用例自動(dòng)化測(cè)試代碼實(shí)例如下:
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; @BeforeMethod publicvoidsetUp()throwsException{ //LaunchFirefoxbrowser driver=newFirefoxDriver(); baseUrl="http://www.baidu.com"; } @Test publicvoidbaiDuSearchTest()throwsException{ StringexResult="WebDriverautomationtesting"; //Open百度homepage driver.get(baseUrl); //Locatesearchboxandinputsearchkeyword driver.findElement(By.id("kw1")).sendKeys("WebDriverautomationtesting"); //Click百度一下button driver.findElement(By.id("su1")).click(); //在結(jié)果頁面找到第一個(gè)link并驗(yàn)證搜索關(guān)鍵字顯示在鏈接中 StringactResult=driver.findElement(By.id("1")).getText(); Assert.assertTrue(actResult.contains(exResult)); } @AfterMethod publicvoidtearDown()throwsException{ driver.quit(); } } |
最簡(jiǎn)單的一個(gè)測(cè)試用例就到這里了。是不是很easy?
posted on 2014-06-18 10:46 順其自然EVO 閱讀(270) 評(píng)論(0) 編輯 收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測(cè)試學(xué)習(xí)