Thứ Hai, 5 tháng 11, 2012

How Selenium Works ?

How Selenium Works ?

Rating: 4.9/5 (7 votes cast)
We have seen many topics on Selenium ranging from working from Selenium IDE to Creating a data driven framework in Selenium, but let’s turn back our attention on how Selenium actually works. Since we have seen all the magic selenium has did for us by just writing very simple codes.
Did we ever thought how selenium opens a browser, the pages and communicates with the pages and perform operations we have specified in the code we have written? Did you ever heard about Selenese? Do you know Selenium server actually understand only Selenese command? Where did your actual code turns into selenese command?
Well we are going to discuss all the above questions in this topic of how Selenium works
We know there is a Selenium Server (Selenium RC Server), Selenium Client driver (driver specific to languages such as C#, JAVA etc) and we use them in our famous Eclipse IDE for writing code.
Once we start running a code from Eclipse IDE following stuffs will happen behind the scenes

1. The Client driver will first establishes a connection with Selenium server.
2. Selenium Server will do following
a. It will create a session for that particular request
b. It will launch the desired browser (Specified in the code IE,FF,Chrome etc)
c. Loads the Selenium cores Javascript file into the specified browser (So as selenium server will have handle with the webpage for performing Selenese action)
3. Now the Client driver will send the program that we have written in eclipse IDE as selenese (by making conversion) and send it to Selenium server.
4. Selenium server is intelligent enough to understand the selenese command and triggers the corresponding javascript execution in the web browser.
5. Here Selenium Server act as a “Proxy Server” between the AUT (Application under Test) and actual browser, due to the restriction of “Same origin policy” selenium server performs “Proxy Injection”.Being a proxy gives Selenium Server the capability of “lying” about the AUT’s real URL.
6. Now Selenium server requests the actual webserver for the page open request and then it receives the page and sends it to the browser. It will look something like this.
clip_image001
7. Now any operation or request which the browser makes will eventually passes through Selenium RC server to actual webserver and vice verse.
Well you can see the same behind the scenes operation by your own. Let us see how we can do that.
Step 1
Open the selenium server 2.15 from command prompt using the following command.
java -jar selenium-server-standalone-2.15.0.jar
Now your command prompt will look something like this.
clip_image003
Step 2
Now navigate to the URL http://127.0.0.1:4444/wd/hub, which is nothing but the default URL in which selenium server start, you can of course change the same if you want. Now your browser will have a page something like this
clip_image005
As you could see in the screenshot above, you have two buttons with create session and refresh sessions, as discussed in the point 2 above, first Selenium server will creates a session and then it starts the rest of operation by default.
Step 3
Lets create a session by clicking on the Create Session button in the browser we have, now this will ask us to select the browser
clip_image006
We will select Internet Explorer and click “OK” button, which will eventually create a session for us and launches a browser with empty page (Since we have not supplied any command to Selenium server at this point to open any URL or to perform any operations)
Now your Selenium URL page which you have opened in step 1 will looks something like this.
clip_image007
Here we have three more buttons with rest of steps we are going to perform.
In this topic we are not going to detail the Load scriptfunctionality, since this is beyond the scope of the topic which we are dealing with.
Anyways, this is how selenium actually works and performs the magic !!!
That’s it.

Không có nhận xét nào: