Introduction to Selenium Learning-selenium RC

Source: Internet
Author: User
Selenium RC is the use of programming language script, through the Selenium RC server as a proxy server to access the application to achieve the purpose of the test. Since Selenium RC no longer needs to be dependent on Firefox, it can be tested on a number of other browsers, And that's one of the more important things we do with web testing (solving problems that are important to test because of concerns about browser compatibility issues).     RC scripts are more flexible and powerful because they are written in programming languages. And it supports a very rich language. So RC is the most widely used selenium test tool. At the same time, it has a higher level of programming requirements for testers. The following is an introduction to the selenium RC. Selenium RC use consists of two parts, one is the server, the other is the script. The server can be used after downloading, and remember to open the server when you start running scripts. It is a packaged Java program that runs Java-jar Selenium-server.jar. To use SELENIUM-RC, it is necessary to start this server.     Of course, there are some parameters to start up, you can refer to its official website. However, to do a general test, do not need additional parameters are sufficient. The other part is the script, and that's what we're going to write. It can be written in multiple languages, such as C#,ruby,java, where I use Java. It can be applied to multiple test frameworks, such as Junit/nunit, testng, and so on, with JUnit. Throughout the test framework,    Selenium provides encapsulated selenium interfaces and classes, and if you use JUnit It also provides encapsulated test classes. The following steps take a simple example to introduce a junit3.0 based test framework to write and run scripts on the Ecplise platform in the Java language. 1> write a test script. First build a Java project, remember to put the junit3.0 package and selenium Java (that is, Selenium-java-client-driver.jar) The package is placed in project. Then build a class to inherit the encapsulated selenium test class directly. The script is as follows: Package com.xpg.study;
Import com.thoughtworks.selenium.*;
Inherit test class public class Defaulttestcase extends Selenesetestcase {//Instantiate Selenium class Selenium Selenium;//Overwrite setup method public Voi D setUp () throws exception{//Instantiate Defaultselenium class, other commands are its method selenium=new defaultselenium ("localhost", 4444, "* IExplore "," http://www.baidu.com "); Start Selenium to create a new session selenium.start (); }//Overwrite teardown method (there is no special setting here) public void teardown () throws exception{Selenium.stop ()///Set up a test method, which is a collection of commands. public void Testbaidu () throws exception{//Defaulttestcase test=new defaulttestcase (); Note that the selenium here is the selenium that is already started in the class, and the command is its method Selenium.open ("http://www.baidu.com"); Selenium.waitforpagetoload ("6000"); Selenium.type ("kw", "selenium"); Selenium.click ("SB"); Thread.Sleep (3000); Asserttrue (selenium.istextpresent ("Related Search")); } }
     Above is a simple example used to test the Baidu site. Of course, in general, we'll put JUnit TestCase in a specialized test class that inherits the Selenesetestcase class directly, Reuse can also be achieved with better organizational scripting.      Writing a good script is certainly a trial run. First, you have to open a selenium server, with commands Java-jar Selenium-server.jar-multiwindow. A parameter-multiwindow is used to separate the browser that is running at run time from the browser of the selenium service. You can run the script after you open the server. The final script should be passed if it is not unexpected.      Above is just a very simple example of a selenium RC for testing purposes. To apply selenium RC well to the test, it takes a little time to be familiar with the study ....

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.