How does Selenium work?
In this article, you will understand how does Selenium work? This article explains the concepts of Selenium webdriver in action. Selenium is one of the most popular automation testing tools in the market.
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 run the test cases using script. What does a test case contain?
a) It contains a condition for a field on the screen
b) It has data to test the condition
In order to automate the testing, we need to write code to put the test data in a particular field in the screen and validate the condition.¬† If the condition is found to be TRUE, the test case passes else it fails.
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.
Read Also:¬ How do you install and setup selenium version 3?
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 offers¬†IT certification courses for professionals.¬†We are an IIBA endorsed education provider (EEP), iSQI ATP (for Certified Agile Business Analyst Training) as well as Agile Testing alliance partner for CP-SAT certification training in Selenium.
Techcanvass offers following courses on Automation Testing, click on them to explore further