???????????????????????????????locateelements?????????????????????????????????????????????
??????????????£?
????1.????????
????2.?????????????????????????磺webdriverautomationtesting
????3.?????????button
????4.?????????????????????????
??????????????????????????£?

 

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();
//???????????????link?????????????????????????
StringactResult=driver.findElement(By.id("1")).getText();
Assert.assertTrue(actResult.contains(exResult));
}
@AfterMethod
publicvoidtearDown()throwsException{
driver.quit();
}
}

???????????????java??????runasTestNGtest??????????????????????????????
??????????????????????????????????easy??