Selenium Learning (1)

Source: Internet
Author: User

Selenium-web interface Testing Tool

1. Selenium can use the recording tool to record the script and test the page.

2. Selenium can generate HTML-like code, Java code, and Ruby code.

3. Selenium recording tool locates HTML elements based on the ID attribute

Required Software

1. Install Firefox, selenium ide plug-in, and firebug plug-in.

2. Unzip selenium's selenium-remote-control package to get the selenium-server.jar.

3. Get selenium-java-client-driver.jar for selenium development in Java language.

Use of selenium ide

1. Firefox -- tool -- selinum ide

2. Click the recording button to start recording a test. You can use a browser to perform operations.

3. Click the stop recording button of selenium ide To view scripting languages such as HTML, Java, and Ruby.

In addition to recording HTML requests and Ajax call operations, seleniumide. Other operations that do not involve communication will also be recorded. Other automatic script recording tools, such as webload and LoadRunner, only record HTTP requests and cannot actually record page operations.

4. The script can be formatted into multiple languages.

5. selinum uses XPath and CSS to select HTML elements.

How selenium works

Selenium is different from general testing tools. The recording script of a general script testing tool is actually implemented by intercepting HTTP requests sent and received by the browser. In fact, there is no way to record users' operations on HTML pages.

Of course, this type of simulation is sufficient for the tools that perform stress testing.

Selenium's script recording tool records scripts by listening to users' operations on HTML pages. Selenium is a recording tool that truly monitors users' operations on HTML pages. Selenium fully understands the HTML page for user operations.

Selenium can generate scripts in seven languages: HTML, Java, C #, Ruby, Python, Perl, and PHP.

You can directly execute HTML scripts in seleniumide. Firefox on your machine will execute the selenium script.

HTML scripts generated by selenium are a set of scripting languages developed by Selenium Using HTML language elements.

If you want to execute the selenium script in other language formats, you need to use the selenium server. The use of the six languages is the same.

Internal execution principle of Selenium

Seleniumserver communicates with the selenium client over the network to receive selenium test commands.

Seleniumserver comprehensively tracks HTML pages by sending JavaScript calls to the browser, and returns the execution results to the selenium client through the network.

The selenium client is generally implemented using unit test technology. It determines whether the program runs correctly by judging whether the returned results are consistent with the expected ones.

Selenium uses JavaScript to perform operations on HTML pages. It provides rich methods to specify HTML page elements and operate on page elements.

When selenium opens the browser, It embeds its Javascript file into the webpage. Then, the selenium webpage is embedded into the target Webpage Through frame. In this way, you can use the JavaScript Object of selenium to control the target webpage.

Selenium is the most important JavaScript Object in selenium. It is used to execute a series of commands on behalf of the selenium interface in Java, allowing the browser to execute.

Browsers supported by selenium RC

* Iexplore
* Konqueror
* Firefox
* Mock
* Pifirefox
* Piistme
* Chrome
* Safari
* Opera
* Iehta
* Custom

Selenium Remote Control: server command line parameters

Example: Java-jar selenium-server.jar [-interactive] [Options]
-Port <NNNN>: the port number used by the selenium server (4444 by default)
-Timeout <NNNN>: the number of seconds that we waited for before giving up (timeout ).
-Interactive: Enter the interaction mode. Refer to the tutorial for more information
-Multiwindow: the mode in which all tested websites are opened in a separate window. Selenium supports frame.
-Forcedbrowsermode <Browser>: sets the browser mode (for example, all sessions use "* iexplore", regardless of the parameter passed to getnewbrowsersession)
-Userextensions <File>: Specifies a Javascript file loaded to selenium.
-Browsersessionreuse: Stop reinitializing and replacing the browser during the test.
-Alwaysproxy: by default, we can perform as few proxies as possible. setting this flag will force all browser communications to pass through the proxy.
-Firefoxprofiletemplate <dir>: Generally, a clean Firefox setting is generated before each startup. You can specify a directory for us to copy your settings instead of what we generated.
-Debug: enters the debug mode and more tracing debugging information is available.
-Htmlsuite <Browser> <starturl> <suitefile> <resultfile>: Use the specified browser (for example, "* Firefox") at the specified URL (for example, " "), run a separate HTML selenese (selenium core) test suite and exit immediately. You must specify the absolute path of the HTML test suite and the path of the HTML test result file that we will generate.
-Proxyinjectionmode: Enter the proxy injection mode. In this mode, the selenium server acts as the proxy server that enters all the content of the test program. In this mode, access is allowed across multiple domains, and the following additional parameters are also supported:
-Dontinjectregex <RegEx>: the added regular expression. The proxy injection mode can be used to determine whether to inject the regular expression.
-Userjsinjection <File>: Specifies a Javascript file and injects it into all pages.
-Usercontenttransformation <RegEx> <replacement>: a regular expression that matches all tested HTML content. The second string replaces all matched content. This flag can be used multiple times. A simple example of using this parameter: If you add "-usercontenttransformation https http", all "HTTPS" strings in the HTML of the test application will be replaced with "HTTP ".

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: 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.