"Selenium-webdriver self-study" SELENIUM-RC Scripting (10)

Source: Internet
Author: User
Tags xpath

==========================================================================================================

Write in front:

It's pretty happy to start learning the integration scripts for selenium and Java-eclipse.

After all, it's hard for me to take the first step. Always want to learn a deeper layer of selenium, but every study is a little, after learning the IDE, there is no following.

This time finally can carry on the deep-seated study.

==========================================================================================================

SELENIUM-RC means Selenium remote control (also known as Selenium1.0), is the main Selenium project for a long period of time Selenium Webdriver (Selenium2.0) only effective existence. Now selenium RC is hard to use in Webdriver with more powerful features, but users can still continue to develop using RC scripts.

It allows us to write programming languages such as Java,c#,perl,python and PHP to create more complex tests, such as reading and writing files with full power to help automate the Web application's UI testing, querying the database, and e-mail test results.

Note: The Selenium RC has been processed just to understand the plot points and the unique Webdriver detailed description, Webdriver more powerful and stable. The Selenium RC and Webdriver comparisons are explained in the following chapters.

Structure of the Selenium RC

Selenium RC Works This way, and the client library uses the Selenium RC server to perform the communication through each Selenium command. The server then uses the Selenium command to use the Selenium core JavaScript command browser.

Executes the selenium command using the JavaScript interpreter in the browser.

The Selenium RC is divided into two parts.

    • The selenium server starts and terminates, except that its browser interprets and executes the Selenese command. It also acts as an HTTP proxy by intercepting and passing HTTP messages between the authenticator and the test application.

    • The client library, which provides the interface between the programming language (Java,c#,perl,python and PHP) and each of the SELENIUM-RC servers.

RC-Script

Now let's write a sample script that uses selenium remote control. Let's use http://www.calculator.net/to understand Selenium RC. We will use the percent calculator, which is currently performing a percentage calculation in the Math Calculator module.

1th Step: Start Selenium remote control (with the help of a command prompt) explained in the environment settings chapter.

2nd step: start Selenium RC, open Eclipse, and create "New Project", as shown below.

3rd Step: Enter the project name and click on the "Next" button.

4th Step: Verify the source, project, library, and output folders, and then click "Finish".

4th step: Right-click the project container and select Configure Build Path.

5th step: attribute ' Selrcdemo ' opens. Navigate to the "Libaries" tab and select "Add External JARs". Select we downloaded the Selenium rc jar file and it will appear as shown in.

6th step: Display the referenced Couroux as shown.

Step 7: Create a new class file by performing a right-click on the "src" folder and select "New" >> "class".

8th step: Enter the name of the class file and enable "public static void Main" as shown in.

Step 9: Create the class created in the folder structure as follows.

10th Step: Now is the time to encode. The following code has comments embedded to make the reader understand.

 PackageSelrcdemo;ImportCom.thoughtworks.selenium.DefaultSelenium;ImportCom.thoughtworks.selenium.Selenium; Public classRcdemo { Public Static voidMain (string[] args)throwsinterruptedexception {//instatiate the RC ServerSelenium Selenium =NewDefaultselenium ("localhost", 4444, "Firefox", "Http://www.calculator.net");   Selenium.start (); //StartSelenium.open ("/");//Open the URLselenium.windowmaximize (); //Click on Link Math CalculatorSelenium.click ("xpath=.//*[@id = ' Menu ']/div[3]/a"); Thread.Sleep (2500);//Wait for page load//Click on Link Percent CalculatorSelenium.click ("xpath=.//*[@id = ' Menu ']/div[4]/div[3]/a"); Thread.Sleep (4000);//Wait for page load//Focus on text BoxSelenium.focus ("Name=cpar1"); //Enter a value in Text box 1Selenium.type ("Css=input[name=" cpar1 "]", "10"); //Enter a value in Text box 2Selenium.focus ("Name=cpar2"); Selenium.type ("Css=input[name=" Cpar2 "]", "50"); //Click Calculate ButtonSelenium.click ("xpath=.//*[@id = ' content ']/table/tbody/tr/td[2]/input"); //Verify if the result is 5String result = Selenium.gettext (".//*[@id = ' content ']/p[2]"); if(Result = = "5") {System.out.println ("Pass"); }Else{System.out.println ("Fail"); }            }}

11th Step: Now, let's execute the script by clicking the "Run" button.

The 12th step: The script will start executing and the user will be able to see the command history on the "Command Histories" tab.

Step: The final status of the application is shown below. The percentage calculation method and the results that it displays on the screen are as follows.

Step 14: The output from the test is printed on the Eclipse console as shown, because we have printed the output to the console below. Real-time output is written to an HTML file or a simple text file.

==========================================================================================================

Learning Summary:

1. First: When I study this part of the content, I use the selenium-2.52 package. There is no difference from the above description.

2. This part, I was not very good at the beginning of the writing, so I use the Selenium IDE to export the recorded script to selenium or Webdriver Java code, and then add to the
Project, go to call. At the same time, because the tutorial is used in the calculator, I can not access, so the Baidu page to complete.

3. The above tutorial is simple to use the eclipse environment to build a simple test, has been able to implement the basic, I use the derivative, so run out of the results are using junit results.

==========================================================================================================

Reference Address: Http://www.yiibai.com/selenium/selenium_rc.html#article-start

"Selenium-webdriver self-study" SELENIUM-RC Scripting (10)

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.