You are on page 1of 11

Tell me about your Project?

My current project is to develop and support Automation Framework using Selenium WebDriver, Java, Junit
and Maven tools. We followed Page Object Design pattern using which we have created Page Objects for each
page template that we have. In our tests we have written our tests against those page objects. We also have
some tests which are Data Driven as we need to run these tests against multiple sets of data. we have build
jobs set up for our Regression and Functional tests using Jenkins.

Tell me how page object framework is created?


Page Object is a design pattern where we create a class file for each Page template we have. In these page
classes, we define the locators present on the page and also write the functions around it. In our tests we
create an instance of the page class and then write assert statements
by calling the functions from the page class.

Tell me how Data driven framework is created?


If we are using excel to get data for testing, we need to create an excel utility class file which access the excel
file and returns call data. We can use this data as an input whereever needed. For example if we are creating a
script for login functionality, the data for username
and password fields can be gathered from the excel file.

How do you set up Selenium Grid?


To configure your tests on remote servers we need to set up Hub and Node. We need to first download
"Selenium-Standalone-Server.jar" on both local machine and remote machine. On you local machine run
command "java -jar selenium-server-standalone-2.30.0.jar -role hub". This will set our machine as hub from
where we can run the tests. we need to register remote serves as node with the hub. Once set up, when we
launch tests on hub the tests will run on remote servers.

Have you worked with Selenium Grid?


Yes we currently run our tests on remote servers. On Jenkins, we have selenium plugin is installed. We can set
up grid on Jenkins using this plugin. So we have registered remote servers with various OS and browser
configurations as nodes to hub in Jenkins. When you run the build in Jenkins the tests will start executing on
the appropriate nodes.

Explain Git Workflow?


https://www.atlassian.com/blog/git/simple-git-workflow-simple
Explain Agile Methodology in your current Project?
https://xbsoftware.com/blog/software-development-life-cycle-sdlc-scrum-step-step/

What are the prereqs for building a Selenium Cucumber automation framework?
You might like to consider the following facts while creating a productive and scalable test
framework.

1- Identify the type of application you are going to test. Is it a Web app, support mobile devices
or runs on a desktop.
2- Would it require backend testing? e.g. Databases or SDK.
3- Decide on the input format. Is it static or dynamic?
4- Do you need to test the app for internationalization?
5- It must have a report which can help you trace a failure with minimum efforts.
6- It must support auto-generation of parametrization tests.
7- Have a config file to define any setup related settings or the global properties.
8- Apply abstraction at every level to separate the functionality.
If you follow the above rules, then youll land up with a product which is easy to maintain and
free to scale.

What are the two files which you need to run a Cucumber test scenario?
If you want to execute a Cucumber test, then make sure it has the following two files.

1- A feature file.
2- A step definition file.

What does a feature file contain?


A feature file in cucumber specifies parameters and conditions for executing the test code. It
can combine any of the following.

1- A feature.
2- A user scenario.
3- The scenario outline.
4- A <Given> clause.
5- A <When> clause.
6- A <Then> clause.

What is a profile in cucumber?


You can create Cucumber profiles to run a set of features and step definitions. Use the following
command to execute a cucumber profile.
1 cucumber features -p <profile_name>
2
3 #Example: cucumber features -p acceptance

What are cucumber tags? And why do we use them?

Cucumber tags help in filtering the scenarios. We can tag the scenarios and then run them
based on tags.

1- We can add tags to scenarios with <@> symbol.


2- We can use the following command to run a cucumber tagged scenario.
cucumber features -t @<tag_name>

#Example: cucumber features -t @test

What is the purpose of cucumber dry-run?


We use to compile the cucumber feature files and step definitions. If there occur any
compilation errors, then it shows them on the console.

Why do you use the scenario outline?


We use it to execute the same scenario with different test data.

List out some of the main differences between Jbehave and Cucumber?
However, the Cucumber and Jbehave share the same perspective, but there are few key
differences.

1- Jbehave is Java-based and Cucumber is Ruby-based.


2- Jbehave is story-driven whereas the Cucumber is feature-driven.

What are the steps to generate a report in Cucumber?


