Selenium – Overview

Introduction

Hello,

Recently, I met one of my colleague  who is preparing for Automation Test interviews.

As I do take interviews in my organization, I thought why not I throw my two cents on this topic. As the thought goes into action you see me here. I hope it helps people who are preparing for interviews and automation learners.

Every interviewer’s perception and thought process for selecting a candidate will be different. In my view one should know below three areas of the automation testing for that matter in any technology or the software we are learning or planned to learn.

  • Conceptual details :
    • This would cover the concepts of the tool/technology what we are planning to use where does this tool exactly fit in place.
  • Technical details:
    • This will give us complete information of the tool/technology implementation details.
  • Managerial details
    • This is the last area but the most important area, this will give us picture of what are the efforts and risks involving this tool and this implementation.
    • At the end this is the most deciding factor for choosing the technology and tool that we are planned to use.

In this blog I tried to put focus on above three mentioned areas and come up with general questions that an interviewer might ask.

and the details

Conceptual

What are the factors to choose the Selenium vs other tools ? why not UFT or other tools ?

  • Selenium is free library and driver owners are constantly updating the driver exes
  • Selenium is best suited for multiple browser testing with Java/.Net/python etc, if we have skilled resources available we can always utilize them for building the automated tests
  • Selenium can be integrated easily with BDD with Cucumber for business driven development for modern development environment
  • It can be easily integrated with CICD process with Jenkins or with TFS
  • It is not suited for the applications involving interactions with windows UI objects.
  • Auto IT is the free tool combined with Selenium is widely used for limited windows operations and more html DOM operations.
  • UFT tool is very much suited for HP tool set environment like ALM. It is also most widely used tool in the automated testing space, as it is licensed tool and license is costlier Its slowly loosing the market share. It only supports vb where as Java resources much widely found. Distributed testing can be easily done with this combination as test management tool like ALM, it has capabilities to run scripts on multiple host machines.
  • Selenium Grid can be used for distributed testing, if Jenkins is used, we can configure multiple Slave nodes containing different browsers and operating systems.
  • If regression suite size is large it would be good to use frame works like testNG or cucumber for better maintainability.

 What is Jenkins and CICD process how does Selenium fit in this ?

  • CICD is continuous integration and continuous development
  • It is the integrated part of modern fast paced development methodologies like Agile Scrum.
  • CICD , CI part of it is being when build gets generated there will be set of automated tests will run to verify the build stability.
  • Jenkins is the tool which is widely used to build the code in distributed (there are lot of other tools which supports CICD environment) we can add build steps in this tool
    • Post build operation being triggering the automated build
    • Jenkins will receive feedback from the automated tests and it will mark build pass/fail/warning based on the test results.
    • CD part being development of new code/ enhancements based on the failures or new features.

Technical:

What is selenium ?

  • Selenium is code library that has methods developed to interact with modern browsers.
  • The actions on the browsers are performed by driver exes. Selenium methods can talk to browsers through these driver exes.
  • We can send or receive information from driver exes through the selenium methods.

What is xpath ?

  • Xpath is the general location of an web element in the HTLM dom (document object model)
  • This will tell us the location or generalized location of element or elements in the DOM tree
  • This is most widely used and modern browsers supports the xpath search.
  • This is fast and not mostly reliable as the dom structure will dynamically change in the modern web technologies.

What is css selectors ?

  • Css selector is the why selenium identifies the object similar to Xpath
  • Selenium can read the css files and it can identify the objects based on css classes.
  • Css selectors and xpaths are most commonly used methods to identify the object

In web application driver.findement(by.xpath) not recognizing te objects. Application is html based we can see element in the dom, what might be the issue ?

  • The most common reason for this is being that element is in iFrame.
  • We need to switch the driver to that iFrame
    • Before that we need to find all elemnts with iFrame tag get either ids or names of the frames and switch to that frame
    • With Driver.switchto
    • Then if we use find elements we can find the element.

What is TestNG xml ?

  • TestNG xml is the source or driving the test suites build on TestNG framework
  • We can give test classes and test groups information to run the tests.

How can we identify a link in the application ?

  • Link can be identified with by.linktext or by.partiallinktext

What are the different ways to identify elements ?

  • By.TagName
  • BY.Xpath
  • By.cssseector
  • By.classname

How do handle elements with in the elements say for example data in table ?

  • We can iterate the findelements with in the elements like below
  • First find Elements with tag name tr
