In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Now that you have set up the environment for testing and learned the methods of locate elements, let's create the first simple automated test case.
The test scenario is as follows:
1. Open Baidu home page
two。 Enter keywords in the search box, such as: webdriver automation testing
3. Click on Baidu button
4. Verify that the search results contain the keywords entered
An example of use case automated test code is as follows:
Package com.example.tests
Import org.openqa.selenium.By
Import org.openqa.selenium.WebDriver
Import org.openqa.selenium.firefox.FirefoxDriver
Import org.testng.Assert
Import org.testng.annotations.AfterMethod
Import org.testng.annotations.BeforeMethod
Import org.testng.annotations.Test
Public class BaiDuSearchTest {
Private WebDriver driver
Private String baseUrl
@ BeforeMethod
Public void setUp () throws Exception {
/ / Launch Firefox browser
Driver = new FirefoxDriver ()
BaseUrl = "http://www.baidu.com";
}
@ Test
Public void baiDuSearchTest () throws Exception {
String exResult= "WebDriver automation testing"
/ / Open Baidu home page
Driver.get (baseUrl)
/ / Locate search box and input search keyword
Driver.findElement (By.id ("kw1")) .sendKeys ("WebDriver automation testing")
/ / Click Baidu button
Driver.findElement (By.id (su1)) .click ()
/ / find the first link on the results page and verify that the search keyword is displayed in the link
String actResult=driver.findElement (By.id ("1")) .getText ()
Assert.assertTrue (actResult.contains (exResult))
}
@ AfterMethod
Public void tearDown () throws Exception {
Driver.quit ()
}
}
Then right-click the java file and select run as TestNG test, and then you can view the execution of the automated test case.
This is the end of the simplest test case. Is it very easy?
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.