Interview Questionsandanswers
Interview Questionsandanswers
❖ How often does the test need to be executed? i.e. is that going to be a regression test?
Sometimes the test will need to be executed once, but with a large set of data
❖ How much time does automating this test will save me so that I can use my time in
exploratory testing
❖ How important is the test to the business; i.e. is the test scenario a typical user journey
through the application
❖ How complex is it to automate the test and how likely is it that the complexity doesn’t
cause many false positives which increases results analysis time?
❖ How likely is it that this test catches a defect?
❖ How likely is it that a feature or functionality will break and what is the impact of it to
the business? If it is high impact, then it should be automated to ensure it passes from
release to release
Pros
❖ UI automated tests execute in a way that simulates user interacting with the system. So it
is very good for validating user journeys and flows
❖ Can cover end-to-end flows that communicate with 3rd party systems
❖ Because tests are run against the system, they can be demoed to the customer who can
understand what tests are run
❖ Can catch high severity or show stopper bugs
❖ Can check UI functionality where it is not possible to test otherwise
Cons
▪ UI automated tests can be very brittle (i.e. fail due to UI changes even though functionality
hasn’t changed)
▪ Slow feedback to the team. Execution is slow as you have to wait for the system to launch
and connections with 3rd party system can take a long time
▪ Limitation on what can be checked from the UI. There are some information that are not
present from the UI
▪ Because tests are slow from UI, we can’t have a lot of tests running against the UI
▪ Can be time consuming to construct automated test scripts for the UI
▪ Usually have to depend on a 3rd party tool or vendor for UI testing
What are the differences between open source tools, vendor tools, and in-house tools?
❖ Open source tools are free to use frameworks and applications. Engineers build the tool,
and have the source code available for free on the internet for other engineers to use.
❖ Vendor tools are developed by companies that come with licenses to use, and often cost
money. Because they are developed by an outside source, technical support is often
available for use. Example vendor tools include WinRunner, SilkTest, Rational Robot,
QA Director, QTP, LR, QC, RFT, and RPT.
❖ An in-house tool is a tool that a company builds for their own use, rather than purchasing
vendor tools or using open source tools.
How do you choose which automation tool is best for your specific scenario?
In order to choose the proper automation testing tool, you must consider:
❖ 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.
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
❖ XPath Locator
❖ CSSSelector Locator
❖ ClassName Locator
❖ ID Locator
❖ Name Locator
❖ LinkText Locator
❖ PartialLinkText Locator
❖ TagName Locator
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.
● JUnit
● TestNG
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.
14. What is the difference between absolute XPath and relative XPath?
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]/d
iv/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 :
//input[@id='Resultbox']
Alternative : 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.
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/d
iv/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.
//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.
div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
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);
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.
❖ 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.
driver.get("http://www.google.com");
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.
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.
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()
driver.get()
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.
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.
driver.manage().window().setSize(new Dimension(500,500));
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.
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.
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");
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..
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.
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);
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
42 : Give me any five different xPath syntax to locate bellow given Input element.
//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')]
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.
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
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..
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
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.
❖ 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.
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.
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.
❖ 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.
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.
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.
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.
driver.switchTo().alert().dismiss();
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.
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.
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 {
}
61 : For what purpose, assertTrue and assertFalse assertions are used?
Answer : Example of JUnit assertEquals assertion Is as bellow. It assert that values of actTotal
and expTotal are equal or not.
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.
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.
● 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.
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"})
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.
You need to provide @Test method name In exclude tag to exclude It from
execution.
Answer : You can use bellow given syntax Inside @Test method to skip It from
test execution.
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.
<test>
<suite>
<class>
</methods>
</classes>
<suite>
<test>
</classes>
<class>
</methods>
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.
❖ assertEquals
❖ assertNotEquals
❖ assertTrue
❖ assertFalse
❖ assertNull
❖ assertNotNull
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.
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”)
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.
81 : Tell me looks like CSSSelector path of sibling Input element which Is after Div in the
DOM.
84 : I wants to run test cases/classes In parallel. Using which attribute and value I can do
It?
86 : What Is the syntax to set test method dependency on multiple test methods.
@Test(dependsOnMethods={"Login","checkMail"})
public void LogOut() {
System.out.println("LogOut Test code.");
}
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.");
}
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()
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();
92 : 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.
93 : Do you know method name using which we can builds up the actions chain?
94 : 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
❖ Drag and drop by x,y pixel offset
❖ Selecting JQuery selectable Items
❖ Moving JQuery slider
❖ Re-sizing JQuery re-sizable element
❖ Selecting date from JQuery date picker
96 : 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.
97 : 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.
6. StaleElementReferenceException
98 : 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.
2. Using JavascriptExecutor
((JavascriptExecutor)driver).executeScript("document.getElementById('fname').va
lue='Using JavascriptExecutor'");
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);
Answer : We can check If element Is present or not using bellow given 2 simple ways.
1. Using .size() method
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.
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.
104 : 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.
105: 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);
106 : I wants to set size and position of my browser window. Do you know how to do it in
selenium webdriver?
Answer : We can use setSize function to set size of window and setPosition
function to set position of browser window.
107 : Is there any way to get size and position of browser window in selenium webdriver?
Answer : Yes.. We can get it using webdriver functions getSize and getPosition.
108 : I wants to scroll my page by 300 pixel. Tell me how can i do it?
Answer : We can use javascript executor with window.scrollBy(x,y) to scroll
page in x or y directions.
110 : How can we get the font size, font color, font type used for a particular text on a web
page using Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);
111. How to prepare Customized html Report using TestNG in hybrid framework.
Below are the 3 ways:
• Junit: with the help of ANT.
• TestNG: using inbuilt default.html to get the HTML report. Also XST reports from ANT,
Selenium, TestNG combination.
• Using our own customized reports using XSL jar for converting XML content to HTML.
112 : How to handle Ajax popup window?
By using getWindowHandles() and obj.switchTo.window(windowid) we can handle popups
using explicit wait and driver.swtchT0.window("name") commands for your
requirements.
116: “Suppose developer changed the existing image to new image with same xpath. Is test case
pass or fail?"
Answer : Pass
118: In frame if no frame Id as well as no frame name then which attribute
I should consider throughout our script.
You can go like this.....driver.findElements(By.xpath("//iframe"))...
Then it will return List of frames then switch to each and every frame and search for the locator
which you want then break the loop
122: What is the difference between single and double slash in Xpath?
/
1.It starts selection from the document node
2. It Allows you to create 'absolute' path expressions
3. e.g “/html/body/p” matches all the paragraph elements
//
1. It starts selection matching anywhere in the document
2. It Allows you to create 'relative' path expressions
3. e.g“//p” matches all the paragraph elements
What is WebDriverBackedSelenium ?
Ans- WebDriverBackedSelenium is a kind of class name where we can create an object for it as
below:
1 Selenium wbdriver= new WebDriverBackedSelenium(WebDriver object name, "URL path of website")
The main use of this is when we want to write code using both WebDriver and Selenium RC , we
must use above created object to use selenium commands.
How to check if an element is visible on the web page ?
Ans- use isDisplayed() method. The return type of the method is boolean. So if it return true then
element is visible else not visible.
driver.findElement(By.xpath("xpath of elemnt")).isDisplayed();
webelement.sendKeys(press);
num = num*i;
System.out.println(num);
}catch(Exception e){
Syste.out.println(“name is invalid”);
In eclipse, I created java projects and added JUnit or TestNG classes. In the project reference, I added JUnit or
TestNG jar file. In the test class, I used webdriver in setup, test and teardown methods. Sometimes, I used webdriver
in beforeclass, beforemethod, aftermethod, afterclass sections.
Depending on the programming language, reference files should be added to the test solutions in C# or test projects
in Java. For example, in C#, I added webdriver dlls and in Java, I added Selenium-client-driver.jar file. And also, we
should have programming IDE like visual studio or eclipse to run webdriver.
Selenium WebDriver is very flexible to use with Java, .Net, Python, Ruby or html languages. QA engineers who have
good coding skills can use it very effectively.
Since selenium web driver requires coding skills, QA engineers should have some knowledge of program
development in Java, .Net, or other languages.
WebDriver backed Selenium is API that enables running Selenium 1.0 tests in web driver.
if a Selenium function requires a pattern argument, what five prefixes might that argument have?
* which translates to “match anything,” i.e., nothing, a single character, or many characters.
[ ] (character class) which translates to “match any single character found inside the square brackets.” A dash
(hyphen) can be used as a shorthand to specify a range of characters (which are contiguous in the ASCII character
set). A few examples will make the functionality of a character class clear:
[aeiou] matches any lowercase vowel
What is the regular expression sequence that loosely translates to "anything or nothing?"
* which translates to “match anything,” i.e., nothing, a single character, or many characters.
glob: label
32. What does a character class for all alphabetic characters and digits look like in regular expressions?
33. What does a character class for all alphabetic characters and digits look like in globbing?
regexp: *[a-zA-Z0-9]
What is the difference between thread.Sleep() and selenium. Set Speed ("2000")?
If the application is taking time to load the page then we use selenium.waitforpageload(" ").
This command is doesn’t wait upto the given time whenever the page load is completed.
If the application is taking time to refresh the page, then we use Thread. Sleep ( ).it is a
standard wait it simply wait to the given time.
selenium.setSpeed
1. Takes a single argument in string format
Ex: selenium.setSpeed("2000") - will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in
set Speed.
thread.sleep
1. Takes a single argument in integer format
ex: thread. Sleep(2000) - will wait for 2 seconds
3. Waits for only once at the command given at sleep.
● Select “Toggle break point” by right click on the command in Selenium IDE
● Press “B” on the keyboard and select the command in Selenium IDE
● Multiple break points can be set in Selenium IDE
Selenese is a selenium set of command which are used for running the test
6) In selenium IDE what are the element locators that can be used to locate elements on
web page?
● X-path locators
● Css locators
● Html id
● Html name
7) In Selenium IDE how you can generate random numbers and dates for test data ?
In Selenium IDE you can generate random numbers by using Java Script
type
css=input#s
javascript{Math.random()}
type
css=input#s
javascript{new Date()}
8) How you can convert any Selenium IDE tests from Selenese to another language?
You can use the format option of Selenium IDE to convert tests into another programming
language
9) Using Selenium IDE is it possible to get data from a particular html table cell ?
storeTable
Css=#table 0.2
textFromCell
● Select “Execute this command” by right clicking on the command in Selenium IDE
● Press “X” key on the keyboard after selecting the command in Selenium IDE
13) In which format does source view shows your script in Selenium IDE ?
14) Explain how you can insert a start point in Selenium IDE?
● Press “S” key on the keyboard and select the command in Selenium IDE
● In Seleniun IDE right click on the command and the select “Set / Clear Start Point”
● 15) What if you have written your own element locator and how would you test it?
● To test the locator one can use “Find Button” of Selenium IDE, as you click on it, you
would see on screen an element being highlighted provided your element locator is
right or or else an error message will be displayed.
● 16) What is regular expressions? How you can use regular expressions in
Selenium ?
● A regular expression is a special text string used for describing a search pattern. In
Selenium IDE regular expression can be used with the keyword- regexp: as a prefix
to the value and patterns needs to be included for the expected values.
● 17) What are core extension ?
● If you want to “extend” the defualt functionality provided by Selenium Function
Library , you can create a Core Extension. They are also called “User Extension”. You
can even download ready-made Core Extension created by other Selenium
enthusiats.
● 18) How will you handle working with multiple windows in Selenium ?
● We can use the command selectWindow t o switch between windows. This command
uses the title of Windows to identify which window to switch to.
● 19) How will you verify the specific position of an web element
● You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel
comparison of the position of the element from the Left and Top of page respectively
● 20) How can you retrive the message in an alert box ?
● You can use the storeAlert command which will fetch the message of the alert pop up
and store it in a variable.
a) Functional
b) Regression
For post release validation with continuous integration automation tool could be used
a) Jenkins
b) Hudson
c) Quick Build
d) CruiseCont
5) Explain what is assertion in Selenium and what are the types of assertion?
Assertion is used as a verification point. It verifies that the state of the application conforms
to what is expected. The types of assertion are “assert” , “verify” and “waifFor”.
Thread.sleep () : It will stop the current (java) thread for the specified period of time. Its done
only once
SetSpeed () : For specific amount of time it will stop the execution for every selenium
command.
6) What are the selenium locators and what is the tool you use to identify element ?
A) Selenium locators are the way of finding HTML element on the page to perform Selenium
actions... We usefirebug(for firefox) to identify elements as it is more popular and powerful web
development tool.. It inspects HTML and modify style and layout in real-time.. We can edit,
debug and monitor CSS, HTML and Javascript live in any web page.. ((click here to download
firebug))
-->For Internet Explorer we can choose debugbar.. It views HTML DOM tree, we can view and
edit tab attributes..
((click here to download debugbar))
8) What is selenese ?
A) Selenium set of commands that run our test is called Selenese.. A sequence of these
commands is a test script.. There are three types of selenese..
1. Actions : They perform some operations like clicking a link or typing text in text
box or selecting an option from drop-down box etc..
2. Assertions : They verify that the state of application conforms to what is
expected.. Ex: 'verify that this checkbox is checked', 'make sure that the page title is X'..
3. Accessors : Checks the state of application and store the results in a variable.. Ex:
storeText, storeTitle, etc..
1. Right click on the command in Selenium IDE and select “Set / Clear Start Point”
2. Select the command in Selenium IDE and press “S” key on the keyboard
3. You can have only one start point
4. If you have already set one start point and you selected other command as start point. Then the
first start point will be removed and the new start point will be set
1. Right click on the command in Selenium IDE and select “Inert New Comment”
2. If you want to comment an existing line. You need to follow the below mentioned steps.
a. Select the source tab in IDE
b. Select the line which you want to comment
c. Assume that if you want to comment a open command you need to write like below mentioned code
<tr>
<!–
<td>open&l/td>
<td>/node/304/edit&l/td>
<td></td>
–>
</tr>
1. Right click on the command in Selenium IDE and select “Toggle Break Point”
2. Select the command in Selenium IDE and press “B” key on the keyboard
3. If you want to clear the break point once again Spress “B” key on the keyboard
4. You can set multiple break points in Selenium IDE
12. How to export the tests from Selenium IDE to Selenium RC in different languages?
From selenium IDE the test cases can be exported into the languages
1. .Net
2. Java
3. Perl
4. Python
5. PHP
6. Ruby
The below mentioned steps can explain how to export the test cases
1. Open the test case from Selenium IDE
2. Select File -> Export Test Case As
Which is the command used for displaying the values of a variable into the output console
or log?
The command used for displaying the values of a variable into the output console or log – echo
If you want to display a constant string. The below mentioned command can be used
echo <constant string>
ex: echo “The sample message”
If you want to display the value of a variable it can be written like below
echo ${<variable name>>
ex: echo ${var1}
1. *firefox
2. *mock
3. *firefoxproxy
4. *pifirefox
5. *chrome
6. *iexploreproxy
7. *iexplore
8. *firefox3
9. *safariproxy
10. *googlechrome
11. *konqueror
12. *firefox2
13. *safari
14. *piiexplore
15. *firefoxchrome
16. *opera
17. *iehta
18. *custom
Command: verifyText
Target: //font/font/b/font[1]
Value: regexp:Flight Confirmation # [0-9]{4}-[0-9]{2}-[0-9]{5,10}
PATTER MATCH
N
. any single character
[] character class: any single character that appears inside the brackets
* quantifier: 0 or more of the preceding character (or group)
+ quantifier: 1 or more of the preceding character (or group)
? quantifier: 0 or 1 of the preceding character (or group)
{1,5} quantifier: 1 through 5 of the preceding character (or group)
| alternation: the character/group on the left or the character/group on the
right
() grouping: often used with alternation and/or quantifier
1) Capture the bitmap for the entire page – it captures the browser main page area of AUT
2) Capture the bitmap for the screen shots – it captures the entire screen shot like the print scree that
you give from your keyboard
Selenium doesn’t support bitmap capturing for an element on AUT.
JVM
JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the
runtime environment in which java bytecode can be executed. It is a specification.
JVMs are available for many hardware and software platforms (so JVM is platform dependent).
JRE
JDK
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE +
development tools.
2. Heap
3. Stack
4) What is platform?
A platform is basically the hardware or software environment in which a program runs. There are
two types of platforms software-based and hardware-based. Java provides software-based
platform.
5) What is the main difference between Java platform and other platforms?
The Java platform differs from most other platforms in the sense that it's a software-based
platform that runs on top of other hardware-based platforms.It has two components:
1. Runtime Environment
6) What gives Java its 'write once and run anywhere' nature?
The bytecode. Java is compiled to be a byte code which is the intermediate language between
source code and machine code. This byte code is not platform specific and hence can be fed to
any platform.
7) What is classloader?
The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many
types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader,
Plugin classloader etc.
8) Is Empty .java file name a valid source file name?
Yes, save your java file by .java only, compile it by javac .java and run by java
yourclassname Let's take a simple example:
1. /save by .java only
2. class A{
3. public static void main(String args[]){
4. System.out.println("Hello java");
5. }
6. }
7. //compile by javac .java
8. //run by java A
9. run it by java A
9) Is delete,next,main,exit or null keyword in java?
No.
0) If I don't provide any arguments on the command line, then the String array of Main method
will be empty or null?
It is empty. But not null.
11) What if I write static public void instead of public static void?
Program compiles and runs properly.
13) What is difference between object oriented programming language and object based
programming language?
Object based programming languages follow all the features of OOPs except Inheritance.
Examples of object based programming languages are JavaScript, VBScript etc.
14) What will be the initial value of an object reference which is defined as an instance variable?
The object references are all initialized to null in Java.
15) What is constructor?
● Constructor is just like a method that is used to initialize the state of an object. It is
invoked at the time of object creation
● static variable gets memory only once in class area at the time of class loading.
● A static method can be invoked without the need for creating an instance of a class.
● static method can access static data member and can change the value of it.
because object is not required to call static method if It were non-static method,jvm creats object
first then call main() method that will lead to the problem of extra memory allocation.
23) What is static block?
● Is used to initialize the static data member.
1)A method i.e. declared as static is known as static method. A method i.e. not declared
as instance method.
3)Non-static (instance) members cannot be accessed in static context (static static and non-static variab
method, static block and static nested class) directly. accessed in instance metho
4)For example: public static int cube(int n){ return n*n*n;} For example: public void m
1) Method overloading increases the Method overriding provides the specific implementation of
readability of the program. already provided by its super class.
2) method overlaoding is occurs within the Method overriding occurs in two classes that have IS-A rela
class.
3) In this case, parameter must be different. In this case, parameter must be same.
1)An abstract class can have method body (non-abstract methods). Interface have only abstract m
2)An abstract class can have instance variables. An interface cannot have insta
3)An abstract class can have constructor. Interface cannot have construc
4)An abstract class can have static methods. Interface cannot have static me
5)You can extends one abstract class. You can implement multiple in
67) Can we define private and protected modifiers for variables in interfaces?
No, they are implicitly public.
68) When can an object reference be cast to an interface reference?
An object reference can be cast to an interface reference when the object implements the
referenced interface.
69) What is package?
A package is a group of similar type of classes interfaces and sub-packages. It provides access
protection and removes naming collision.
70) Do I need to import java.lang package any time? Why ?
No. It is by default loaded internally by the JVM.
71) Can I import same package/class twice? Will the JVM load the package twice at runtime?
One can import the same package or same class multiple times. Neither compiler nor JVM
complains about it.But the JVM will internally load the class only once no matter how many
times you import the same class.
72) What is static import ?
By static import, we can access the static members of a class directly, there is no to qualify it
with the class name.
73) What is Exception Handling?
Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle checked
exceptions.
74) What is difference between Checked Exception and Unchecked Exception?
1)Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known as
checked exceptions e.g.IOException,SQLException etc. Checked exceptions are checked at
compile-time.
2)Unchecked Exception
The classes that extend RuntimeException are known as unchecked exceptions e.g.
ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at
compile-time.
75) What is the base class for Error and Exception?
Throwable.
76) Is it necessary that each try block must be followed by a catch block?
It is not necessary that each try block must be followed by a catch block. It should be followed
by either a catch block OR a finally block. And whatever exceptions are likely to be thrown
should be declared in the throws clause of the method.
77) What is finally block?
● finally block is a block that is always executed.more details...
2)checked exceptions can not be propagated checked exception can be propagated with throws.
with throw only.
4)throw is used within the method. throws is used with the method signature.
5)You cannot throw multiple exception You can declare multiple exception e.g. public void metho
IOException,SQLException.
82) Can subclass overriding method declare an exception if parent class method doesn't throw an
exception ?
Yes but only unchecked exception not checked.
83) What is exception propagation ?
Forwarding the exception object to the invoking method is known as exception propagation.
There is given a list of string handling interview questions with short and pointed answers. If you
know any string handling interview question, kindly post it in the comment section.
84) What is the meaning of immutable in terms of String?
The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been
created, its value can't be changed.
85) Why string objects are immutable in java?
Because java uses the concept of string literal. Suppose there are 5 reference variables,all referes
to one object "sachin".If one reference variable changes the value of the object, it will be affected
to all the reference variables. That is why string objects are immutable in java.
finally: finally block is used in exception handling. finally block is always executed.
125)What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class
hierarchy is byte-oriented.
126)What an I/O filter?
An I/O filter is an object that reads from one stream and writes to another, usually altering the
data in some way as it is passed from one stream to another.
127) What is serialization?
Serialization is a process of writing the state of an object into a byte stream.It is mainly used to
travel object's state on the network.
128) What is Deserialization?
Deserialization is the process of reconstructing the object from the serialized state.It is the
reverse operation of serialization.
129) What is transient keyword?
If you define any data member as transient,it will not be serialized.
130)What is Externalizable?
Externalizable interface is used to write the state of an object into a byte stream in compressed
format.It is not a marker interface.
131)What is the difference between Serializalble and Externalizable interface?
Serializable is a marker interface but Externalizable is not a marker interface.When you use
Serializable interface, your class is serialized automatically by default. But you can override
writeObject() and readObject() two methods to control more complex object serailization
process. When you use Externalizable interface, you have a complete control over your class's
serialization process.
134) Can you access the private method from outside the class?
Yes, by changing the runtime behaviour of a class if the class is not secured.
148)What are wrapper classes?
Wrapper classes are classes that allow primitive types to be accessed as objects.
149)What is a native method?
A native method is a method that is implemented in a language other than Java.
150)What is the purpose of the System class?
The purpose of the System class is to provide access to system resources.
151)What comes to mind when someone mentions a shallow copy in Java?
Object cloning.
152)What is singleton class?
Singleton class means that any given time only one instance of the class is present, in one
153)Which containers use a border layout as their default layout?
The Window, Frame and Dialog classes use a border layout as their default layout.
154)Which containers use a FlowLayout as their default layout?
The Panel and Applet classes use the FlowLayout as their default layout.
155)What are peerless components?
The peerless components are called light weight components.
156)is the difference between a Scrollbar and a ScrollPane?
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane
handles its own events and performs its own scrolling.
157)What is a lightweight component?
Lightweight components are the one which doesn?t go with the native call to obtain the graphical
units. They share their parent component graphical units to render them. For example, Swing
components.
158)What is a heavyweight component?
For every paint call, there will be a native call to get the graphical units.For Example, AWT.
159)What is an applet?
An applet is a small java program that runs inside the browser and generates dynamic contents.
160)Can you write a Java class that could be used both as an applet as well as an application?
Yes. Add a main() method to the applet.
161)What is Locale?
A Locale object represents a specific geographical, political, or cultural region.
162)How will you load a specific locale?
By ResourceBundle.getBundle(?) method.
163)What is a JavaBean?
are reusable software components written in the Java programming language, designed to be
manipulated visually by a software development environment, like JBuilder or VisualAge for
Java.
1) What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main advantage is:
● Threads share the same address space.
● Thread is lightweight.
2) What is thread?
A thread is a lightweight subprocess.It is a separate path of execution.It is called separate path of
execution because each thread runs in a separate stack frame.
3)What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead
states or a higher priority task comes into existence. Under time slicing, a task executes for a
predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines
which task should execute next, based on priority and other factors.
4) What does join() method?
The join() method waits for a thread to die. In other words, it causes the currently running
threads to stop executing until the thread it joins with completes its task.
5) What is difference between wait() and sleep() method?
wait() sleep()
1) The wait() method is defined in Object class. The sleep() method is defined in Thread c
2) wait() method releases the lock. The sleep() method doesn't releases the lo
14)Can Java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is
inaccessible to any thread other than the one that explicitly claimed it.
15) What is static synchronization?
If you make any static method as synchronized, the lock will be on the class not on object.
3) ArrayList increases its size by 50% of the array size. Vector increases its size by doubling t
2 ArrayList is not efficient for manipulation because a lot of shifting is LinkedList is efficien
) required. manipulation.
3 ArrayList is better to store and fetch data. LinkedList is better t
)
1 Iterator traverses the elements in forward ListIterator traverses the elements in backward a
) direction only. directions both.
2 Iterator can be used in List, Set and Queue. ListIterator can be used in List only.
)
1) Iterator can traverse legacy and non-legacy elements. Enumeration can traverse only legac
2) HashMap can contain one null key and Hashtable cannot contain any
multiple null values.
null key or null value.
1) Comparable provides only one sort of sequence. Comparator provides multiple sort of sequences
2) It provides one method named compareTo(). It provides one method named compare().
1) What is JDBC?
JDBC is a Java API that is used to connect and execute query to the database. JDBC API uses
jdbc drivers to connects to the database.
● Creating connection
● Creating statement
● Executing queries
● Closing connection
● Statement
● PreparedStatement
● ResultSet
● ResultSetMetaData
● DatabaseMetaData
● CallableStatement etc.
Classes:
● DriverManager
● Blob
● Clob
● Types
● SQLException etc.
2. PreparedStatement
3. CallableStatement