Professional Documents
Culture Documents
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.
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.
1- A feature.
2- A user scenario.
3- The scenario outline.
4- A <Given> clause.
5- A <When> clause.
6- A <Then> clause.
Cucumber tags help in filtering the scenarios. We can tag the scenarios and then run them
based on tags.
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.
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/
/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
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.
1. Implicit Wait
2. Explicit Wait
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.
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.
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.
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
@Test
public void TestJavaS1()
{
// Open Firefox
WebDriver driver=new FirefoxDriver();
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
Tell me any 5 webdriver common exceptions which you faced during software test case
execution.
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.
If you want to use Grid (which is run via selenium-server-standalone) then you *must* use
RemoteWebDriver.
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 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;
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);
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
source : https://sites.google.com/site/testingbulletin/selenium/interview-questions/selenium-
webdriver