Part 1
·
Selenium
WebDriver Is well designed object oriented API which Is developed to
automate web and mobile applications testing process. WebDriver API Is bigger than Selenium RC but
It's Architecture Is simple and easy to understand compared Selenium RC
API.
·
We can automate our
web application testing process using selenium webdriver.
·
We can say It advanced
version of selenium RC because some limitations of selenium RC has been
overcome In selenium WebDriver.
·
WebDriver Is designed
to provide better support for dynamic changing pages. Example : Web
page elements changing without reloading the page. In this case WebDriver works
better.
·
Selenium Webdriver Is
more faster that Selenium RC as It Is directly Interacting with web browsers
and mimic the behavior of a real user. Example : User clicks
on button of web page or moving mouse on main menu to get the sub menu list.
WebDriver works Same.
·
All popular browser
vendors are active participants In selenium WebDriver's development and all of
them have their own engineers team to Improve this framework.
You can Include answers of Question 2, Question 3, Question 4 and Question 5 In answer of this question If Interviewer need more detail
on selenium webdriver.
2 : Tell Me
WebDriver Supported Browsers?
Answer : Selenium
WebDriver API has a many different drivers to test your web application In
different browsers. List of Webdriver browser drivers are as bellow.
·
Firefox
Driver - For Mozilla
Firefox browser
·
Internet
Explorer Driver -
For Internet Explorer browser
·
Chrome
Driver - For Google
Chrome browser
·
HtmlUnit
Driver -
GUI-Less(Headless) browser for Java programs
·
Opera
Driver - For Opera
browser
3 : Tell Me
WebDriver Supported Mobile Testing Drivers?
Answer : We can
get support of mobile application testing using Selenium
webdriver. Selenium WebDriver supports bellow given drivers to test mobile
application.
·
AndroidDriver
·
OperaMobileDriver
·
IPhoneDriver
4 : Which
Programming Languages Supported By Selenium WebDriver To Write Test Cases?
Answer : Selenium
WebDriver Is very wast API and It support many different languages to write
test cases for your software web application. List of WebDriver supported
languages are as bellow.
·
C#
·
Python
·
Ruby
·
Perl
·
PHP
5 : Which Different
Element Locators Supported By Selenium WebDriver?
Answer : Selenium WebDriver supports bellow given element locators.
Answer : Selenium WebDriver supports bellow given element locators.
Part 2
6 : What are the benefits of automation testing.
Answer : We can get
bellow given benefits If automate our testing process.
·
Fast
Test Execution : Manual testing
process Is time consuming. Automation tests are faster and takes less time to
execute tests compared to manual test execution.
·
Re-usability
Of Test Cases : You need to
prepare automation test cases only one time. Then you can use same test cases
for all upcoming version release of software application. However you need to
modify your test cases If there Is any flow change of business logic changes In
software. But It Is less time consuming.
·
Testing
Cost Reduction : You have to
put human efforts only one time to automate your test process. Latter on
automation tool will work for you at place of human resource.
·
Better
Test Coverage In Each Version Release: You have to Implement test scenarios only once In your
automation test cases. Latter on you can execute same test cases In all
upcoming release. So each scenarios will be tested In every version release.
·
Easy
For Compatibility Testing :
It Is easy to run same tests In combination of different OS and browser
environments using automation tools.
7 : Does Selenium
WebDriver Support Record And Playback Facility?
Answer : No.
WebDriver do not have any record and playback facility. But you can record your
tests In one of the selenium version called Selenium IDE and then you can
export your recorded tests In webdriver compatible format as per your preferred
language.
You can VIEW MORE TUTORIALS on selenium IDE or @ PART 1 andPART 2 for more details.
8 : Which Operating systems support Selenium WebDriver?
Answer : At present, Mainly bellow given operating systems support Selenium WebDriver.
·
Windows - Windows XP, Windows
7, Windows 8 and Windows 8.1
·
Apple
OS X
·
Linux - Ubuntu. Other versions of linux should
support too.
9 : Selenium
WebDriver Is Paid Or Open Source Tool? Why you prefer to use It?
Answer : All
versions of selenium tool are open source. You can use any version of selenium
In free of charge.
I choose to use It because
I choose to use It because
·
Open Source.
·
It has multi-browser
support.
·
Multi-OS support.
·
Multi types of
locators support. So If one not works, We can use another type.
·
Web as well mobile
application testing support.
·
Many testers are using
selenium WebDriver to automate their testing process. So getting solution of
any complex Issue very easily on Internet.
·
It Is extendable and
flexible.
·
Continues support from
WebDriver's development team to Improve the API and resolve current Issues.
10 : Which OpenSource
Framework Is Supported In WebDriver With Java?
Answer : Bellow given 2 java frameworks are supported by selenium WebDriver.
Answer : Bellow given 2 java frameworks are supported by selenium WebDriver.
·
JUnit
·
TestNG
·
Part 3
·
11 : Can you tell me the syntax to open/launch Firefox browser In WebDriver?
11 : Can you tell me the syntax to open/launch Firefox browser In WebDriver?
·
Answer : We can open new Mozilla Firefox
browser Instance using bellow given syntax.
·
WebDriver driver = new FirefoxDriver();
·
Answer : In Selenium WebDriver, XPath is
used to locate the elements. Using XPath, We can navigate through elements and
attributes In an XML document to locate webpage elements like buttons, text
box, links, Images etc..
·
13 : Which tool you are using to find the
XPath of any element?
·
Answer : I am using Mozilla Firefox AddOns
FireBug and FirePath to find the XPath of web elements.
VIEW MORE TUTORIALS ON SELENIUM WEBDRIVER
VIEW MORE TUTORIALS ON SELENIUM WEBDRIVER
·
·
14 : What is the difference
between absolute XPath and relative XPath?
·
Answer :
Absolute XPath : Absolute XPath Is the full path starting from root node and ends with desired descendant element's node. It will start using single forward slash(/) as bellow.
Absolute XPath : Absolute XPath Is the full path starting from root node and ends with desired descendant element's node. It will start using single forward slash(/) as bellow.
·
Example
Of Absolute XPath :
·
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/form/table/tbody/tr[1]/td/input
·
·
Above XPath
Is absolute XPath of calc result box given on THIS PAGE. It
starts top node html and ends with input node.
·
·
Relative
XPath : Instead of
starting from root node, Relative XPath starts from any In between node or
current element's node(last node of element). It will start using double
forward slash(//) as bellow.
Example Of Relative XPath :
Example Of Relative XPath :
·
//input[@id='Resultbox']
·
·
15 : How To Handle Dynamic Changing IDs In
XPath.
Example : //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1]
In this XPath "3647323225296998740" Is changing every time when reloading the page. How to handle this situation?
Example : //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1]
In this XPath "3647323225296998740" Is changing every time when reloading the page. How to handle this situation?
·
Answer : There are many different alternatives In such case.
Alternative 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then we can write xpath as bellow.
Answer : There are many different alternatives In such case.
Alternative 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then we can write xpath as bellow.
·
//div[@class='post-body entry-content']/div[1]/form[1]/input[1]
·
Alternative 2 : You can use absolute xpath(full xpath) where you not need to give any attribute names In xpath.
Alternative 2 : You can use absolute xpath(full xpath) where you not need to give any attribute names In xpath.
·
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/div[1]/form[1]/input[1]
·
Alternative 3 : Use starts-with function. In this xpath's ID attribute, "post-body-" part remain same every time. So you can use xpath as bellow.
Alternative 3 : Use starts-with function. In this xpath's ID attribute, "post-body-" part remain same every time. So you can use xpath as bellow.
·
//div[starts-with(@id,'post-body-')]/div[1]/form[1]/input[1]
·
Alternative 4 : Use contains function. Same way you can use contains function as bellow.
Alternative 4 : Use contains function. Same way you can use contains function as bellow.
·
div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]
Part 4
16 : How to press ENTER key button on text
box In selenium webdriver?
Answer : To press ENTER key using selenium
WebDriver, We need to use selenium Enum Keys with Its
constant ENTER as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys(Keys.ENTER);
17 : How many types of waits available In selenium WebDriver
Answer : There are two types of waits
available In selenium WebDriver.
1.
Implicit Wait
2.
Explicit Wait
VIEW TUTORIALS on Implicit and Explicit Waits with
practical examples detailed description.
18 : What Is Implicit Wait In
Selenium WebDriver?
Answer : Sometimes, Elements are taking time to
be appear on page. Using Implicit wait In webdriver test case, We can poll the
DOM for certain amount of time when some element or elements are not available
Immediately on webpage.
Implicit Wait Example :
Implicit Wait 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.
19 : What
Is Explicit Wait In Selenium WebDriver?
Answer : Using explicit wait code In
selenium webdriver, You can define to wait for a certain condition to
occur before proceeding further test code execution.
Explicit Wait Example :
Explicit Wait Example :
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gbqfq']")));
Above code will wait for 20 seconds for
targeted element to be displayed and enabled or we can say clickable.
20 : I wants to pause my test execution
for fix 10 seconds at specific point. How can I do It?
Answer : You can
use java.lang.Thread.sleep(long milliseconds) method to pause
the test execution for specific time. If you wants to pause your test execution
for 10 seconds then you can use bellow given syntax In your test.
Thread.sleep(10000);
Part 5
21 : How
does selenium RC drive the browser?
Answer :
When browser loaded In Selenium RC, It ‘injected’ javascript functions into the browser and then It Is using javascript to drive the browser for application under test.
When browser loaded In Selenium RC, It ‘injected’ javascript functions into the browser and then It Is using javascript to drive the browser for application under test.
22 : How does the
selenium WebDriver drive the browser?
Answer : Selenium webdriver works like
real user Interacting with web page and Its elements. It Is using each
browser's native support to make direct calls with browser for your application
under test. There Is not any Intermediate thing In selenium
webdriver to Interact with web browsers.
VIEW MORE TUTORIALS on selenium WebDriver.
VIEW MORE TUTORIALS on selenium WebDriver.
23 : Do
you need Selenium Server to run your tests In selenium WebDriver?
Answer : It
depends. If you are using only selenium webdriver API to run your tests and you
are running your all your tests on same machine then you do not need selenium
server because In this case, webdriver can directly Interact with browser using
browser's native support.
You need selenium server with webdriver when you have to perform bellow given operations with selenium webdriver.
You need selenium server with webdriver when you have to perform bellow given operations with selenium webdriver.
·
When you are using
remote or virtual machine to run your webdriver tests and that machine
have specific browser version that is not on your current machine.
·
When you are
using selenium-grid to distribute your webdriver's test execution on
different remote or virtual machines.
24 : Bellow given
syntax will work to navigate to specified URL In WebDriver? Why?
driver.get("www.google.com");
Answer : No.
It will not work and show you an exception like : "Exception in thread
"main" org.openqa.selenium.WebDriverException: f.QueryInterface is
not a function" when you run your test.
You need to provide http:// protocol with URL In driver.get method as bellow.
You need to provide http:// protocol with URL In driver.get method as bellow.
driver.get("http://www.google.com");
Now It will work.
25 : 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"
Answer : You will get
this exception when WebDriver Is not able to locate element on the page using
whatever locator you have used In your test. To resolved this Issue, I will
check bellow given things.
·
First of all I will
check that I have placed Implicit wait code In my test or not. If you have not
placed Implicit timeout 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 resolved Issue. View
Practical Example Of Implicit Wait.
driver.manage().timeouts().implicitlyWait(15,
TimeUnit.SECONDS);
·
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.
·
If Implicit wait 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 explicit wait 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("#submitButton")));
Part 6
26 : Can we automate desktop application's
testing using selenium WebDriver?
Answer : No. This Is the biggest disadvantage
of selenium WebDriver API. We can automate only web and mobile application's
testing using selenium WebDriver.
27 : Can you tell me the alternative
driver.get() method to open URL In browser?
Answer : We can use anyone from bellow
given two methods to open URL In web browser In selenium webdriver.
1.
driver.get()
2.
driver.navigate().to()
28 : Can you tell
me a difference between driver.get() and driver.navigate() methods?
Answer : Main and mostly used functions of both
methods are as bellow.
driver.get()
driver.get()
·
driver.get() method Is
generally used for Open URL.
·
It will wait
till the whole page gets loaded.
driver.navigate()
·
driver.navigate()
method Is generally used for navigate to URL, navigate back, navigate forward,
refresh the page.
·
It will just navigate
to the page but wait not wait till the whole page gets loaded.
29 : WebDriver has built In Object
Repository. Correct me If I am wrong.
Answer : No. WebDriver do not have any
built In object repository till now. But yes, I am using java .properties file
In my framework to store all required element objects In my tests. View Example.
30 : Can you tell me syntax to set browser
window size to 800(Width) X 600(Height)?
Answer : We can set browser window size
using setSize method of selenium webdriver. To set size at
800 X 600, Use bellow given syntax In your test case.
800 X 600, Use bellow given syntax In your test case.
driver.manage().window().setSize(new
Dimension(500,500));
Part 7
31 : Can you tell
me the names of different projects of selenium?
Answer : At present,
Selenium has four different projects as bellow.
·
Selenium
IDE : It Is Firefox
add-on which allows you to record and playback your tests In Firefox browser.
·
Selenium
RC : It Is web
application automation tool which allows you to write your tests In many
different programming languages.
·
Selenium
WebDriver : It Is well
designed object oriented API developed to automate web and mobile application
testing process. You can write your tests In different languages too In
selenium webdriver.
·
Selenium
Grid : Grid allows
you to execute your tests In parallel by distributing them on different
machines having different browser/OS combinations.
32 : I wants to use
java language to create tests with Selenium WebDriver. Can you tell me how to
get latest version of WebDriver?
Answer : You can download language specific
latest released client drivers for selenium WebDriver at http://docs.seleniumhq.org official
website. For java language, You will get bunch of jar files In zip folder. And
then you can add all those jar files In your project's java build path as a
referenced libraries to get support of webdriver API.
33 : Can you tell
me the usage of "submit" method In selenium WebDriver?
Answer : We can use submit method to submit the
forms In selenium WebDriver. Example : Submitting registration form, submitting
LogIn form, submitting Contact Us form ect.. After filling all
required fields, We can call submit method to submit the form. VIEW EXAMPLE.
34 : Do you have
faced any Issue with "submit" method any time?
Answer : Yes, I have faced Issue like submit
method was not working to submit the form. In this case, Submit button of form
was located outside the opening <form> and closing </form> tags. In
this case submit method will not works to submit the form.
Also If submit button Is located Inside opening <form> and closing</form> tags but that button's type tag's attribute Isn't submit then submit method will not work. It(type tag's attribute) should be always submit.
Also If submit button Is located Inside opening <form> and closing</form> tags but that button's type tag's attribute Isn't submit then submit method will not work. It(type tag's attribute) should be always submit.
35 : What Is the
syntax to type value In prompt dialog box's Input field using selenium
WebDriver?
Answer : Prompt dialog Is just like
confirmation alert dialog but with option of Input text box as
bellow.
To Input value In that text box of prompt dialog, You can use bellow given syntax.
driver.switchTo().alert().sendKeys("Jhon");
Part 8
36 : When I am
running tests In Firefox Browser using selenium webdriver, It Is not showing me
any bookmarks, addons, saved passwords etc. In that browser. Do you know why?
Answer : Yes. It Is
because all those bookmarks, addons, passwords etc.. are saved In your regular
browser's profile folder so when you launch browser manually, It will use existing
profile settings so
It will show you all
those stuffs. But when you run your tests In selenium webdriver, It Is opening
new browser Instance with blank/new profile. So It will not show you bookmarks
and all those things In that browser Instance.
You can create custom firefox profile and then you can use It In
selenium webdriver test. In your custom profile, you can set all required
bookmarks, addons etc.. VIEW THIS EXAMPLE to
know how to set custom profile of firefox browser.
37 : Arrange
bellow given drivers In fastest to slowest sequence?
Firefox Driver, HtmlUnit Driver, Internet Explorer Driver.
Answer : HTMLUnit
Driver Is faster than all other drivers because It Is not using any UI to
execute test cases. Internet Explorer driver Is slower than Firefox and
HtmlUnit driver. So, Fastest to slowest driver sequence Is as bellow.
1.
HtmlUnit
Driver
2.
Firefox
Driver
3.
Internet
Explorer Driver
38 : What Is Ajax?
Answer : Asynchronous
JavaScript and XML Is full form of AJAX which Is used for creating
dynamic web pages very fast. Using ajax, We can update page behind the scene by
exchanging small amounts of data with server asynchronously. That means, Using
ajax we can update page data Without reloading page.
39 : How to
handle Ajax In selenium WebDriver?
Answer : Generally we
are using Implicit wait In
selenium WebDriver to wait for some element to be present on page. But Ajax
call can not be handled using only Implicit wait In your test because page not
get reloaded when ajax call sent and received from server and we can not assume
how much time It will take to receive ajax call from server.
To handle ajax call In selenium WebDriver, We needs to use
webdriver's FluentWait method or Explicit Waits which can wait for
specific amount of time with specific condition. You can get different Explicit
Waits examples links on THIS PAGE.
40 : On Google
search page, I wants to search for some words without clicking on Google Search
button. Is It possible In WebDriver? How?
Answer : Yes we can do
It using WebDriver sendKeys method where we do not need to use
Google Search button. Syntax Is as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("Search
Syntax",Keys.ENTER);
In above syntax, //input[@id='gbqfq'] Is xPath
of Google search text field. First It will enter "Search Syntax"
text In text box and then It will press Enter key on same text box to search
for words on Google.
Part 9
41 : What kind of testings are possible using selenium WebDriver? We can use It for any other purpose except testing activity?
Answer : Generally we
are using selenium WebDriver for functional and regression testing of software
web applications. We can also use It for data entry kind of work like
submitting online
forms using different data
forms using different data
42 : Give me any five different xPath syntax to locate bellow given Input element.
<input id="fk-top-search-box"
class="search-bar-text fk-font-13 ac_input" type="text" autofocus="autofocus"
value="" name="q" />
Answer : Five xPath syntax for
above element are as bellow.
//input[@id='fk-top-search-box']
//input[contains(@name,'q')]
//input[starts-with(@class,
"search-bar-text")]
//input[@id='fk-top-search-box' or @name='q']
//input[starts-with(@id, 'fk-top-search-box') and
contains(@class,'fk-font-13')]
See detailed tutorial on How To Locate XPath Of Element.
43 : Can
you tell me two drawbacks of xPath locators as compared to cssSelector
locator?
Answer : Two main
disadvantage of xPath locator as compared to cssSelector locator are
as bellow.
·
It Is slower
than cssSelector locator.
·
xPath which works In
one browser may not work In other browser because some browsers (Ex. IE) reads
only Lower-cased tag name and Attribute Name. So If used It In upper case
then It will work In Firefox browser but will not work In IE browser. Every
browser reads xPath In different way. In sort, do not use xPath locators In
your test cases If you have to perform cross browser testing using selenium
WebDriver.
44 : Why
xPath locator Is much more popular than all other locator types In WebDriver?
Answer : xPath locators
are so much popular In selenium webdriver test case development because
·
It Is very easy to
learn and understand for any new user.
·
There are many
functions to build xPath In different ways like contains, starts-with etc.. So
If one Is not possible you will have always another option to build xPath of
any element.
·
Presently many tools
and add-ons are available to find xpath of any element.
45 : Give
me WebDriver's API name using which we can perform drag and drop operation.
Answer : That API's
name Is Advanced User Interactions API using which we can
perform drag and drop operation. Same API can help us to perform some other
operations too like moveToElement,
doubleClick, clickAndHold, moveToElement, etc..
View Example1 and Example2 for dragging and dropping element.
View Example1 and Example2 for dragging and dropping element.
Part 10
46 : Can we perform drag and drop operation In Selenium WebDriver? Tell me a syntax to drag X element and drop It On Y element.
Answer : Yes, We can perform drag and drop operation using selenium webdriver's Advanced User Interactions API. Syntax Is like bellow.
new Actions(driver).dragAndDrop(X,
Y).build().perform();
47 : Do you
have faced any technical challenges with Selenium WebDriver test automation?
Answer : Yes, I have
faced bellow given technical challenges during selenium webdriver test cases
development and running.
·
Sometimes (Not
always), 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 wait for
element to be present or get enabled on page during test execution. We can use
Explicit wait to handle this situation. You can find different explicit wait
example links on THIS PAGE.
·
Handling dynamic
changing ID to locate element Is tricky. If element's ID Is changing every time
when you reload the page 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. Other alternate solutions to
handle this situation are described in answer of Question 15 of THIS PAGE.
·
Clicking on sub menus
which are getting rendered on mouse hover of main menu Is some what tricky. You
need to use webdriver's Actions class to perform mouse hover operation. You
can VIEW FULL EXAMPLE on
how to generate mouse hover event on main menu.
·
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 (nosuchelement exception) 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.
·
Above Issue can arise
due to the unsupported XPath In IE browser. In this case, You need to you OTHER ELEMENT LOCATING METHODS (ID,
Name, CSSSelector etc.)to locate element.
·
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. You can find few example links for working with
JQuery Items on THIS PAGE.
·
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.
·
There Is not any
direct command to upload or download files from web page using selenium
webdriver. For downloading files usign selenium webdriver, You need to create
and set Firefox browser profile with webdriver test case. You can VIEW PRACTICAL EXAMPLE.
·
Webdriver do not have
any built In object repository facility. You can do It using java .properties
file to create object repository as described In THIS EXAMPLE.
·
Webdriver do not have
any built In framework or facility using which we can achieve bellow 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. 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. ON THIS PAGE, I
have described how to create data driven framework step by step for selenium
webdriver. That framework contains all above functionality.
You can share other webdriver technical challenges which you
have faced by commenting bellow so that your experience can help to others
too.
Part 11
48 : Can you tell me a syntax to
close current webdriver Instance and to close all opened webdriver Instances?
Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
driver.close();
If there are opened multiple webdriver Instances and wants to close all of them then we can use webdriver's quit() method as bellow.
driver.quit();
49 : Is It possible to execute javascript directly during test execution? If Yes then tell me how to generate alert by executing javascript In webdriver script?
Answer :
Yes, we can execute javascript during webdriver test execution. To generate alert, You can write bellow given code In your script.
JavascriptExecutor javascript = (JavascriptExecutor)
driver;
javascript.executeScript("alert('Javascript
Executed.');");
VIEW DIFFERENT EXAMPLES to see usage of WebDriver's JavascriptExecutor.
50 : Give me a syntax to read javascript alert message string, clicking on OK button and clicking on Cancel button.
Answer :
We can read alert message string as bellow.
String alrtmsg =
driver.switchTo().alert().getText();
We can click on OK button of alert as bellow.
driver.switchTo().alert().accept();
We can click on Cancel button of alert as bellow.
driver.switchTo().alert().dismiss();
VIEW PRACTICAL EXAMPLE to handle alert, Confirmation And Prompt popups.
51 : Tell me a scenario which we can not automate In selenium WebDriver.
Answer :
1. Bitmap comparison Is not possible using selenium webdriver.
2. Automating captcha Is not possible. (Few peoples says we can automate captcha but I am telling you If you can automate any captcha then It Is not a captcha).
3. We can not read bar code using selenium webdriver.
52 : What Is JUnit?
Answer : Java developers use JUnit as unit testing framework to write repeatable tests for java programming language. It Is very simple and open source framework and we can use It In selenium webdriver test scripts creation to manage them In well manner.
Part 12
53 : Which Is the
latest version of JUnit.
Answer : Current latest
version of JUnit Is 4.12-beta-2. This can change In future. To check
latest released version of JUnit, You can Visit JUnit Official WebSite.
54 : Tell me
different JUnit annotations and Its usage.
Answer : JUnit has
bellow given different annotations.
·
@Test : @Test annotation Is useful
to Identify method as a Test method.
·
@Before : @Before annotation method will be
executed before each and every @Test method.
·
@After : @After annotation method
will be executed after each and every @Test method.
·
@BeforeClass : @BeforeClass annotation
method will be executed before all @Test methods In a class(Means before
first @Test method).
·
@AfterClass : @AfterClass annotation
method will be executed after all @Test method In a class(Means after last
@Test method).
·
@Test(timeout=1000) : You can set @Test method
execution timeout. This @Test method fails Immediately when Its
execution time cross 1000 milliseconds.
VIEW PRACTICAL EXAMPLE of JUnit annotations with selenium
webdriver.
55 : Write
sample JUnit @Test method that passes when expected ArithmeticException
thrown.
Answer : Sample JUnit
@Test to pass on expected ArithmeticException Is as bellow.
@Test(expected = ArithmeticException.class)
public void excOnDivision() {
int i =
5/0;
}
VIEW PRACTICAL EXAMPLE for Junit Timeout And Expected Exception Test.
56 : Write sample
JUnit @Test method that fails when unexpected ArithmeticException thrown.
Answer : Sample JUnit
@Test to fail on unexpected ArithmeticException Is as bellow.
@Test
public void excOnDivision() {
int i =
5/0;
}
57 : What
are the advantages of TestNG over JUnit.
Answer : Advantages of
TestNG over JUnit JUnit are as bellow.
TestNG Annotations
are simple and Easy to understand.
Easy to
parameterize the test cases In TestNG.
Easy to run test
cases In parallel.
Can generate Interactive XSLT test execution
reports using TestNG.
Part 13
58 : Tell me main features of JUnit.
Answer : JUnit features
are as bellow.
·
JUnit Is unit testing
framework. So It helps developers to create and run unit test cases very
easily.
·
There are many
different annotations available In JUnit. Using all those annotations, we can
Identify and configure webdriver test case very easily.
·
JUnit supports many
different assertions using which we can compare webdriver test's expected and
actual result.
·
We can create test
suite for multiple test cases to run all of them In one go using JUnit.
·
We can generate
webdriver test execution HTML reports using JUnit. VIEW EXAMPLE.
59 : What
are different assertions supported by JUnit?
Answer : List of JUnit
assertions as bellow.
1.
assertEquals
2.
assertFalse
3.
assertTrue
4.
assertNull
5.
assertNotNull
6.
assertSame
7.
assertNotSame
8.
assertArrayEquals
60 : How to
create and run JUnit test suite for selenium WebDriver?
Answer : For creating
JUnit test suite, we have to create test cases class files and one separate
test suite file. Then we can write syntax like bellow In test suite file to run
test suite.
@RunWith(Suite.class)
@SuiteClasses({ junittest1.class, junittest2.class })
public class junittestsuite {
}
In above example, junittest1.class and junittest2.class are test case class names.
VIEW PRACTICAL EXAMPLE on how to create and run JUnit test suite with selenium WebDriver.
61 : For
what purpose, assertTrue and assertFalse assertions are used?
Answer : In selenium webdriver test, We need to
assert Boolean conditions true and false. We can assert both these conditions
using assertTrue and assertFalse JUnit assertions.
62 : Can
you give me example of JUnit assertEquals assertion?
Answer : Example of
JUnit assertEquals assertion Is as bellow. It assert that values of
actTotal and expTotal are equal or not.
public void sumExample() {
int val1 =
10;
int val2 =
20;
int expTotal
= 35;
int actTotal
= 0;
actTotal =
val1 + val2;
assertEquals(actTotal,
expTotal);
}
Part 14
63 : What Is TestNG?
Answer : TestNG Is Open
Source(Freeware) framework which Is Inspired from NUnit and JUnit with
Introducing few new features and functionality compared to NUnit and JUnit to
make It easy to use and more powerful.
We can use TestNg with selenium webdriver to configure and run
test cases very easily, easy to understand, read and manage test cases, and to
generate HTML or XSLT test reports.
64 : Can
you describe major features of TestNG?
Answer : TestNG has
many major features like support of @DataProvider annotation to perform
data driven testing, can set test case execution dependency, test case
grouping, generate HTML and XSLT test execution report etc.. VIEW MORE FEATURES with
detailed description.
65 : Describe
the similarities and difference between JUnit and TestNG unit testing
frameworks.
Answer : You can find
all the similarities and difference between JUnit and TestNG framework
on THIS PAGE.
66 : How to
Install TestNG In Eclipse? How do you verify that TestNg Is Installed properly
In Eclipse?
Answer : To Install
TestNG In Eclipse, We have to follow steps as described on THIS PAGE.
67 : What
are different annotations supported by TestNG ?
Answer : TestNG
supports many different annotations to configure Selenium WebDriver test. You
can see mostly used annotations list with detailed description and practical
example link on THIS PAGE.
Part 15
68 : What Is the usage of testng.xml file?
Answer : In selenium WebDriver, We are using testng.xml file to configure our whole test suite In single file. Few of the tasks which we can specify In testng.xml file are as bellow.
·
We can define test
suite using set of test cases to run them from single place.
·
Can Include or exclude
test methods from test execution.
·
Can specify a group to
Include or exclude.
·
Can pass parameter to
use In test case.
·
Can specify group
dependencies.
·
Can configure parallel
test execution.
·
Can define listeners.
69 : How to pass
parameter with testng.xml file to use It In test case?
Answer : We can define parameter In testng.xml file using syntax like bellow.
Answer : We can define parameter In testng.xml file using syntax like bellow.
<parameter name="browser"
value="FFX" />
Here, name attribute defines parameter name and value defines value of that parameter. Then we can use that parameter In selenium webdriver test case using bellow given syntax.
@Parameters ({"browser"})
VIEW FULL EXAMPLE on how to define and use parameter from testng.xml file.
70 : I have a test case with two @Test methods. I wants to exclude one @Test method from execution. Can I do It? How?
Answer : Yes you need to specify @Test method exclusion In testng.xml file as bellow.
<!DOCTYPE suite SYSTEM
"http://testng.org/testng-1.0.dtd" >
<suite name="Test Exclusion
Suite">
<test
name="Exclusion Test" >
<classes>
<class name="Your Test Class Name">
<methods>
<exclude
name="Your Test Method Name To Exclude"/>
</methods>
</class>
</classes>
</test>
</suite>
You need to provide @Test method name In exclude tag to exclude It from execution.
You can VIEW DETAILED EXAMPLE on how to exclude specific @Test method from execution.
71 : Tell me syntax to skip @Test method from execution.
Answer : You can use bellow given syntax Inside @Test method to skip It from test execution.
throw new SkipException("Test Check_Checkbox Is
Skipped");
It will throw skip exception and @Test method will be sipped Immediately from execution. You can VIEW FULL EXAMPLE on how to skip @Test method from execution.
72 : Arrange bellow give testng.xml tags from parent to child.
<test>
<suite>
<class>
</methods>
</classes>
Answer : Parent to child arrangement for above testng tags Is as bellow.
<suite>
<test>
</classes>
<class>
</methods>
Part 16
73 : How to set priority of @Test method? What Is Its usage?
Answer : In your test
case, you can set priority for TestNG @Test annotated methods as bellow.
@Test(priority=0)
Using priority, We can control @Test method execution
manner as per our requirement. That
means @Test method with
priority = 0 will be executed 1st and @Test method with priority = 1 will be
executed 2nd and so on. VIEW PRACTICAL EXAMPLE to
know how to use It.
74 : Tell
me any 5 assertions of TestNG which we can use In selenium webdriver.
Answer : There are many
different assertions available In TestNG but generally I am using bellow given
assertions In my test cases.
1.
assertEquals VIEW EXAMPLE
2.
assertNotEquals VIEW EXAMPLE
3.
assertTrue VIEW EXAMPLE
4.
assertFalse VIEW EXAMPLE
5.
assertNull VIEW EXAMPLE
6.
assertNotNull VIEW EXAMPLE
75 : Can
you tell me usage of TestNG Soft Assertion?
Answer : Using TestNG
soft assertion, We can continue our test execution even if assertion fails.
That means on failure of soft assertion, remaining part of @Test method
will be executed and assertion failure will be reportedat the end of @Test
method. VIEW PRACTICAL EXAMPLE.
76 : How to
write regular expression In testng.xml file to search @Test methods
containing "product" keyword.
Answer : Regular
expression to find @Test methods containing keyword "product" Is
as bellow.
<methods>
<include
name=".*product.*"/>
</methods>
77 : Which
time unit we provide In time test? minutes? seconds? milliseconds?
or hours? Give Example.
Answer : Time unit we
provide on @Test method level or test suite level Is In milliseconds.You
can VIEW FULL EXAMPLE to
know how to set time out.
Part 17
78 : What
Is the syntax to get value from text box and store It In variable.
Answer : Most of the
time, String In text box will be stored as value. So we need to access value
attribute(getAttribute) of that text box as shown In bellow example.
String Result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");
VIEW PRACTICAL EXAMPLE to get text from calc result text box.
79 : What
Is the difference between findelement and findElements ?
Answer : findElement Is
useful to locate and return single element from page while findElements Is
useful to locate and return multiple elements from web page.
80 : Tell
me looks like XPath of sibling Input element which Is after Div in the DOM.
Answer : XPath for
above scenario will be something like bellow.
//div/following-sibling::input
81 : Tell
me looks like CSSSelector path of sibling Input element which Is after Div in
the DOM.
Answer : CSSSelecor
path will looks like bellow.
css=div + input
82 : What
Is Parallelism In TestNG?
Answer : In general
software term, Parallelism means executing two part of
program simultaneously or executing program simultaneously or we can
say multithreaded or parallel mode. TestNG has same feature using which we
can start multiple threads simultaneously In parallel mode and test methods
will be executed In them. VIEW PARALLELISM EXAMPLE.
Part 18
83 : What
are the benefits of parallelism over normal execution?
Answer : Using
parallelism facility of TestNG In selenium webdriver,
·
Your test execution
time will be reduced as multiple tests will be executed simultaneously.
·
Using parallelism, We
can verify multithreaded code In application.
84 : I
wants to run test cases/classes In parallel. Using which attribute and value I
can do It?
Answer : You have to
use parallel = classes attribute In testng.xml to run
tests parallel. VIEW EXAMPLE.
85 : What
Is dependency test In TestNG?
Answer : Dependency Is
very good feature of testng using which we can set test method as dependent
test method of any other single or multiple or group of test methods. That
means depends-on method will be executed first and then dependent test method
will be executed. If depends-on test method will fail then execution of
dependent test method will be skipped automatically. TestNG dependency feature
will works only If depends-on test method Is part of same class or part of
Inherited base class. DETAILED DESCRIPTION ON DEPENDENCY.
86 : What
Is the syntax to set test method dependency on multiple test methods.
Answer : We can set
test method's dependency on multiple test methods as bellow.
@Test(dependsOnMethods={"Login","checkMail"})
public
void LogOut() {
System.out.println("LogOut
Test code.");
}
Above test method Is depends on Login and checkMail test methods.VIEW EXAMPLE.
87 : What
Is the syntax to set test method disabled.
Answer : We can use
attribute enabled = false with @Test annotation to set test
method disabled. Syntax Is as bellow.
@Test(enabled = false)
public
void LogOut() {
System.out.println("LogOut Test code.");
}
Disabled test methods will be excluded automatically during execution.VIEW PRACTICAL EXAMPLE.
Part 19
88 : In
XPath, I wants to do partial match on attribute value from beginning. Tell me
two functions using which I can do It.
Answer : We can use
bellow given two functions with XPath to find element using attribute value
from beginning.
1.
contains()
2.
starts-with()
89 : I have
used findElements In my test case. It Is
returning NoSuchElementException when not element found. Correct me If I
am wrong.
Answer : It Is Incorrect. findElements will
never return NoSuchElementException. It will return just an empty list.
90 : My
Firefox browser Is not Installed at usual place. How can I tell FirefoxDriver
to use It?
Answer : If Firefox
browsers Is Installed at some different place than the usual place then you
needs to provide the actual path of Firefox.exe file as bellow.
System.setProperty("webdriver.firefox.bin","C:\\Program
Files\\Mozilla Firefox\\Firefox.exe");
driver =new FirefoxDriver();
91 : How to
create custom firefox profile and how to use It In selenium webdriver test?
Answer : You can view detailed answer for
firefox custom profile onTHIS PAGE.
92 : What
versions of Internet Explorer are supported by selenium WebDriver?
Answer : Till date,
Selenium WebDriver supports IE 6, 7, 8, 9, 10 and 11 with appropriate
combinations of Windows 7, Vista or XP.
Part 20
93 : Tell
me the class name using which we can generate Action chain.
Answer : The WebDriver
class name Using which we can generate Action chain Is "Actions". VIEW USAGE OF ACTIONS CLASS with
practical example on how to generate series of actions to drag and drop
element.
94 : Do you
know method name using which we can builds up the actions chain?
Answer : Method name of
Actions class to build up actions chain Is "build()". THIS EXAMPLE will
show you how to build drag and drop element by x,y pixel actions using build()
method.
95 : When
we can use Actions class In Selenium WebDriver test case?
Answer : Few of the
examples are bellow where can use actions class to perform operations In web
application.
·
Drag and drop element
- VIEW EXAMPLE
·
Drag and drop by x,y
pixel offset - VIEW EXAMPLE
·
Selecting JQuery
selectable Items - VIEW EXAMPLE
·
Moving JQuery
slider - VIEW EXAMPLE
·
Re-sizing JQuery
re-sizable element - VIEW EXAMPLE
·
Selecting date from
JQuery date picker - VIEW EXAMPLE
96 : Can we
capture screenshot In Selenium WebDriver? How?
Answer : We can use
selenium webdriver TakesScreenshot method to capture screenshot. Java File
class will be used to store screenshot In your system's local drive. You can
view how to capture screenshot In selenium webdriver on THIS PAGE.
97 : Selenium
WebDriver has any built In method using which we can read data from excel file?
Answer : No, Selenium
webdriver do not have any built In functionality using which we can read data
from excel file.
Part 21
98 : Do you
know any external API name using which we can read data from excel file?
Answer :
·
We can use jxl API
(Java Excel API) to read data from excel file. VIEW EXAMPLE
·
We can use one more
powerful API known as Apache POI API to read and write data In excel file.
I have created data driven framework using Apache POI API. You can VIEW DATADRIVEN FRAMEWORK
CREATION TUTORIALS step by step.
99 : Tell
me any 5 webdriver common exceptions which you faced during test case
execution.
Answer : WebDriver's
different 5 exceptions are as bellow.
1.
TimeoutException - This exception will be thrown when
command execution does not complete In given time.
2.
NoSuchElementException - WebDriver will throw this exception
when element could not be found on page.
3.
NoAlertPresentException - This exception will be generated when
webdriver ties to switch to alert popup but there Is not any alert present on
page.
4.
ElementNotSelectableException - It will be thrown when webdriver Is
trying to select unselectable element.
5.
ElementNotVisibleException - Thrown when webdriver Is not able to
Interact with element which Is available In DOM but It Is hidden.
100 : Tell
me different ways to type text In text box In selenium test.
Answer : We can type
text In text box of web page using bellow given ways In selenium test.
1.Using .SendKeys() method
1.Using .SendKeys() method
driver.findElement(By.xpath("//input[@id='fname']")).sendKeys("Using
sendKeys");
2. Using JavascriptExecutor
((JavascriptExecutor)driver).executeScript("document.getElementById('fname').value='Using
JavascriptExecutor'");
3. Using Java Robot class VIEW EXAMPLE
driver.findElement(By.xpath("//input[@id='fname']")).click();
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_N);
robot.keyPress(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_R);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_T);
101 : Tell
me different ways to verify element present or not on page.
Answer : We can check
If element Is present or not using bellow given 2 simple ways.
1. Using .size() method
1. Using .size() method
Boolean elePresent = driver.findElements(
By.id("ID of element") ).size() != 0;
If above syntax return "false" means element Is not
present on page and "true" means element Is present on page.
2. Using .isEmpty() method
2. Using .isEmpty() method
Boolean elePresent =
driver.findElements(By.id("ID of element")).isEmpty();
If this returns
"true" means element Is not present on page and "false"
means element Is present on page.
102 : Why we
need to customize Firefox browser profile In webdriver test?
Answer : Webdriver
launch fresh browser Instance when we run tests In Firefox browser using
selenium webdriver. Fresh browser Instance do not have any Installed add-ons,
saved passwords, bookmarks and any other user preferences. So we need to create
custom profile of Firefox browser to get any of this thing In Webdriver
launched browser.VIEW MORE DETAIL WITH EXAMPLE
Part 22
103 : How to customize Firefox
browser profile for webdriver test?
Answer : You can do It
In two different ways.
1.
You can create your
desired firefox browser profile before running test and then you can use It In
your selenium webdriver test. VIEW EXAMPLE.
2.
You can customize your
firefox browser profile run time before launching webdriver's Firefox browser
Instance. VIEW EXAMPLE.
104 : What
is Difference between getAttribute() and getText()?
Answer :
·
getAttribute() method
Is useful to read element's attribute value like id, name, type etc. VIEW EXAMPLE.
·
getText() method Is
useful to read text from element or alert. VIEW EXAMPLE.
105 : What is the difference between
WebDriver and Remote WebDriver?
Answer : Simple answer
for this questions Is as bellow.
·
WebDriver : Webdriver Is an Interface or we can
say tool using which we can create automated test cases for web application and
then run on different browsers like IE, Google chrome, Firefox etc.. We can
create test cases In different languages. VIEW MORE DETAIL.
·
Remote
WebDriver : Remote
WebDriver Is useful to run test cases In same machine or remote machines using
selenium Grid.
106 : I have
total 200 test cases. I wants to execute only 20 test cases out of them. Can I
do It In selenium WebDriver? How?
Answer : Yes. If you are using TestNG with
selenium webdriver then you can do Is using grouping approach as described
In THIS PAGE.
Create separate group for those 20 test cases and configure testng.xml file
accordingly to run only those 20 test cases.
Also If you are using data driven framework then you can configure It In excel file. You can configure such data driven framework at your own by following steps given on THIS PAGE.
Also If you are using data driven framework then you can configure It In excel file. You can configure such data driven framework at your own by following steps given on THIS PAGE.
107 : Can you tell me three
different ways to refresh page. Do not use .refresh() method.
Answer : We can refresh
browser In many different ways. Three of them are as bellow.
driver.get(driver.getCurrentUrl());
driver.navigate().to(driver.getCurrentUrl());
driver.findElement(By.xpath("//h1[@class='title']")).sendKeys(Keys.F5);
No comments:
Post a Comment