We run the following command to produce HTML reports.
cucumber <featurename>.feature --format html --out report.html --format pretty

Refer: http://www.techbeamers.com/selenium-webdriver-cucumber-interview-questions/
https://mindmajix.com/ruby-cucumber-interview-questions
https://www.testingexcellence.com/bdd-guidelines-best-practices/

TestNG related questions: http://www.techbeamers.com/testng-framework-interview-


questions-answers/
http://www.softwaretestingmaterial.com/testng-interview-questions/

What is the difference between absolute XPath and relative XPath?


An absolute xpath in HTML DOM starts with /html e.g.

/html/body/div[5]/div[2]/div/div[2]/div[2]/h2[1]
and a relative xpath finds the closed id to the dom element and generates xpath starting
from that element e.g.

.//*[@id='answers']/h2[1]/a[1]
You can use firepath (firebug) for generating both types of xpaths

It won't make any difference which xpath you use in selenium, the former may be faster
than the later one (but it won't be observable)

Absolute xpaths are prone to more regression as slight change in DOM makes them
invalid or refer to a wrong element

How To Handle Dynamic Changing IDs In XPath.

if element's ID is changing every time when you reload the application and you have to use that
ID in XPath to locate element then you have to use functions like starts-with(@id, post-body-')
or contains(@id, post-body-') in xPath.

How many types of waits available In selenium WebDriver

There are two types of waits available in selenium WebDriver

1. Implicit Wait
2. Explicit Wait

What Is Implicit Wait and ExplicitWait In Selenium WebDriver?

ImplicitlyWait: Sometimes, Elements are taking time to be appearing on web application page.
Using implicit wait in Selenium WebDriver, we can poll the DOM for certain amount of time
when some element or elements are not available immediately on webpage.
Example:
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
If you will write above syntax in your test, your WebDriver test will wait 10 seconds for
appearing element on page.
ExplicitWait: Using explicit wait code In selenium WebDriver software automation testing tool,
You can define to wait for a certain condition to occur before proceeding further test code
execution.
Example:
WebDriverWait wait = new WebDriverWait(driver, 20);
Wait.until(expectedconditions.elementtobeclickable(By.xpath("//input[@id='gbqfq']")));
Tell me a reason behind bellow given WebDriver exception and how will you resolve It?
"Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate
element"

We will get this exception when WebDriver is not able to locate element on the page of software
web application using whatever locator you have used in your test. To resolve this Issue, I will
check bellow given things.

o First of all I will check that I have placed implicitlyWait code in my test or not. If you have
not placed implicitlyWait in your test and any element is taking some time to appear on
page then you can get this exception. So I will add bellow given line at beginning of my
test case code to wait for 15 seconds for element to be present on page. In 70% cases,
this step will resolve Issue.

Driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

o Another reason behind this Issue is element's ID Is generated dynamically every time
when reloading the page. If I have used element's ID as an element locator or used it in
xpath to locate the element then I need to verify that ID of element remains same every
time or It Is changing? If it is changing every time then I have to use alternative element
locating method. In 20% cases, this step will resolve your Issue.
o If implicitlyWait is already added and element locator is fine then you need to verify that
how much time it (element) is taking to appear on page. If It Is taking more than 15
seconds then you have to put explicitWait condition with 20 or more seconds wait
period as bellow. In 5 to 10% cases, this step will resolve your Issue. View Example.

WebDriverWait wait = new WebDriverWait(driver, 25);


Wait.until(expectedconditions.elementtobeclickable(By.cssselector("#input")));

Can you tell me a difference between driver.get() and driver.navigate() methods?

driver.get() method is generally used for Open URL of web application and it will wait till the
whole page gets loaded.
driver.navigate() method is generally used for navigate to URL of software web application,
navigate back, navigate forward, refresh the page. It will just navigate to the page but it will not
wait till the whole page gets loaded.

Arrange bellow given drivers In fastest to slowest sequence?


Firefox Driver, HtmlUnit Driver, Internet Explorer Driver.
Fastest to slowest driver sequence is as bellow.

1. HtmlUnitDriver
2. FirefoxDriver
3. InternetExplorerDriver

Do you have faced any technical challenges with Selenium WebDriver software test
automation?

Yes, I have faced many technical challenges during selenium webDriver test cases development
and few of them are listed below.

1. Sometimes, Some elements like text box, buttons etc. are taking more time(more than
given Implicit wait time) to appear on page or to get enabled on page. In such situation,
if I have used only Implicit wait then my test case can run fine on first run but it may fail
to find element on second run. So we need provide special treatment for such elements
so that webDriver script waits for element to be present or get enabled on page of
software web application during test execution. We can use ExplicitWait to handle this
situation.
2. Handling dynamic changing ID to locate element is tricky. if element's ID is changing
every time when you reload the application and you have to use that ID in XPath to
locate element then you have to use functions like starts-with(@id, post-body-') or
contains(@id, post-body-') in xPath.
3. Clicking on sub menus which are getting rendered on mouse hover of main menu is
somewhat tricky. You need to use webDriver's Actions class to perform mouse hover
operation.
4. If you have to execute your test cases in multiple browsers then one test case can run
successfully in Firefox browser but same test case may fail in IE browser due to the
timing related issues (NoSuchElementException) because test execution in Firefox
browser is faster than IE browser. You can resolve this issue by increasing Implicit wait
time when you run your test in IE browser.
5. Above issue can arise due to the unsupported XPath in IE browser. In this case, you need
to you other locating methods (ID, Name etc.,) to locate element.
6. Handling JQuery elements like moving pricing slider, date picker, drag and drop etc., is
tricky. You should have knowledge of webDriver's Advanced User interactions API to
perform all these actions.
7. Working with multiple Windows, Frames, and some tasks like Extracting data from web
table, Extracting data from dynamic web table, Extracting all Links from page, Extracting
all text box from page are also tricky and time consuming during test case preparation.
8. There is not any direct command to upload or download files from web page using
selenium webDriver. For downloading files using selenium webDriver, you need to
create and set Firefox browser profile with webDriver test case.
9. WebDriver do not have any built in object repository facility. You can do it using java
.properties or .java files to create object repository.
10. webDriver do not have any built in framework or facility using which we can achieve
below given tasks directly :
1. Capturing screenshots
2. Generating test execution log
3. Reading data from files
4. Generating test result reports, Manage test case execution sequence.
11. To achieve all these tasks, we have to use external services with webDriver like Log4J to
generate log, Apache POI API to read data from excel files, TestNG XSLT reports to
generate test result reports. TestNG to manage test case execution, .properties file to
create object repository. All these tasks are very time consuming.

What are the advantages of TestNG over JUnit.


JUnit is part of Java and its shipped with most of the IDEs such as Eclipse and NetBeans.
There are many testing framework being developed using JUnit. TestNGis an open source
framework. It supports parametrization, data driven testing, parallel execution.
Annotations made testers life easy. Test cases can be Grouped & Prioritized more
easily

What are different annotations supported by TestNG ?


https://www.tutorialspoint.com/testng/testng_basic_annotations.htm

What Is the usage of testng.xml file?


In TestNG, we cannot define a suite in testing source code, but it is represented by one XML
file, as suite is the feature of execution. It also allows flexible configuration of the tests to be run.

Tell me any 5 assertions of TestNG which we can use In selenium webdriver software
testing tool.
What Is the difference between findelement and findElements ?
The difference between findElement() and findElements() method is the first returns a
WebElement object otherwise it throws an exception and the latter returns a List of
WebElements

How to create custom firefox profile and how to use It In selenium webdriver software
test?
Ans : https://www.guru99.com/firefox-profile-selenium-webdriver.html
When we can use Actions class In Selenium WebDriver test case?
Ans: To handle Keyboard & Mouse Events

Can we capture screenshot In Selenium WebDriver software testing tool? How?


public class ScreenshootGoogle {

@Test
public void TestJavaS1()
{
// Open Firefox
WebDriver driver=new FirefoxDriver();

// Maximize the window


driver.manage().window().maximize();

// Pass the url


driver.get("http://www.google.com");

// Take screenshot and store as a file format


File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
// now copy the screenshot to desired location using copyFile //method
FileUtils.copyFile(src, new File("C:/selenium/error.png"));
}

catch (IOException e)
{
System.out.println(e.getMessage());

}
}

Tell me any 5 webdriver common exceptions which you faced during software test case
execution.

Why we need to customize Firefox browser profile In webdriver test?


A profile is a user's personal settings. When you want to run a reliable automation
on a Firefox browser, it is recommended to make a separate profile.

What is Difference between getAttribute() and getText()?


<input attr1='a' attr2='b' attr3='c'>foo</input>
getAttribute(attr1) you get 'a'

getAttribute(attr2) you get 'b'

getAttribute(attr3) you get 'c'


getText() with no parameter you can only get 'foo'

What is the difference between WebDriver and Remote WebDriver?


Difference between WebDriver and RemoteWebDriver:

WebDriver is actually interface and implementations are firefoxdriver, iedriver,


chromedriver, htmlunitdriver, remoteWebDriver

If tests are running on local browser then you can use all except RemoteWebDriver. If tests
are running on remote machines browser then use
RemoteWebDriver

You don't actually use WebDriver, it's just an interface. Implementations of it include:
InternetExplorerDriver, FirefoxDriver, ChromeDriver, HtmlUnitDriver, OperaDriver and
RemoteWebDriver.

If you want to use the browser on the machine that is running the automation, then you can
use everything but RemoteWebDriver.

RemoteWebDriver requires the selenium-server-standalone to be running (the others do


not). This could be running on the same machine or a "remote" one.

If you want to use Grid (which is run via selenium-server-standalone) then you *must* use
RemoteWebDriver.

AFAIK RemoteWebDriver can be used when Development environment and Execution


environment are
a) The same machine
b) Different machines.

The only requirement is that for a RemoteWebDriver to work, you would always have to
have it pointing to the URL of a Grid.

So if a person needs to work with Grid he/she would have to stick with RemoteWebDriver,
and if there is no need for a grid then he/she can use anything other than the
RemoteWebDriver.

f you are using any of the drivers not RemoteWebDriver, they assume
the communication to the web browser is local. So if I have:

Webdriver driver = new FirefoxDriver();

using driver will access Firefox on the local machine, directly. If I


use RemoteWebDriver, it requires you to tell it where the Selenium
Server (Grid) is located and which web browser you want to use. For
example,

WebDriver driver = new RemoteWebDriver(new URL Desired capabilities.firefox());


This example assumes that Selenium Server is running on localhost with
the default port of 4444. The nice thing about this is you can run
Selenium Server on any machine, change the URL to point to the new
machine and run the tests. For example, I run the test code from my
Mac OS X computer but I run Selenium Server on a Window XP machine.
This way I can launch Internet Explorer tests from my Mac OS X
computer.

WebDriver is the interface that you should be using throughout your tests.
RemoteWebDriver is a concrete implementation of that interface.
As a general principle, it always a wise idea to code against
interfaces wherever possible.

I wants to pass parameter In software test case through testng.xml file. How can I do It?

I wants to scroll my software web application page by 300 pixel. Tell me how can i do it?

package Testing_Pack;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Scrolling {

WebDriver driver;
@BeforeTest
public void setup() throws Exception {
driver =new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://only-testing-blog.blogspot.in");
}

@Test
public void Scroll_Page() throws IOException, InterruptedException {
//To scroll down web page by 600 pixels In x(vertical) direction.
//You can y parameter to scroll page In horizontal direction.
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("window.scrollBy(0,600)", "");

Thread.sleep(3000);

//To scroll up web page by 300 pixels In x(vertical) direction.


javascript.executeScript("window.scrollBy(0,-300)", "");
}
}

Source : http://www.software-testing-tutorials-automation.com/2015/02/scroll-down-up-
web-page-using.html

Refer: http://www.software-testing-tutorials-automation.com/2015/07/latest-interview-questions-
on-selenium.html

how to run selenium scripts in Jenkins


http://www.seleniumeasy.com/jenkins-tutorials/invoke-testng-xml-tests-from-jenkins

source : https://sites.google.com/site/testingbulletin/selenium/interview-questions/selenium-
webdriver

You might also like