How does a Selenium test work?
Selenium is the industry standard for automatically testing websites in browsers. A selenium test is a set of instructions that will be sent to a browser of your choice.
Most major programming language offer support for Selenium. Either by plugins or by default. These plugins will translate language specific syntax to Selenium commands which can be understood by a Selenium Grid.
For example, let's say we want a test where we will test Google on Firefox. We want to check if the title of the homepage on Google is "Google".
We start of by specifying which browser we want to use. In Selenese (the syntax used by Selenium), we would use the command
getNewBrowserSession together with the options: Firefox and browser version.
This command is sent to the Selenium grid, which is managed by a hub. The hub will receive the command, check if its grid supports the browser and assign the requester (client) a session.
The client now needs to use this session to further instruct the grid. An example of a session-id would be
When we've reached this point, the hub has instructed one of its node on the grid (which supports the browser we requested) to start the browser.
Since we want to test Google, we need to instruct the browser on the node to go to google.com. We do this by sending the "open" command to the grid, together with the URL and our sessionId. The hub will receive the request, check the sessionId and knows that we previously requested a Firefox browser on a specific node.
Our hub will forward the request to the node, which in its turn will instruct Firefox to open the page and go to the requested URL.
To end our test, we need to verify if the title of the page which is now opened on the node does in fact equal "Google". We send a request to the grid, asking our hub to contact the correct node and ask for the title of the current page.
We receive the title back from the grid and verify if the title does in fact equal the title we expect.
< Back to Blog Overview