List <WebElement>rows = Driver.FindElements(By.tagnme(“tr”))
for (WebElement row :rows)
 {
   List<WebElement> dataincolumns = Row.findelements(By.tagname(“td”))
 }
  • This is just illustration that we can  do following
Driver.FindElement(By.tagname(<locator>)).FindElement(By.xpath(<locator>).FindElement….. etc

How can we get the text in the textbox

  • We use element.getAttribute to get the attribute of elements such as value and color
  • Element.getAttribute(value) will give us the text of the element.

What are actions ?

  • Actions is class for mouse interactions
  • Some of the web elements need to be hovered to get the list in the common web page designs.
  • We need actions class to perform those operations.
  • Examples:
    • Hovering
    • Mouse move

what is test framework ?

  • test framework is well defined process for creating, execution reporting the automated tests.
  • We see lot of customized framworks in each organizations and some free framework tools also available
    • Junit
    • TestNG
    • Cucumber
  • The main concepts for designing framework should be
    • Process to easily create tests
    • Process to pass data to tests
    • Process to easily maintain the tests
    • Process to generate required reports

Managerial

How can we report with selenium

  • Reporting is bit of crude in selenium, if we use standard frameworks we can get html report
  • Generally we create expected result and actual result in array lists and at the end of the tests we flush them to excel.

How can we manage the code repository if many people are working

  • Selenium development of tests is same as any development project.
  • We use SVN or TFS code management tools to make regular check ins and check outs.
  • SVN is free , and most widely used code management tool, for Microsoft technologies we use TFS as code management.

What is Maven ?

  • Maven is the repository for Jar files. Jar files are nothing but java libraries which has functions or methods readily available for usage.
  • When building a project with selenium we require to use standard java libraries for different purposes
  • Examples:
    • testNG jar file
    • Apache poi jar file
  • If multiple people are using the project, sharing of these libraries will become challenge.
  • Maven project will remove this dependency by adding all dependent jar files directly from Maven repository.
  • Maven will create local repository and down loads all required jar files in the local system. We need to make sure we add all dependencies in the pom.xml.

These are some of the commonly asked High level overview questions in the Selenium interviews. I see we did not cover everything in very detail as it is just overview.

I will try to cover each area with important aspects in my next blogs. Thank you.

Page Object Model – Approach

In selenium, most frequently we hear page object model.

I have asked people why did they call it as page object model ? Is there any specific reason behind this ?

I got general answer saying “we store all locators in a page as static final strings in a page class”

Is this correct explanation ? are we doing page object model as is ? below is another view point.

In general we call page object model because every method in a page returns the page object instead of string/float/int or any standard return types.  This will provide flexibility in writing test cases easily.

Step 1 : Define Page class

package test.pom;
public class page1 extends pageRep
{  
public page1() 
{
super(); 
} 
public page1 testM1() 
{ 
System.out.println("Method 1 Page 1");  
return this; 
} 
public page1 testM2() 
{ 
System.out.println("Method 2 Page 1");  
return this; 
} 

}

Create another page to illustrate navigation between pages.

package test.pom;
public class page2 extends pageRep 
{
 public page2() 
{ 
super(); 
} 
public page2 test_M1() 
{ 
System.out.println("Method 1 Page 2");  
return this; 
} 
public page2 test_M2() 
{ 
System.out.println("Method 2 Page 2");  
return this; 
} 
}

If you observe clearly, the above classes are returning the page class as object and extending the class page repository. The class page repository is the class where we use to navigate between the pages.

Step 2: Create page repository for navigation between pages

package test.pom;
public class pageRep { 
public pageRep() 
{
 System.out.println("Calling the super class"); 
}
public page1 navigateToPage1() 
{ 
return new page1();
} 
public page2 navigateTopage2() 
{ 
return new page2(); 
} 
}

Step 4 : While creating the test case you can see it will be simple as we can keep “.” to see the methods in the class as each method returns the class object again, you will have visibility of all methods.

Page repository helps us to navigate between pages.

This is the best illustration of the Java extends concept which we can use to write our tests in selenium.

package test.testcases;
import test.pom.pageRep;
public class tests {
public static void main(String[] args) 
{ 
 pageRep start = new pageRep();
 start     
.navigateToPage1().testM1().testM2()
.navigateTopage2().test_M1().test_M2()     
.navigateToPage1().testM1(); 
 }
}

output:

Calling the super class
Calling the super class
Method 1 Page 1
Method 2 Page 1
Calling the super class
Method 1 Page 2
Method 2 Page 2
Calling the super class
Method 1 Page 1