Regression Test Cases Selenium Webdriver: What Is Automation Testing?
Regression Test Cases Selenium Webdriver: What Is Automation Testing?
Regression Test Cases Selenium Webdriver: What Is Automation Testing?
37.5K
Ruby Rose asked Morgan Freeman to record her voicemail message
Next
Stay
This is one of the common interview questions in any Automation testing job.
As we all know Selenium WebDriver is a tool that automates the browser to mimic real user
actions on the web. Selenium is a free open source testing tool. Some of the challenges with
Selenium WebDriver are as follows
Actually, it depends on Test case scenario complexity and length. I did automate 2-5 test
scenarios per day when the complexity is limited. Sometimes just 1 or fewer test scenarios in
a day when the complexity is high.
6. What is a Framework?
A framework defines a set of rules or best practices that we can follow in a systematic way to
achieve the desired results. There are different types of automation frameworks and the most
common ones are:
Subjective Validation
New Functionalities
Strategic Development
User Experience
Complex Functionality
Quality Control
Low return on investment
Installation and setup testing
If you are a beginner: You can say “No, I didn’t get a chance to create framework from the
scratch. I have used the framework which is already available. My contribution is mostly in
creating test cases by using the existing framework.”
If you are a beginner but have good knowledge on creating framework: You can say
“Yes, I have involved in developing framework along with other automation tester in my
company.”
11. How would you explain the Selenium test automation framework in the
interview?
Here we have clearly explained each component of the Framework. Check this post to learn
more about how to explain the selenium test automation framework to the interviewer.
Free and open source – It is a free open source tool. There is no need to allot
budget for this tool
Help – Have large user base and helping communities.
Cross-browser compatibility – It works on almost all popular browsers such as
Chrome, Firefox, Internet Explorer, and Safari.
Cross Platform compatibility – It works on platforms such as Windows, Linux,
Mac.
Multiple programming languages – It supports programming languages such
as Java, Phyton, Perl, Php, C#, Ruby, etc.,
Parallel Execution – Selenium Grid supports parallel execution of Selenium
Scripts.
Continuous Integration – We can achieve nightly execution using Jenkins.
13. What is Selenium?
Selenium is an open source (free) automated testing suite to test web applications. It supports
different platforms and browsers. It has gained a lot of popularity in terms of web-based
automated testing and giving a great competition to the famous commercial tool HP QTP
(Quick Test Professional) AKA HP UFT (Unified Functional Testing).
Selenium is a set of different software tools. Each tool has a different approach in supporting
web based automation testing.
Selenese is the language which is used to write test scripts in Selenium IDE.
16. Which is the only browser that supports Selenium IDE to be used?
Firefox
Selenium RC AKA Selenium Remote control / Selenium 1. Selenium Remote Control was the
main Selenium project for a long time before the WebDriver merge brought up Selenium 2.
Selenium 1 is still actively supported (in maintenance mode). It relies on JavaScript for
automation. It supports Java, Javascript, Ruby, PHP, Python, Perl and C#. It supports almost
every browser out there.
18. What is Selenium WebDriver?
Selenium Grid is a tool used together with Selenium RC to run tests on different machines
against different browsers in parallel. That is, running multiple tests at the same time against
different machines running different browsers and operating systems.
In simple words, it is used to distribute your test execution on multiple platforms and
environments concurrently.
Selenium Grid can be used to execute same or different test scripts on multiple platforms and
browsers concurrently so as to achieve distributed test execution
It allows running test cases in parallel thereby saving test execution time.
It allows multi-browser testing
It allows us to execute test cases on multi-platform
A hub is a server or a central point that controls the test executions on different machines.
Node is the machine which is attached to the hub. There can be multiple nodes in Selenium
Grid.
Selenium supports all major programming languages such as Java, C#, Perl, Python, Ruby,
PHP, Scala and Groovy. As of today, others are not compatible.
Functional Testing
Regression Testing
Retesting
Acceptance Testing
End-to-End Testing
Smoke Testing
Sanity Testing
Responsive Testing
Cross Browser Testing
UI Testing
Integration Testing
30. How many parameters can selenium commands have at minimum?
There are four parameters that you have to pass in Selenium are
Host
Port Number
Browser
URL
Host: It is the parameter which we use to bind Selenium to a specific IP. Usually, we run
selenium tests on our local machine so the value will be ‘localhost’. You can sepcify IP
address instead of localhost.
java -jar <selenium server standalone jar name> -host <Your IP Address>
Port Number: TCP/IP port which is used to connect selenium tests to the selenium grid hub.
Default port hub is 4444.
java -jar <selenium server standalone jar name> -role hub -port 4444
Make sure no other application in your system is using this port. You may face an exception
like Exception in thread “main” java.net.BindException: Selenium is already running on port
4444. Or some other service is.
If this occurs you can either shutdown the other process that is using port 4444, or you can
tell Selenium-Grid to use a different port for its hub. Use the -port option for changing the port
used by the hub.
java -jar <selenium server standalone jar name> -role hub -port 4441
Browser: To pass the browser which has to execute our selenium scripts
1. ID – Practical example
2. ClassName – Practical example
3. Name – Practical example
4. TagName – Practical example
5. LinkText – Practical example
6. PartialLinkText – Practical example
7. XPath – Practical example
8. CSS Selector – Practical example
XPath is used to locate the elements. Using XPath, we could navigate through elements and
attributes in an XML document to locate web elements such as textbox, button, checkbox,
Image etc., in a web page.
34. When you use these locators ID, Name, XPath, Or CSS Selector?
ID & Name locators will be used when there are unique identifiers & unique names available
on the web page.
CSS Selector can be used for performance and when ID & Name locators are not unique.
XPath is used when there is no preferred locators.
Single Slash “/” – Single slash is used to create XPath with absolute path i.e. the XPath
would be created to start selection from the document node/start node.
Double Slash “//” – Double slash is used to create XPath with relative path i.e. the XPath
would be created to start selection from anywhere within the document.
36. What is the difference between Absolute Path and Relative Path?
Absolute XPath starts from the root node and ends with desired descendant element’s node.
It starts with top HTML node and ends with input node. It starts with a single forward slash(/)
as shown below.
1 /html/body/div[3]/div[1]/form/table/tbody/tr[1]/td/input
Relative XPath starts from any node in between the HTML page to the current element’s
node(last node of the element). It starts with a double forward slash(//) as shown below.
1 //input[@id='email']
37. What is the difference between Assert and Verify in Selenium?
Assert: In simple words, if the assert condition is true then the program control will execute
the next test step but if the condition is false, the execution will stop and further test step will
not be executed.
Verify: In simple words, there won’t be any halt in the test execution even though the verify
condition is true or false.
Read this detailed post on Assert vs Verify with practical example here detailed post check
the below link.
Soft Assert: Soft Assert collects errors during @Test Soft Assert does not throw an exception
when an assert fails and would continue with the next step after the assert statement.
Both sleep() and setSpeed() are used to delay the execution speed.
setSpeed(): It set up speed that will apply a delay time before every Selenium operation.
sleep(): It set up wait only for once when called in our Selenium script.
In Selenium IDE, we use Selenese Verify and Assert Commands as Verification points
In Selenium WebDriver, there is no built-in features for verification points. It totally depends
on our coding style. some of the Verification points are
To check for page title
To check for certain text
To check for certain element (text box, button, drop down, etc.)
41. How to launch a browser using Selenium WebDriver?
Note: If you use geckodriver with Selenium, you must upgrade to Selenium 3.3. Here we
have to set the property as follows
If we create a reference variable driver of type WebDriver then we could use the same driver
variable to work with any browser of our choice such as IEDriver, SafariDriver etc.,
47. What are the different exceptions you have faced in Selenium WebDriver?
1. ElementNotVisibleException
2. StaleElementReferenceException
This exception will be thrown when you are trying to locate a particular element on webpage
that is not currently visible eventhough it is present in the DOM. Also sometimes, if you are
trying to locate an element with the xpath which associates with two or more element.
A stale element reference exception is thrown in one of two cases, the first being more
common than the second.
We face this stale element reference exception when the element we are interacting is
destroyed and then recreated again. When this happens the reference of the element in the
DOM becomes stale. Hence we are not able to get the reference to the element.
WebDriverException
IllegalStateException
TimeoutException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
48. How to handle STALEELEMENTREFERENCEEXCEPTION?
Before looking how to handle Stale Element Reference Exception through Page Object
Model. Let’s see what is Stale Element Reference Exception first.
Stale means old, decayed, no longer fresh. Stale Element means an old element or no longer
available element. Assume there is an element that is found on a web page referenced as a
WebElement in WebDriver. If the DOM changes then the WebElement goes stale. If we try to
interact with an element which is staled then the StaleElementReferenceException is thrown.
In Selenium we could see three types of waits such as Implicit Waits, Explicit Waits and
Fluent Waits.
Implicit waits tell to the WebDriver to wait for a certain amount of time before it throws an
exception. Once we set the time, WebDriver will wait for the element based on the time we
set before it throws an exception. The default setting is 0 (zero). We need to set some wait
time to make WebDriver to wait for the required time.
Practical example
Practical example
FluentWait can define the maximum amount of time to wait for a specific condition and
frequency with which to check the condition before throwing an “ElementNotVisibleException”
exception.
Practical example
53. What happen if you mix both implicit wait and explicit wait in a Selenium Script?
As per the official Selenium documentation, it is suggested not to mix both Implicit waits and
Explicit Waits. Mixing both of them can cause unpredictable wait times.
Implicit wait is defined only once in the code. It will remain same throughout the driver object
instance.
Explicit wait is defined whenever it is necessary in the code. This wait will call at the time of
execution. It is a conditional wait.
Explicit wait will overwrite the implicit wait where ever explicit wait is applied. So, Explicit Wait
gets first preference then Implicit Wait.
54. What happen if you mix both Thread.Sleep and WebDriver Waits in a Selenium
Script?
Thread.sleep() method can be used to pause the execution for specified time in milliseconds
If we use WebDriver waits along with Thread.sleep() method then webdriver will hold the
execution for specified time and then will follow other wait. Test execution time will become
more, if we mix both waits.
55. How to Login into any site if it is showing an Authentication Pop-Up for
Username and Password?
1 // To initialize js object
2 JavascriptExecutor JS = (JavascriptExecutor)webdriver;
3 // To enter username
4 JS.executeScript("document.getElementById('User').value='SoftwareTestingMaterial.com'");
5 // To enter password
6 JS.executeScript("document.getElementById('Pass').value='tester'");
Learn JavaScriptExecutor in Selenium with Examples
58. How to clear the text in the text box using Selenium WebDriver?
By using getAttribute(value);
HTML:
Selenium Code:
Alternatively, you can use click method on the element which does form submission
1 driver.findElement(By.xpath("xpath")).sendKeys(Keys.ENTER);
64. How to pause a test execution for 5 seconds at a specific point?
1 Thread.sleep(5000)
65. Is Selenium Server needed to run Selenium WebDriver Scripts?
When we are distributing our Selenium WebDriver scripts to execute using Selenium Grid, we
need to use Selenium Server.
If the URL doesn’t contain http or https prefix then an exception is thrown. So, we need to
pass HTTP protocol within driver.get() method.
1 driver.get("https://www.softwaretestingmaterial.com");
67. What is the alternative to driver.get() method to open an URL using Selenium
WebDriver?
Alternative method to driver.get(“url”) method is driver.navigate.to(“url”)
driver.get(): To open an URL and it will wait till the whole page gets loaded
driver.navigate.to(): To navigate to an URL and It will not wait till the whole page gets loaded
We use Navigate interface to do navigate back and forth in a browser. It has methods to
move back, forward as well as to refresh a page.
1 driver.getCurrentUrl();
72. How can we maximize browser window in Selenium?
1 driver.manage().window().maximize();
73. How to delete cookies in Selenium?
To delete cookies we use deleteAllCookies() method
1 driver.manage().deleteAllCookies();
74. What are the ways to refresh a browser using Selenium WebDriver?
Purpose of these two methods (driver.close and driver.quit) is almost same. Both allow us to
close a browser but still, there is a difference.
MaxInstances is the no. of browser instances of the same version of the browser that can run
on the remote machine.
1 -browser browserName=InternetExplorer,version=6,maxInstances=2,platform=WINDOWS
2 -browser browserName=firefox,version=11,maxInstances=2,platform=WINDOWS
As per the above example, it will allow us to run 4 instances of both IE and Firefox at the
same time (in parallel) in a remote machine.
MaxSession says how many browsers, independent of the type & version, can run in parallel
on the remote machine.
If maxSession=1 then no more than a single browser would run. If maxSession=2 then any of
the below combinations can run at a time irrespective of what MaxInstances we have defined.
2 Internet Explorer
2 Firefox
1 Internet Explorer + 1 Firefox
WebDriver facilitates the user with the following methods to check the visibility of the web
elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels
etc.
1. isDisplayed()
1 boolean elePresent = driver.findElement(By.xpath("xpath")).isDisplayed();
2. isSelected()
1 boolean eleSelected= driver.findElement(By.xpath("xpath")).isSelected();
3. isEnabled()
1 boolean eleEnabled= driver.findElement(By.xpath("xpath")).isEnabled();
80. How to select a value in a dropdown?
By using Select class
Practical Example:
Test cases may fail while executing the test scripts. While we are executing the test cases
manually we just take a screenshot and place in a result repository. The same can be done
by using Selenium WebDriver.
Some of the scenarios we may need to capture a screenshot using Selenium WebDriver are
i. Application issues
ii. Assertion Failure
iii. Difficulty to find Webelements on the web page
iv. Timeout to find Webelements on the web page
In Selenium 3, we may face few issues while capturing Screenshots. To overcome we use
aShot utility. Click on below links to see posts related to the normal way of capturing a
screenshot and capturing a screenshot using aShot utility.
Practical Example.
To handle Web-based alerts or popups, we need to do switch to the alert window and call
Selenium WebDriver Alert API methods.
Practical Example.
Selenium doesn’t support windows based applications. It is an automation testing tool which
supports only web application testing. We could handle windows based popups in
Selenium using some third party tools such as AutoIT, Robot class etc.
Practical Example.
87. How to find more than one web element in the list?
By using JavascriptExecutor
For example:
1 driver.findElement(By.id("Id Value")).click();
Sometimes web controls don’t react well against selenium commands and we may face
issues with the above statement (click()). To overcome such kind of situation, we
use JavaScriptExecutor interface.
It provides a mechanism to execute Javascript through Selenium driver. It provides
“executescript” & “executeAsyncScript” methods, to run JavaScript in the context of the
currently selected frame or window.
There is no need to write a separate script to execute JavaScript within the browser
using Selenium WebDriver script. Just we use predefined interface named ‘Java Script
Executor’. We need to import the JavascriptExecutor package in the script.
Package:
1 import org.openqa.selenium.JavascriptExecutor;
Syntax:
No, It’s not possible to automate captcha and bar code reader.
92. Can You Use Selenium For Rest API Testing Or Web Services Testing?
Simple answer for this is Selenium is not a tool for API Testing. It automates web browsers.
Rest API & Web Services contains no UI. So we cannot automate using Selenium.
Handling AJAX calls is one of the common issues when using Selenium WebDriver. We
wouldn’t know when the AJAX call would get completed and the page has been updated. In
this post, we see how to handle AJAX calls using Selenium.
AJAX stands for Asynchronous JavaScript and XML. AJAX allows the web page to retrieve
small amounts of data from the server without reloading the entire page. AJAX sends HTTP
requests from the client to server and then process the server’s response without reloading
the entire page. To handle AJAX controls, wait commands may not work. It’s just because the
actual page is not going to refresh.
When you click on a submit button, the required information may appear on the web page
without refreshing the browser. Sometimes it may load in a second and sometimes it may
take longer. We have no control over loading time. The best approach to handle this kind of
situations in selenium is to use dynamic waits (i.e. WebDriverWait in combination with
ExpectedCondition)
1. titleIs() – The expected condition waits for a page with a specific title.
1 wait.until(ExpectedConditions.alertIsPresent()) !=null);
Object Repository is used to store element locator values in a centralized location instead of
hard coding them within the scripts. We do create a property file (.properties) to store all the
element locators and these property files act as an object repository in Selenium WebDriver.
In QTP, there is an Object Repository concept. When a user records a test, the objects and
its properties are captured by default in an Object Repository. QTP uses this Object
Repository to play back the scripts. Coming to Selenium, there is no default Object Repository
concept. It doesn’t mean that there is no Object Repository in Selenium. Even though there is
no default one still we could create our own. In Selenium, we call objects as locators (such as
ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, XPath, and CSS). Object
repository is a collection of objects. One of the ways to create Object Repository is to place all
the locators in a separate file (i.e., properties file). But the best way is to use Page Object
Model. In the Page Object Model Design Pattern, each web page is represented as a class.
All the objects related to a particular page of a web application are stored in a class.
97. What is Page Object Model in Selenium?
Page Object Model is a Design Pattern which has become popular in Selenium Test
Automation. It is widely used design pattern in Selenium for enhancing test maintenance and
reducing code duplication. Page object model (POM) can be used in any kind of
framework such as modular, data-driven, keyword driven, hybrid framework etc. A page
object is an object-oriented class that serves as an interface to a page of your Application
Under Test(AUT). The tests then use the methods of this page object class whenever they
need to interact with the User Interface (UI) of that page. The benefit is that if the UI changes
for the page, the tests themselves don’t need to change, only the code within the page object
needs to change. Subsequently, all changes to support that new UI is located in one place.
We have seen that ‘Page Object Model’ is a way of representing an application in a test
framework. For every ‘page’ in the application, we create a Page Object to reference the
‘page’ whereas a ‘Page Factory’ is one way of implementing the ‘Page Object Model’.
99. What is the difference between Page Object Model (POM) and Page Factory?
Page Object is a class that represents a web page and hold the functionality and members.
Page Factory is a way to initialize the web elements you want to interact with within the page
object when you create an instance of it.
Code reusability – We could achieve code reusability by writing the code once and use it in
different tests.
Code maintainability – There is a clean separation between test code and page specific
code such as locators and layout which becomes very easy to maintain code. Code changes
only on Page Object Classes when a UI change occurs. It enhances test maintenance and
reduces code duplication.
Object Repository – Each page will be defined as a java class. All the fields in the page will
be defined in an interface as members. The class will then implement the interface.
Readability – Improves readability due to clean separation between test code and page
specific code
101. How can you use the Recovery Scenario in Selenium WebDriver?
There are two cases which are majorly used to upload a file in Selenium WebDriver such
as using SendKeys Method and using AutoIT Script.
Practical Example.
Practical Example
104. How to run Selenium WebDriver Test from the command line?
1 driver.switchTo().frame();
106. How to connect a Database in selenium?
As we all know Selenium WebDriver is a tool to automate User Interface. We could only
interact with Browser using Selenium WebDriver.
We use JDBC Driver to connect the Database in Selenium (While using Java Programming
Language).
Practical Example
107. How To Resize Browser Window Using Selenium WebDriver?
To resize the browser window to particular dimensions, we use ‘Dimension’ class to resize the
browser window.
Practical Example
Practical Example
109. How To Perform Right Click Action (Context Click) In Selenium WebDriver?
Practical Example
Practical Example
In some applications, we may face a situation to automate drag and drop an item from one
location to another location. We could not achieve these using basic elements. Selenium has
provided an “Actions” class to handle this kind of scenarios. We overcome this kind of
scenarios such as drag and drop using Actions Class.
Practical Example
Practical Example
113. Have you used any crossbrowsertesting tool to run selenium scripts on cloud?
I have used BrowserStack to run selenium tests on multiple browsers & Multiple operating
systems in parallel. Earlier we have made a video on how to use BrowserStack to run
selenium scripts on the cloud. Find the link in the description below.
Some of the continuous integration tools are Jenkins, TeamCity, Bamboo, Travis, Circle Ci,
Bitbucket.
Selenium
Katalon Studio
Appium
Unified Functional Testing
Travis CI
Egg Plant
Watir
Tricentis Tosca
Test Sigma
IBM Rational Functional Tester
Test Complete
QuerySurge
JMeter
Jenkins
Bamboo
Docker
PagerDuty
JIRA
GitHub
As we all know Selenium WebDriver is a tool to automate User Interface. We could only
interact with Browser using Selenium WebDriver.
Sometimes, we may face a situation to get the data from the Database or to modify
(update/delete) the data from the Database. If we plan to automate anything outside the
vicinity of a browser, then we need to use other tools to achieve our task. To achieve the
Database connection and work on it, we need to use JDBC API Driver.
The Java Database Connectivity (JDBC) API provides universal data access from the Java
programming language. Using the JDBC API, you can access virtually any data source, from
relational databases to spreadsheets and flat files. It lets the user connect and interact with
the Database and fetch the data based on the queries we use in the automation script. JDBC
is a SQL level API that allows us to execute SQL statements. It creates a connectivity
between Java Programming Language and the database.
1
119. What is TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from unit
testing to integration testing.
121. What is TestNG Assert and list out some common Assertions supported by
TestNG?
TestNG Asserts help us to verify the condition of the test in the middle of the test run. Based
on the TestNG Assertions, we will consider a successful test only if it is completed the test run
without throwing any exception.
In TestNG framework, we need to create TestNG XML file to create and handle multiple test
classes. We do configure our test run, set test dependency, include or exclude any test,
method, class or package and set priority etc in the XML file.
Output:
1 Test Case 1
2 Test Case 2
124. What is Parameterized testing in TestNG?
Parameterized tests allow developers to run the same test over and over again using different
values.
TestNG allows you to perform sophisticated groupings of test methods. Not only can you
declare that methods belong to groups, but you can also specify groups that contain other
groups. Then TestNG can be invoked and asked to include a certain set of groups (or regular
expressions) while excluding another set. This gives you maximum flexibility in how you
partition your tests and doesn’t require you to recompile anything if you want to run two
different sets of tests back to back.
Ans. TestNG listeners are used to configure reports and logging. One of the most widely used
listeners in TestNG is ITestListener interface. It has methods like onTestStart,
onTestSuccess, onTestFailure, onTestSkipped etc. We should implement this interface
creating a listener class of our own. Next, we should add the listeners annotation
(@Listeners) in the Class which was created.
Practical Example
1 @DataProvider(name="getData")
2 public Object[][] getData(){
3 //Object [][] data = new Object [rowCount][colCount];
4 Object [][] data = new Object [2][2];
5
6 data [0][0] = "FirstUid";
7 data [0][1] = "FirstPWD";
8
9 data[1][0] = "SecondUid";
10 data[1][1] = "SecondPWD";
11
12 return data;
13
14 }
Practical Example
I would like to conclude this post here. Final words, Bookmark this post “Selenium Testing
Interview Questions” for future reference. We keep on updating this post based on user
requests.