This time we mainly use Selenium for automated testing , First we need to download Selenium-java dependencies.
If you are using MAVEN to manage your project, include the following dependencies in the. Pom File:
<dependency><groupid>org.seleniumhq.selenium</groupid><artifactid>selenium-java</ Artifactid><version>2.53.0</version></dependency>
You can also download the jar package manually, you can download the above-mentioned website, and don't repeat it here.
Here's what we're experimenting with:
First, the purpose of the experiment
- Installing the Seleniumide Plugin
- Learn to use Seleniumide to record scripts and export scripts
- Access http://www.ncfxy.com Use the number login system (account name is the school number, the password is the number 6), after entering the system can see the user's mailbox.
- Write the Selenium Java webdriver program to test the correct relationship between the number and the mailbox in the Info.csv table.
Second, Java Webdriver code:
Package Lesson1;import static Org.junit.assert.*;import Java.util.concurrent.timeunit;import Org.junit.*;import Org.openqa.selenium.by;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.firefox.firefoxdriver;import Org.openqa.selenium.support.ui.expectedcondition;import Org.openqa.selenium.support.ui.webdriverwait;import Java.io.File; Import Java.io.FileInputStream; Import Java.io.ioexception;import Java.io.InputStream; Import JXL. Cell; Import JXL. Celltype; Import JXL. Sheet; Import JXL. Workbook; Import Jxl.write.Label; public class Exampleforfirefox {private Webdriver driver; Private String baseUrl; @Before public void SetUp () throws Exception {driver = new firefoxdriver (); BASEURL = "http://www.ncfxy.com/"; Driver.manage (). Timeouts (). implicitlywait (Timeunit.seconds); } @Test public void Test1 () throws Exception {Jxl. Workbook READWB = null; Build Workbook object, read-only Workbook object//create directly from local fileWorkbook InputStream instream = new FileInputStream ("D:/info.xls"); READWB = Workbook.getworkbook (instream); System.out.println ("JJJJJJJ"); Sheet subscript is starting from 0//Get the first Sheet table Sheet readsheet = readwb.getsheet (0); Gets the total number of columns contained in the sheet table int rscolumns = Readsheet.getcolumns (); Gets the total number of rows contained in the sheet table int rsrows = Readsheet.getrows (); Gets the object reference for the specified cell for (int i = 0; I <rsRows; i++) {driver.get (BASEURL); Cell cell = Readsheet.getcell (0, I); String username = cell.getcontents (); String Password = username.substring (4, 10); Find the DOM webelement element = driver.findelement (by.id ("name") of input via ID; Webelement element1 = driver.findelement (by.id ("pwd")); System.out.println (Element.getsize ()); Enter the keyword Element.sendkeys (username); Element1.sendkeys (passworD); Submit the Form element.submit () where input is located; Get the resulting mailbox webelement Element2 = driver.findelement (By.xpath ("//td[2]")); String mailbyweb = Element2.gettext (); String mailbyinfo = Readsheet.getcell (1,i). getcontents (); Assertequals (Mailbyinfo,mailbyweb); System.out.println (Element2.gettext ()); System.out.println (); }/*//Use the Excel workbook you have created to create a new writable Excel workbook Jxl.write.WritableWorkbook WWB = Workbook.createworkboo K (New File ("D:/info.xls"), READWB); Read the first sheet jxl.write.WritableSheet ws = Wwb.getsheet (0); Get the first Cell object Jxl.write.WritableCell WC = Ws.getwritablecell (0, 0); Determine the type of cell, make the appropriate conversion if (wc.gettype () = = Celltype.label) {label L = (label) WC; L.setstring ("new name"); } Write to Excel object Wwb.write (); Wwb.close (); *///close Read inflow readwb.close (); }}
Third, experience
Through this experiment we learned how to use the Selenium IDE to implement simple automated tests, including the recording, writing, and running of tests, giving us a deeper understanding of the testing methodology and the importance of testing.
Software test second on-machine experiment