Selenium private kitchen Series 8-fun selenium server [oo]

Source: Internet
Author: User
Tags case statement

This article mainly introduces the working principle of selenium server.Interaction ModeStart.

In the first selenium RC test case, we started selenium server with the command "Java-jar selenium-server.jar". In fact, when we started selenium server, you can also add parameters (for specific parameters, see selenium RC Server command line parameters list ).Selenium server interaction modeThe command is"Java-jar selenium-server.jar-interactive". Interactive Mode is a fast test method provided by selenium server. You can enter commands on selenium server to directly start the test.

1. Start selenium server interaction mode

 

2. In the command line enter: cmd = getnewbrowsersession & 1 = * iexplore & 2 = http://www.google.com. Control selenium server to start the browser and create a session.

 

(1). ---> Requesting http: // localhost: 4444/selenium-server/driver? Cmd = getnewbrowsersession & 1 = * iexplore & 2 = http://www.google.com

I have read "in-depth understanding of selenium RC Working Principles (1)" And should understand: the test case we have compiled is actually to control selenium server by sending HTTP requests, the request sent in the test case is: ---> requesting http: // localhost: 4444/selenium-server/driver? Cmd = getnewbrowsersession & 1 = * iw.e & 2 = http://www.google.com. In another IE browser, enter http: // localhost: 4444/selenium-server/driver in the address bar? Cmd = getnewbrowsersession & 1 = * iw.e & 2 = http://www.google.com, press Enter! Look, selenium server has another session for this! Haha:>

(2). Here, the selenium server randomly generates a session ID for the above request: 9505f5f8c52041c28f4cdc1f8e59f769 (because the selenium server is restarted midway through the writing of this article, the session ID here is different from the session ID, the session ID 9505f5f8c52041c28f4cdc1f8e59f769 will be used later ).

(3). If everything is normal, the selenium server will display the get result OK at the end, and the following two boxes will appear:

 

3. Control browser accessWww.google.com/Webhp, input: cmd = open & 1 = http://www.google.com/webhp&sessionId=9505f5f8c52041c28f4cdc1f8e59f769

 

Oh, the browser successfully accessed http://www.google.com/webhp:>.

Summary:

(1)In selenium server, enter the following command format:Cmd = command & 1 = target & 2 = Value & sessionid =...This is similar to the case statement of selenium IDE.

(2)After you enter the command, the selenium server sends an HTTP request to itself. The request URL format is also fixed:Http: // localhost: 4444/selenium-server/driver? Cmd = command & 1 = target & 2 = Value & sessionid =...We can use a browser to send a request to control the selenium server for testing.

(3)In addition, sessionid is a very important parameter. When a selenium server runs multiple test cases at the same time, selenium server uses sessionid to determine which browser window to operate. In the following C # code:

ISelenium selenium = new DefaultSelenium("127.0.0.1", 4444, "*iexplore", "http://www.google.com");
selenium.Start();
selenium.Open("/webhp");

 

Selenium is equivalent to the sessionid in the preceding section.

(4 ). when the selenium server starts a session, it must first specify a "Source" (for details, see "working principles of selenium RC (2)"). in the above Code, the http://www.google.com is the "Source", but this may be a problem, please refer to the following code:

ISelenium selenium = new DefaultSelenium("127.0.0.1", 4444, "*iexplore", "http://www.google.com");
selenium.Start();
selenium.Open(http://www.baidu.com);

 

We defined the source as a http://www.google.com when starting the session, but in subsequent operations, we opened the http://www.baidu.com, because the two are not the same, so the next operation may have a variety of problems, therefore, the selenium server will give the following warning:

Selenium server prompts that the problem can be avoided if the test case is running on * iehta or * chrome, or if you change the running mode of selenium server to proxy injection mode.

Well, here, I have to admit that I intentionally did not write anything to simplify the problem in "Understanding the working principle of selenium RC (1!

In fact, the selenium server has two operating modes:

(1 ).Heightened privileges browsers

(2 ).Proxy Injection

The default startup mode of selenium server is heightened privileges browsers. If you want to start the proxy injection mode, you can add a parameter"-Proxyinjectionmode". Previously, I introduced the relationship between Selenium RC and testcase in "Understanding the working principle of selenium RC (1 )".Proxy InjectionBecause I personally think the proxy Injection design mode is more reasonable, so I will only introduce the proxy injection mode. Here I will explain why the heightened privileges browsers mode cannot avoid the above problems. Let's take a look at the selenium server inHeightened privileges browsersWorkflow in the Mode:

 

Unlike the proxy injection mode, in heightened privileges browsers mode, browser does not pass the HTTP proxy for Web requests, therefore, the returned web page may be different from selenium core (in general, open should only obtain a subpage under "Source, pages that use open to retrieve other "sources" should be very rare in the test, because in this case, we should also process a new iselenium selenium, although there are very few opportunities for pages that use open to obtain other "sources", if you really need this, you can only start the-proxyinjectionmode mode, although the efficiency will be lower ).

Selenium private kitchen Series 8-fun selenium server [oo]

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.