Selenium basic knowledge of getting Started

Source: Internet
Author: User

Content reprinted from: http://blog.csdn.net/huangbowen521/article/details/7816538

1, Selenium Introduction:

Selenium is a browser automation operation framework. Selenium mainly consists of three tools. The first tool, Seleniumide, is a Firefox extension that enables users to record and revisit tests. The recording/return mode has limitations and is not suitable for many users, so the second tool,--selenium Webdriver, provides APIs for various locales to support more control and to write applications that conform to standard software development practices. The last tool--seleniumgrid help engineers use the Selenium API to control browser instances distributed across a range of machines, enabling more tests to run concurrently. Within the project, they are referred to as "IDE", "Webdriver", and "Grid", respectively.

2, Webdriver Introduction:

Webdriver is developed for each browser, replacing JavaScript embedded in the Web App under test. Tight integration with the browser enables the creation of more advanced tests, avoiding the limitations caused by the JavaScript security model. In addition to support from the browser vendor, Webdriver also simulates user input using an operating system-level call. Webdriver supports Firefox (firefoxdriver), IE (Internetexplorerdriver), Opera (Operadriver), and Chrome (Chromedriver). It also supports mobile app testing for Android (Androiddriver) and iphone (iphonedriver). It also includes a htmlunit-based, no-interface implementation called Htmlunitdriver. The Webdriver API can be accessed through Python, Ruby, Java, and C #, enabling developers to create tests using their preferred programming language.

3, Webdriver working principle:

Webdriver is a standard for the selenium, hosted by the.

The specific protocol standard can be viewed from http://code.google.com/p/selenium/wiki/JsonWireProtocol#Command_Reference.

From this protocol we can see that Webdriver is able to interact with the browser because the browser implements these protocols. This protocol is transmitted via HTTP using JOSN.

Its implementation uses the classic Client-server model. The client sends a requset, and the server returns a response.

We define several concepts.

Client

Call the Webdriverapi machine.

Server

The machine running the browser. The Firefox browser implements the Webdriver communication protocol directly, while Chrome and IE are implemented through chromedriver and Internetexplorerdriver.

Session

The server side needs to maintain the browser session, from the client sends the request header contains the session information, the server side will execute the corresponding browser page.

Webelement

This is the object in Webdriverapi, which represents a DOM element on the page.

As a practical example, the following code is "command" Firefox to jump to the Google page:

Webdriver Driver = new Firefoxdriver ();
Instantiate a driver

Driver.get ("http://www.google.com");

When executing the code for Driver.get ("http://www.google.com"), the client, which is our test code, sends the following request to remote server:

Postsession/285b12e4-2b8a-4fe6-90e1-c35cba245956/url post_data{"url": "Http://google.com"}

Request the Localhost:port/hub/session/session_id/url address by post, request the browser to complete the jump URL operation.

If the above request is acceptable, or if remote server implements this interface, remote server jumps to the URL contained in the post data and returns the following response

{"Name": "Get", "SessionId": "285b12e4-2b8a-4fe6-90e1-c35cba245956", "status": 0, "Value": "}

The response contains the following information

The name of the Name:remote server-side implementation method, here is get, which represents a jump to the specified URL;

SESSIONID: The ID of the current session;

Status: The state code of the request execution, not 0 indicates not executed correctly, here is 0, means all ok don't worry;

Value: The return value of the request, where the return value is NULL, if the client calls the title interface, then the value should be the title of the current page;

If the client sends a request that locates a particular page element, the return value of response might be:

{"Name": "Findelement", "sessionId": "285b12e4-2b8a-4fe6-90e1-c35cba245956", "status": 0, "value": {"ELEMENT": "{ 2192893e-f260-44c4-bdf6-7aad3c919739} "}}

Name,sessionid,status is similar to the above example, the difference is that the return value of the request is element:{2192893e-f260-44c4-bdf6-7aad3c919739}, which indicates the ID of the element to navigate to, through which the ID, The client can send requests such as Click to interact with the server side.

Selenium basic knowledge of getting Started

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.