Selenium Quick Start (http://www.javaeye.com/topic/36879)

Source: Internet
Author: User
Overview

Our company does not have formal testers. For a module, whether the functions are completed is manually tested by developers. This often happens in the later stages of the project. The developer changes a BUG and passes the test. However, the BUG is fixed when it is sent to the customer, previously, functions that work normally failed to work. For a module, changing a part of the Code may cause a chain reaction. To ensure that other functions are not affected, you must perform a comprehensive test, it is unrealistic to change bugs frequently. In view of this situation, we consider introducing Selenium into the project.

Selenium is a WEB application-based acceptance testing tool developed by ThoughtWorks. It runs directly in a browser to simulate customer operations.

Selenium abstracts a series of commands for module user operations. For example, the open command indicates opening a URL, and the click command indicates clicking a button. Selenium actually converts these commands into actual HTTP requests and runs them in the browser.

For specific commands supported, see SpringSide translation.

Selenium IDE

Selenium IDE is a plug-in based on the FIREFOX browser. It provides a GUI to run Selenium testing. Selenium IDE provides the script recording function to record operations performed by users in the browser, generate various forms of scripts, and save these scripts for future use.

To install Selenium IDE, follow these steps:

  • Download selenimu IDE (an XPI file) from www.openqa.org/selenium-ide/download.action ).
  • Start the FIREFOX browser and open the downloaded file.
  • Restart the FIREFOX browser. The Selenium IDE menu item should be displayed under the tool menu bar.
Selenium RC

Selenium Remote Control is a test tool that allows you to write automated web ui test cases in any language. This tool provides a Selenium Server that can start, stop, and control any browser. This Server uses AJAX to directly interact with the browser and can use http get/POST requests to send commands to the Selenium Server. This means that you can use any programming language to send HTTP requests to the Selenium Server to automate Selenium testing. To simplify this process, Selenium provides packaging objects for mainstream languages. For JAVA, It is the DefaultSelenium class.

Although Selenium provides a simple HTML-based TABLE-based writing test, given that developers are more familiar with JAVA code, and through code writing testing, it is easy to run automatically with ANT script and unit test. The following process describes how to write Selenium tests in JAVA.

Download

Download selenium RC files from www.openqa.org/selenium-rc/download.action. assume that the decompressed directory is HOME.

Start the server

Selenium Server is implemented in JAVA, and the corresponding library file is in the HOME/server/selenium-server.jar. Run the following code to start from the command line:

Java code
  1. Java-jar selunium-server.jar

You can also set options in the command line. For specific options, see www.openqa.org/selenium-rc/options.html. To perform automated testing, you can start it in the ANT script.

Write Test Cases

To write Selenium test cases, you must first load the HOME/java/selenium-java-client-driver.jar file into the class path. Then write a unit test for JUNIT to build a Selenium, including the following steps:

  • Build a Selenium instance
  • Start Selenium instance
  • Run the Selenium command and verify the result. To execute a command, call the method of Selenium instance. For specific commands, see JAVADOC.
  • Disable Selenium instances

The following is an example to test www.google.com and find selenium. The expected result contains "OpenQA: Selenium ".

Java code
  1. Package com. thoughtworks. selenium;
  2. Import junit. framework .*;
  3. Import org. openqa. selenium. server .*;
  4. Public class GoogleTest extends TestCase
  5. {
  6. Private Selenium selenium;
  7. Public void setUp () throws Exception {
  8. String url = "http://www.google.com ";
  9. Selenium = new defaselselenium ("localhost", SeleniumServer. getDefaultPort (), "* firefox", url );
  10. Selenium. start ();
  11. }
  12. Protected void tearDown () throws Exception {
  13. Selenium. stop ();
  14. }
  15. Public void testGoogleTestSearch () throws Throwable {
  16. Selenium. open ("/intl/zh-CN /");
  17. Selenium. type ("q", "selenium ");
  18. Selenium. click ("btnG ");
  19. Selenium. waitForPageToLoad ("30000 ");
  20. AssertTrue (selenium. isTextPresent ("OpenQA: Selenium "));
  21. CheckForVerificationErrors ();
  22. }
  23. }

 

References

Blog of spending money

IBM China 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.