Software testing LAB2 Selenium and automated testing

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.