Installing the Seleniumide Plugin
Open Fire Fox Browser
Click Add-ons
Search Selenium IDE Later
Installation
installation, you can complete the installation of selenium
Record Export Scripts
Open Seleniumide,
After entering the Web page, fill in the information to the appropriate location and click OK.
We found that the recording was completed and the file->export test case as-java/junit4 webdriver to get the corresponding Java file
Writing test Code
Import Java.io.file;import Java.nio.charset.charset;import org.openqa.selenium.by;import Org.openqa.selenium.webdriver;importStaticorg.junit.assert.*; import Org.openqa.selenium.webelement;import Org.openqa.selenium.chrome.chromedriver;import Org.openqa.selenium.firefox.firefoxdriver;import Org.openqa.selenium.ie.internetexplorerdriver;import Org.openqa.selenium.remote.desiredcapabilities;import Com.csvreader.CsvReader; Public classTest {StaticThread th =NewThread (); Public Static voidMain (string[] args) throws Exception {Webdriver driver=NewFirefoxdriver (); Csvreader R=NewCsvreader ("D://info.csv",',', Charset.forname ("Utf-8")); R.readheaders (); while(R.readrecord ()) {String name= R.Get("ID"); String Password= Name.substring (4); String Email= R.Get("e-Mail"); Driver.Get("http://www.ncfxy.com/"); Th.sleep ( -); Webelement Txtbox1= Driver.findelement (By.id ("name")); Txtbox1.sendkeys (name); Webelement Txtbox2= Driver.findelement (By.id ("pwd")); Txtbox2.sendkeys (password); Webelement btn= Driver.findelement (By.id ("Submit")); Btn.click (); Th.sleep ( -); Webelement text= Driver.findelement (By.cssselector ("#table-main tr:first-child td:last-child")); String Email2=Text.gettext (); Assertequals (EMAIL,EMAIL2); } r.close (); }}
There are some unexplained reasons for the local running speed, which causes the problem of not finding elements if the code is run directly, set a new thread each time sleep100ms.
To judge Info.csv, here changed the info.csv in order to cooperate with Csvreader
Add header ID and e-mail to remove the number and mailbox.
After the completion of the test to find all passed, to complete this task.
All Code Engineering Files:
Https://github.com/FomalhautYWT/SoftwareTest/tree/master/STLab2
Software testing LAB2 Selenium and automated testing