Selenium — Beginner’s Guide for Automation Testing
What is Selenium ?
- It is one of the most popular open-source automated testing tool.
- It automates web applications for testing purposes, but is certainly not limited to just that.
- This tool gives many options for locating the UI elements and comparing expected test results against actual application behavior.
Advantages of Selenium :
- Selenium is a free of cost open source tool.
- Easy to learn and less hardware usage.
- It supports Multi-Browser compatibility.
- It supports Multiple Languages and Frameworks.
Limitations of Selenium :
- It is a browser based testing tool. So, desktop & mobile applications can’t be automated.
- Inability to automate a Captcha or an OTP.
Steps to configure Selenium WebDriver For windows :
- Install JDK (1.8 & above) & configure it.
- Install Eclipse (Photon or higher version) & configure it.
- Open Eclipse and create a workspace.
- Go to File → New → Select the Java Project →Give a Project Name.
- Installed JRE file is selected by default.
- Ensure that JDK 1.8 is installed.
- Click Finish to complete the configuration.
- To know whether Selenium WebDriver is installed correctly, check the availability of JRE System Libraries on the Left pane window.
Download Selenium Jar (Selenium Standalone Server) file :
- Go to www.seleniumhq.org.
- Click on Downloads →Selenium Server(Grid) and Download the Latest Stable version.
Configuring Selenium Jar file to the project :
Go to Eclipse → Select the Project → Right click on project and select Build Path option → Configure Build Path → Libraries → Add External JARs → Browse and select the downloaded Selenium Jar file(selenium-server-standalone-3.141.xx.jar) → Apply and Close.
What is Driver Software ?
- Selenium Webdriver is a browser automation framework that accepts commands & sends them to a browser.
- It is implemented through a browser-specific driver which controls the browser by directly communicating with it.
Download Driver Software :
Different ways to install Driver Software :
- System.setProperty(key, value);
2. Copy the Driver Software and Paste into the Project.
3. Set Environment Variables
Handling Web Elements :
- A website is a collection web pages.
- A webpage is a collection of web elements.
- Web elements are anything that you see on a webpage (Text Field, Image, Link, Drop-down, etc).
Locators: Commands used to perform subsequent operations and interact with Web Elements.
- Basic Locators
- class name
2. Advance Locators
- CSS Selector
Syntax: < Tagname attribute=”attribute_value”/>
2. CSS Selectors
(I) Tag & id
Syntax: Tag#id → “input#email”
(II) Tag & Class
Syntax: Tag.class → “input.inputtext”
(III) Tag & Attribute
Syntax: Tag[attribute=’attribute_value’] → “input[name=’email’]”
(IV) Tag,Class & Attribute
Syntax: Tag.class[attribute=’attribute_value’] → “input.inputtext[name=’email’]”
(i) Starts with (^)
Syntax: Tag[attribute^=’attribute_value’] → “input[id^=’em’]”
(ii) Ends with ($)
Syntax: Tag[attribute$=’attribute_value’] → “input[id^=’il’]”
Syntax: Tag[attribute*=’attribute_value’] → “input[id*=’mai’]”
(I) Absolute X-Path (/)
Path that start from the parent node (Root Node) and descend through the immediate child nodes.
(II) Relative X-Path (//)
Path that start from the intermediate node (child node) are only called as Relative X-Path
Syntax: < Tag attribute = “attribute-value”/>
(I) LinkText : Links are accessed using an exact text match.
(II) Partial LinkText : Links are accessed using a portion of their link text.
— — — — — Sample Automation Code in Java — — —
We have covered basic fundamental features of Selenium which would be an effective guide for beginners. Although its usability is not limited to that, we can perform parallel test execution and reduce our manual testing tasks using various components & frameworks which we will try to cover in upcoming blogs.
Originally published at http://blog.logicwind.com on July 1, 2020.