Liam's Software Testing Learning Journey (V): Selenium test

Source: Internet
Author: User

Today's experiment is to use selenium for web testing. First, you need to install the relevant plugin selenium in Firefox. Once installed, a flag will appear in the top right corner of Firefox:. The presence of this sign means that the installation is ready.

Next click on this button, you will see the Selenium IDE interface:

Click the Red Recording button on the right to start recording. The recording step is to test all the steps of a use case, including filling in the URL, entering the number password, and so on. Finally select the mailbox in the result interface, and the message is selected Asserttext.

After you output the appropriate results in the Selenium IDE, note the option to select the Enable experimental features in the output money.

After the output is poured into the selenium and CSV file read the relevant jar package, write the program as follows:

 Packagecom.example.tests;Importjava.io.IOException;ImportJava.nio.charset.Charset;Importjava.util.Arrays;Importjava.util.Collection;ImportJava.util.regex.Pattern;ImportJava.util.concurrent.TimeUnit;Importorg.junit.*;ImportOrg.junit.runner.RunWith;Importorg.junit.runners.Parameterized;Importorg.junit.runners.Parameterized.Parameters;Import Staticorg.junit.assert.*;Import Staticorg.hamcrest.corematchers.*;Importorg.openqa.selenium.*;ImportOrg.openqa.selenium.firefox.FirefoxDriver;ImportOrg.openqa.selenium.support.ui.Select;ImportCom.csvreader.CsvReader; the @RunWith (parameterized.class) Public classSeleniumtest {PrivateWebdriver Driver; PrivateString BaseUrl; Private BooleanAcceptnextalert =true; PrivateStringBuffer verificationerrors =NewStringBuffer (); PrivateString ID, pwd,email;  Publicseleniumtest (string ID, string email) { This. ID =ID;  This. PWD = id.substring (4);  This. email =email;} @Before Public voidSetUp ()throwsException {system.setproperty ("Webdriver.firefox.bin", "C:/Program Files/mozilla Firefox/firefox.exe"); Driver=NewFirefoxdriver (); BASEURL= "http://www.ncfxy.com/"; Driver.manage (). Timeouts (). Implicitlywait (30, Timeunit.seconds); } @Parameters Public StaticCollection<object[]> GetData ()throwsIOException {object[][] obj=Newobject[109][]; Csvreader R=NewCsvreader ("c:/users/Chang/downloads/info.csv", ', ', Charset.forname ("GBK")); intCount = 0;         R.readheaders ();  while(R.readrecord ()) {Obj[count]=NewObject[]{r.get ("id"), r.get ("email"))}; Count++; }         returnarrays.aslist (obj); } @Test Public voidTestuntitled ()throwsException {driver.get (BASEURL); Driver.findelement (By.id ("Name") . Clear (); Driver.findelement (By.id ("Name")). SendKeys ( This. ID); Driver.findelement (By.id ("PWD") . Clear (); Driver.findelement (By.id ("pwd"). SendKeys ( This. pwd); Driver.findelement (By.id ("Submit") . Click (); Assertequals ( This. Email, driver.findelement (By.xpath ("//tbody[@id = ' table-main ']/tr/td[2]") . GetText ()); } @After Public voidTearDown ()throwsException {driver.close (); String verificationerrorstring=verificationerrors.tostring (); if(!"". Equals (verificationerrorstring))    {fail (verificationerrorstring); }  }}

But when I try to run, the following error always occurs:

The morning after the query found that because of the high version of Firefox, and then to other students to run the problem on the computer solved. The results were as follows:

Liam's Software Testing Learning Journey (V): Selenium test

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.