/ Automation

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 :

  1. Install JDK (1.8 & above) & configure it.
  2. Install Eclipse (Photon or higher version) & configure it.
  3. Open Eclipse and create a workspace.
  4. Go to File   New Select the Java Project Give a Project Name.
  5. Installed JRE file is selected by default.
  6. Ensure that JDK 1.8 is installed.
  7. Click Finish to complete the configuration.
  8. 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 :

  1. Goto www.seleniumhq.org.
  2. 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 :

  1. 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.

1. Basic Locators

  • Id
  • name
  • class name

2. Advance Locators

  • Tag
  • CSS Selector
  • X-Path
  • Links

  1. Tag

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']"


(V) Substring

(i) Starts with (^)
Syntax: Tag[attribute^='attribute_value'] → "input[id^='em']"

(ii) Ends with ($)
Syntax: Tag[attribute$='attribute_value'] → "input[id^='il']"

(iii) Contains(*)
Syntax: Tag[attribute*='attribute_value'] → "input[id*='mai']"


3.  X-Path

(I) Absolute X-Path (/)

Path that start from the parent node (Root Node) and descend through the immediate child nodes.
Example:/html/body/div[1]/div[2]/div/form/table/tbody/tr/td[1]/input

(II) Relative X-Path (//)

Path that start from the intermediate node (child node) are only called as Relative X-Path
Example:"//[@id='Email']"


4. Links

Syntax: < Tag attribute = "attribute-value"/>

linktext-3

(I) LinkText : Links are accessed using an exact text match.
Example:"Forgotten account?"


(II) Partial LinkText : Links are accessed using a portion of their link text.
Example:"Forgotten"


-----------------Sample Automation Code in Java-------------------


Conclusion :

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.

Selenium: Beginner's Guide for Automation Testing
Share this

Subscribe to Logicwind