Selenium-transparent and repeated integrated testing tools (Pragmatic Series)

Source: Internet
Author: User

Author: Jiangnan Baiyi

Most companies in China also rely on the QA group's mm to watch the test case document for manual testing. If the money is limited and they want to change the status quo, the most practical advice is to write the business layer unittest for direct access to the database and the selenium-based integration test, which are the two most practical tests.

Under the guidance of Xu Hao, springside2.0 has fully applied selenium.

Selenium can be selected as the best integration and regression testing solution because:

1. Selenium IDE, a Firefox Plugin,Automatically records user operations and generates test scripts..

2. The generated test script can be manually executed using selenium core.Based onSelenium RCAutomatically run in unit test cases of Java, C #, and Ruby..

3.The test case calls the actual browser (such as IE and Firefox) to perform the test.. Compared with some open-source solutions that implement the Web interpretation engine on their own, the actual browser can simulate more user interactions and JS syntaxes. By the way, it can also test the compatibility of various browsers.

4.The test script syntax is very simple., See later.

1. Use selenium ide To generate scripts

Selenium IDE is a firefox1.5 plug-in. After downloading the plug-in, use Firefox to open it.

Tool-> selenium IDE, click the red recorder button to start recording. The script for each action is instantly displayed when the website is in disorder.

Switch format: Display scripts for HTML, Java, C #, and Ruby syntax. You can also set the selenium variable name in Java, such as user.

2. Test Cases and test scripts

The test case is very easy in the selenium ide generation-> copy paste process.

Public class usermanagertest extends testcase
{
Private selenium user;

Public void setup () throws exception {
User = new defaselselenium ("localhost", seleniumserver. default_port, "* iexplore", "http: // localhost: 8080 ");
User. Start ();
}
Protected void teardown () throws exception {
User. Stop ();
}

Public void testuseredit (){
User. Open ("/helloworld ");
User. Click ("// A/[contains (@ href, 'user. do? Id = 0')/] ");
User. waitforpagetoload ("3000 ");
User. Type ("user. Name", "Calvin ");
User. Click ("save ");
User. waitforpagetoload ("3000 ");
Asserttrue (user. istextpresent ("Calvin "));
}

Pay attention to the "* iexplore" parameter in setup and set ie as the test browser. If it is set to "* Firefox", * firefox.exe will be searched in path.

Note that the proxy mechanism of selenium when using IE is special. If you use the local ADSL modem to dial up the Internet at the same time, you must first disconnect the network.

In the script, user is used as the variable name of selenium, which is easier to read.

Selenium provides a wealth of user interaction functions, but selenium RC does not provide a reference manual for a single function column in Java. You need to read the public selenium refrences and then use the Java functions with the same name.

All functions are a locator parameter and put operations into objects on a page. Supports ID, Dom, XPath, and CSS selector syntaxes. For more information, see the reference manual.

If not, selenium IDE is the best teacher. For example, click <a href = "user. do? Id = 0 "_ fcksavedurl =" "user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 "" _ fcksavedurl = "" user. do? Id = 0 ""/> modify </a> to obtain the user. Click ("// A [contains (@ href, 'user. do? Id = 0.

3. Ant running script

An important feature of the ant test script I wrote is to use the <parallel> parallel container node to open both Tomcat and selenium server while waiting for the two to open and execute JUnit.
If you do not use parallel nodes, but use the spawn = Yes attribute to start Tomcat in the background, Tomcat information is not displayed on the screen. If the test ends unexpectedly, Tomcat cannot be disabled, which is inconvenient.

<Parallel>
<Antcall target = "tomcat. Start"/>
<Antcall target = "Selenium. server. Start"/>
<Sequential>
<Waitfor maxwait = "10" maxwaitunit = "Minute" checkevery = "1" checkeveryunit = "second">
<Http url = http: // localhost: 8080/>
</Waitfor>
<Waitfor maxwait = "10" maxwaitunit = "Minute" checkevery = "1" checkeveryunit = "second">
<Socket server = "localhost" Port = "4444"/>
</Waitfor>
<JUnit./>
<Antcall target = "tomcat. Stop"/>
</Sequential>
</Parallel>

4. functionaltestcase base class in springside

Springside abstracts a functionaltestcase base class and extracts the selenium server open/closed operation from the setup () and teardown () functions.

The default browser type is "* iexplore", and the default basic URL is http: // localhost: 8080.

You can reset selenium. Explorer and Selenium. baseurl variables in selenium. properties.

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.