How does Selenium work?
In this article, you will understand how does Selenium work? This is a conceptual article and explains the behind-the-scene concepts. Selenium is one of the most popular automation testing tools in the market. Release of Selenium version 3 will also help in its usage.
I am going to explain the key concepts and will explain how selenium automation script runs in the browser?
Running Automation script
Let’s start by looking at the automation testing using selenium. You use selenium tool to write test scripts, which are executed by Java. Selenium is not an executable application (like MS word or Excel) and cannot run on its own. It needs a programming environment to work. Some of the programming environments supported by Selenium are:
- C# (.NET) & more…
In order to automate the testing, you need to put the required test data in the fields on the web page automatically, as shown below:
How does Selenium script put the data in the fields?
In order to put test data in the fields on the screen, the script must identify the fields. To identify these fields, selenium scripts use locators. Locators, as the name suggests, helps in locating fields on any web page. Every field on the web page is identified as Web Element. So whether it’s text box or a dropdown list, it’s essentially a web element.
Every web element is identified by a locator id. You can find the locator id using simple browser “Inspect” command, as shown below:
So for writing automation script, you just need to get hold of every field on the screen (under test) and use script to enter required test data.
The next question is – how does Selenium identify the correct web page and browser?
How does Selenium identify webpage and browser?
Your selenium code must specify the browser and the URL of the page so that the page can be opened in the specified browser, before putting the test data.
So how do you open the browser through Selenium code? Conceptually speaking, every browser understands a specific language. In order to communicate with the browser, you must use the browser specific language.
It’s not possible to write code in every browser specific language, so we use drivers. These drivers are browser specific and they have the ability to translate any language into browser specific languages.
Every browser has a different driver (from Selenium version 3) and your code must use the browser specific driver to communicate with the browser.
You can find all the browser drivers on the Selenium official website.
How does Selenium code run?
Your selenium code is run by the programming environment.
But how does selenium code run?
Earlier, I had mentioned that selenium code cannot run on its own. It needs a programming environment (better term would be an execution environment) to run.
Java runtime environment is one such environment. You can use Java programming environment to run selenium code as shown below:
You write your selenium code in any standard Integrated development environment (IDE) like Eclipse or Netbeans.
Summarizing – How does Selenium work
Let’s summarize. You write your Selenium automation script in Java (you can use PHP, Ruby etc as well). In your selenium script, you use drivers, specific to the browsers, you are planning to use. You then use locator ids to put test data (for test cases) into the fields and execute the test cases. The browser specific driver, simply translates your code to the browser’s language.
When you are learning Selenium web driver programming, it’s important to understand the concepts along with coding as it can be extremely helpful in your career. If you are planning to learn selenium, do focus on understanding concepts as well.
Our training approach includes conceptual sessions as well as hands-on sessions to help you become a better selenium automation tester.
Techcanvass Training Courses