Selenium IDE installation and script recording and java unit testing, selenium Unit Testing

Source: Internet
Author: User

Selenium IDE installation and script recording and java unit testing, selenium Unit Testing
IDE installation mainly records browser behaviors and records behavior track scripts. After recording, it can be automatically executed. At the same time, it is better to generate test cases in various languages and perform tests directly in the encoding phase, saving the trouble of clicking a browser.
1. Install FireBug. Firefox first installs the firebug plug-in. 2. Install the IDE, open the Firefox extension-plug-in, and drag xpi to install it.


3, test the browser user behavior records: 1, start the Firefox browser, and then navigate to the site (this hurry up)-http://www.oschina.net/
2. Click developer-select selenium IDE To open the IDE

3. Enter the Base URL and press the recording button-that is, in the upper right corner. This prompt shows what is recording and what is stopping recording. Remember to click Start recording.

4. At this time, you can search on oschina, enter scala in the upper right corner, and click search. The result is displayed.

5. The script runs automatically. Note that you can only run the script once at a time. If you run the script multiple times, you need to click it again at a time (note that I did not find the setting for repeated clicks)

6. I think most people will choose to generate a testing instance in a programming language for repeated testing. You can select java.


7. The file name is the name of the test class. The name is Test2, and the file Test2.java is generated. Put this file in 1. The project at the entry level for instance testing. Just change the name of the package. Generated test class:Public ClassTest2 {PrivateWebDriver driver;PrivateString baseUrl;Private BooleanAcceptNextAlert =True;PrivateStringBuffer verificationErrors =NewStringBuffer ();
@ BeforePublic VoidSetUp ()ThrowsException {driver =NewFirefoxDriver (); baseUrl = "http://www.oschina.net/"; driver. manage (). timeouts (). implicitlyWait (30, TimeUnit.SECONDS);}
@ TestPublic VoidTest2 ()ThrowsException {driver. get (baseUrl + "/"); driver. findElement (.Id("Channel_q"). clear (); driver. findElement (.Id("Channel_q"). sendKeys ("scala"); driver. findElement (.CssSelector("Button. BTN"). click (); driver. findElement (.LinkText("Programming language Scala"). click ();}
@ AfterPublic VoidTearDown ()ThrowsException {driver. quit (); String verificationErrorString = verificationErrors. toString ();If(! "". Equals (verificationErrorString )){Fail(VerificationErrorString );}}
Private Boolean IsElementPresent (By){Try{Driver. findElement ();Return True;}Catch(NoSuchElementException e ){Return False;}}
Private Boolean IsAlertPresent (){Try{Driver. switchTo (). alert ();Return True;}Catch(NoAlertPresentException e ){Return False;}}
PrivateStringCloseAlertAndGetItsText (){Try{Alert alert = driver. switchTo (). alert (); String alertText = alert. getText ();If(AcceptNextAlert) {alert. accept ();}Else{Alert. dismiss ();}ReturnAlertText ;}Finally{AcceptNextAlert =True;}}}

8. unit test. Here, you can run it as you want.



9. over, other things are not involved. If you have any new requirements, I will come to the experiment. Over.

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.