Selenium Intrew quest
Selenium Intrew quest
Automation testing is a process in which software tools execute pre-scripted tests on a software
application before it is released into production. Special software is used to control the test execution,
actual outcomes and predicted outcomes comparison, the test preconditions setting up, and other test
control and test reporting functions.
Regression testing coverage, test engineer productivity, consistency in testing, test cases reusability,
reduced software maintenance cost, increased test effectiveness, reduction of the test interval, reducing
human-generated errors.
Selenium is a robust test automation suite designed in a way to support and encourage automation
testing of functional aspects of web-based applications and a wide range of browsers and platforms.
Selenium is a free and open source. You don’t need to spend any licensing cost to use it.
Multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) support
Compatibility with the main platform (Windows, Mac OS, Linux etc.)
Selenium IDE (Integrated Development Environment). It is a tool for recording and playing
back. It is a Firefox plugin.
WebDriver and RC. It provides the APIs for a variety of languages like Java, .NET, PHP, etc. They
work with most of the browsers.
Grid: you can distribute tests on multiple machines so that test can be run parallel which helps
cutting down the time required for running test suites in the browser.
6) How many types of Webdriver APIs are available in Selenium?
The list of driver classes could be used for the browser automation.
AndroidDriver,
ChromeDriver,
EventFiringWebDriver,
FirefoxDriver,
HtmlUnitDriver,
InternetExplorerDriver,
iPhoneDriver,
iPhoneSimulatorDriver,
RemoteWebDriver
Selenium supports only web based applications testing. So, here are the limitations of it:
User should use third-party tools like TestNG or jUnit to write test scripts and generate reports
Selenium IDE is a plug-in used to record and replay tests in Firefox browser. Scripts may be automatically
recorded and edited manually providing auto-completion support and the ability to move commands
around quickly.
9) What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
1. Functional Testing
2. Regression Testing
3. Sanity Testing
4. Smoke Testing
5. Responsive Testing
8. Integration Testing
The different types of locators in Selenium are ID, ClassName, Name, TagName, LinkText,
PartialLinkText, XPath, CSS Selector, DOM.
12) What automation tools could be used for post-release validation with continuous integration?
Automation tools could be used for post-release validation with continuous integration: CruiseCont,
Hudson, Jenkins, Quick Build.
13) Explain the meaning of assertion in Selenium and what are the types of assertion?
Assertion is used as a verification point. It verifies that the application state conforms to the
expectation. The types of assertion are “assert”, “verify” and “waifFor”.
Both of them check if the given condition is true or false. Unlike to “assert”, “verify” will not stop the
test case execution if the test case fail.
XPath is a language that describes a way to locate and process items in Extensible Markup Language
(XML) documents by using an addressing syntax based on a path through the document’s logical
structure or hierarchy.
Absolute XPath is the direct way to find the element. It has a disadvantage. XPath gets failed if there are
any changes made in the path of the element. html/body/div[3]/div/div[1]/div/div/div[1]/div/input –
Absolute XPath example.
18) What is the difference between single slash (/) and a double slash ( //) in XPath?
A single slash (/) is used for creating XPaths with absolute paths beginning from the root node.
Double slash (//) is used for creating relative XPath to start selection from anywhere within the root
node
19) How could the web element attributes be inspected in order to use them in different locators?
Firebug is a Firefox plugin that provides various development tools for debugging applications. From an
automation perspective, Firebug is used specifically for inspecting web-elements in order to use their
attributes like id, class, name etc. in different locators.
Java, C#, Python, and Ruby, are all supported directly by the development team. There are also PHP and
Perl WebDriver implementations.
copy
22) What the WebDriver supported Mobile Testing Drivers do you know?
23) Explain the fundamental difference between XPath and CSS selector.
Using CSS selector we can only move downwards in the document, using XPaths we traverse up in the
document.
There are different methods, which help user to check the visibility of the web elements: isDisplayed(),
isEnabled(), isSelected(). These web elements can be buttons, drop boxes, checkboxes, radio buttons,
labels etc.
User can retrieve the text of the specified web element by using get command. It doesn’t require any
parameter but returns a string value.
copy
is an example of it.
A text written in a text field could be deleted by using the clear() method.
The same click() method could be used for checking checkbox as well as for clicking buttons or radio
buttons.
copy
submit() method could be used as the alternate way to click on login button, but only if attribute
type=submit.
copy
1. selectByVisibleText:
3. selectByVisibleText.selectByVisibleText(“some_visible_text”);
32) Explain the difference between close and quit command.
If you need to close the current browser having focus driver.close() is used. If you need to close all the
browser instances driver.quit() is used.
Both of these methods delay the speed of execution. The main difference between them
is setSpeed sets a speed while will apply delay time before every Selenium operation takes place.
thread.sleep() will set up wait only for once.
For Example:
sleep(5000)– It will wait for 5 seconds. It is executed only once, where the command is written.
setSpeed(“5000”)– It also will wait for 5 seconds. It runs each command after setSpeed delay by
the number of milliseconds mentioned in set Speed.
navigate().back() command takes user back to the previous webpage in the web browser’s
history. An example: driver.navigate().back();
navigate().forward() lets the user to navigate to the next web page with reference to the
browser’s history. An example: driver.navigate().forward();
According to navigate().refresh() command user can refresh the current web page there by
reloading all the web elements. An example: driver.navigate().refresh();
User can launch a new web browser window and navigate to the specified URL by
executing navigate().to()An example:
copy
1. driver.navigate().to(“https:// thinkmobiles.com/”);
Both of them let user to find elements in the current web page matching to the specified locator value.
But if you use findElement(), only the first matching element would be fetched. An example:
copy
If you use findElements(), the all matching elements would be fetched and stored in the WebElements
list. An example:
copy
Windows pop-ups cannot be handled by using Selenium. Because it supports only web application
testing.
string getText() method returns the text displayed on the alert box
void accept() method clicks on the “Ok” button as soon as the pop-up window appears
void dismiss() method clicks on the “Cancel” button as soon as the pop-up window appears
void sendKeys(String stringToSend) method enters the specified string pattern into the alert
box
navigate().refresh()
getCurrentUrl()
navigate().to(driver.getCurrentUrl())
sendKeys(Keys.F5)
copy
40) How can we find the value of different attributes like name, class, value of an element?
copy
copy
2. act.moveToElement(webElement).perform();
3. act.contextClick().perform();
copy
3. moveToElement(TargetElement)
4. release(TargetElement)
5. build();
6. dragAndDrop.perform();
The return method type is logical. If it returns true then element is visible otherwise it is
not. isDisplayed() method could be used for it:
copy
1. driver.findElement(By.id(“id_of_element”)).isDisplayed();
copy
1. driver.findElement(By.id(“id_of_element”)).isEnabled();
46) What kind of mouse actions can be performed in Selenium?
click(WebElement element)
contextClick(WebElement element)
doubleClick(WebElement element)
mouseUp(WebElement element)
mouseDown(WebElement element)
mouseMove(WebElement element)
47) Can you write the code to double click an element in Selenium?
copy
2. WebElement element=driver.findElement(By.id(“elementId”));
3. action.doubleClick(element).perform();
copy
2. WebElement element=driver.findElement(By.id(“elementId”));
3. action.moveToElement(element).perform();
.pressKey(“non-text keys”) is used for keys like control, function keys etc that are non-text
.releaseKey(“non-text keys”) is used in conjunction with key press event to simulate releasing a
key from keyboard event
.sendKeys(“sequence of characters”) is used for passing character sequence to an input or
textbox element.
JUnit is an open source Java applications testing framework, introduced by Apache. A process of adding
a special form of syntactic metadata to Java source code is called annotation. JUnit Annotations are:
variables, parameters, packages, methods and classes.
TestNG is a testing framework inspired from JUnit and NUnit in a way to use the merits by both the
developers and testers. Here are some new functionalities that make it more powerful and easier to
use, such as:
Test
BeforeSuite
AfterSuite
BeforeTest
AfterTest
BeforeClass
AfterClass
BeforeMethod
AfterMethod
TestNG “Priority” is used to schedule the test cases. In order to achieve, we need to add an annotation
as @Test(priority=??). The default value will be zero for priority. If you don’t mention the priority, it will
take all the test cases as “priority=0” and execute.
The example below shows the usage of the priority for test cases.
As we have not defined the priority for test case “Registration”, it will get executed first and then the
other test cases based on priority.
copy
1. import org.testng.annotations.Test;
3. @Test
5. {
6. System.out.println(“Create an account”);
7. }
8. @Test(priority=2)
10. {
12. }
13. @Test(priority=1)
15. {
17. }
18. }
copy
1. import org.testng.annotations.Test;
3. @Test
5. System.out.println(“Create an account”);
6. }
7. @Test(priority=2)
10. }
11. @Test(priority=1)
14. }
15. }
54) Explain how you can find broken images in a page using Selenium Web driver?
You have to follow the next steps to find broken images in a page using Selenium Web driver:
get XPath and get the all links on the page using the tag name
55) Can captcha and bar code reader be automated by using Selenium?
The tooltip text in Selenium could be verified by fetching the value of ‘title’ attribute. An example:
copy
The examples:
copy
As all links are of anchor tag ‘a’, so we can find all of them on a web page by locating elements of
tagName ‘a’:
copy
copy
To handle colors could be handled in Selenium WebDriver by using Use getCssValue(arg0) function to
get the colors by sending ‘color’ string as an argument.
NoAlertPresentException,
NoSuchElementException
NoSuchWindowException
TimeoutException
WebDriverException
File uploading action could be performed by using element.sendKeys("path of file") on the webElement
of input tag and type file: < name="fileUpload" type="file" />
Robot API is used to control keyboard or mouse to interact with OS windows like Download pop-up,
Alerts, Print Pop-ups, etc. or native Operation System applications like Notepad, Skype, Calculator, etc.
Some commonly and popularly used methods of Robot Class during web automation:
Example:
copy
1. keyPress(KeyEvent.VK_DOWN)
Example:
copy
1. robot.keyRelease(KeyEvent.VK_DOWN)
Example:
copy
1. mouseRelease(InputEvent.BUTTON3_DOWN_MASK)
mouseMove() method will move mouse pointer to the specified X and Y coordinates.
Example:
copy
1. robot.mouseMove(point.getX(), point.getY())
mousePress() method will press the right click of your mouse.
Example :
copy
1. robot.mousePress(InputEvent.BUTTON3_DOWN_MASK)
A simple example:
copy
3. ((JavascriptExecutor)driver).executeScript(“{JavaScript Code}”);
4. }
You can get the width of the textbox by using the following command:
copy
The fastest WebDriver is HtmlUnitDriver. Differing of other drivers (FireFoxDriver, ChromeDriver etc),
it’s non-GUI, while running no browser gets launched.
It is used to deselect all the options which have been selected from the drop-down list.
https://username:password@url
https://creds:[email protected]
getOptions() is used to get the selected option from the drop-down list.
You can get the browser address using these commands. But if you use getWindowHandle(), you’ll get
the address of the current browser where the control is and return type is a string. So, if you use
getWindowHandles(), you will get the address of all the open browser and its return type is an iterator.
74) Explain how you can use recovery scenario with Selenium?
You can use recovery scenario in accordance with the programming language.
use click() or submit() methods are used for ENTER. But, don’t forget that submit() method is used only
if type=’submit’.
Here are a few methods of Alerts handling which are widely used in Selenium Webdriver.
copy
1. driver.switchTo().alert().dismiss();
copy
1. driver.switchTo().alert().accept();
copy
1. driver.switchTo().alert().getText();
copy
1. driver.switchTo().alert().sendKeys(“Text”);
The Data Driven test design framework follows a design paradigm where test logic is fixed but varies the
test data. The data itself can be in different repositories like a simple .csv file, .json file or .xls sheet, or
database and can add the tests merely updating those external files or DB (instead of placing in test
code itself).
The keyword driven framework is a methodology where actions or steps are treated as keywords. These
keywords (like click, move, type etc.,) are stored in some external repositories along just like data
(in .csv/.json/.xls/DB).
The combination of data driven and keyword driven framework is called the hybrid. Here the
operations/instructions/keywords in a separate repository (.csv/.xls/.json/DB) and data is in separate
(.csv/.xls/.json/db from data provider) and the tests/driver would read both and perform the actual
tests automatically. In this design, we get the best of both methodologies, and it is kind of practical in
most of the automation cases.
Selenium Grid has following advantages: multi-browser testing, parallel test case execution, multi-
platform testing.
Selenium Grid hub is a central point or a server that controls the test executions on the different
machines.
Selenium Grid node is a hub attached machine, which has instances running the test scripts. Unlike a
hub, there can be more than one nodes in Selenium Grid.
83) Could you explain the line of code Webdriver driver = new FirefoxDriver();.
‘WebDriver’ is an interface and we are creating an object of type WebDriver instantiating an object of
FirefoxDriver class.
84) What is the purpose of creating a reference variable- ‘driver’ of type WebDriver instead of directly
creating a FireFoxDriver object or any other driver’s reference in the statement Webdriver driver =
new FirefoxDriver();?
We can use the same variable to work with multiple browsers like ChromeDriver, IEDriver by creating a
reference variable of type WebDriver.
85) How can you create HTML test report from your test script?
using XSL jar for converting XML content to HTML in own customized reports
SeleniumWebDriver element waiting to access did not appear on the web page and the
operation timed out
SeleniumWebDriver cannot locate the element, because the locator has been changed
87) Explain how can you debug the tests in Selenium IDE?
insert a break point from the location from where you want to execute test step by step
to continue executing all the commands at a time click on the “Run” button
testng.xml file is used to configure the whole a test suite. Here we can create a test suite, create test
groups, mark tests for parallel execution, add listeners and pass parameters to test scripts. It can be
used for the further test suite triggering.
90) In which format does source view show the script in Selenium IDE?
AJAX allows the Web page to retrieve small amounts of data from the server without reloading the
entire page.
The different wait methods should be applied for testing Ajax application:
ThreadSleep
Implicit Wait
Explicit Wait
WebdriverWait
Fluent Wait
92) What is the FirefoxDriver, class or an interface? And which interface does it implement?
FirefoxDriver is a Java class. It implements all the methods available in the interface.
93) How can we make one test method dependent on other using TestNG?
We can make one test method run only after successful execution of dependent test method by using
dependsOnMethods parameter inside @Test annotation in TestNG: @Test(dependsOnMethods =
{ “preTests” })
94) How could you explain the main difference between WebDriver and RC?
Selenium WebDriver drives the browser using built-in support. RC injects JavaScript function into
browsers when the page is loaded.
IntelliJ is an IDE that helps users to write code for Selenium better and faster. It could be used as an
option to Java bean and Eclipse.
96) What are the advantages of Using Git Hub For Selenium?
Members of multiple people team working on the same project can update its details and
inform other team members simultaneously
You can build the project from the remote repository regularly by using Jenkins. This helps you
to keep track of failed builds.
97) Can we use Selenium RC for tests driving on two different browsers on one operating system
without Selenium Grid?
We can do it if JAVA testing framework is not used. If we use Java client driver of Selenium, instead of
using Java testing framework, TestNG allows us not to use Selenium Grid.
You should just to add these two key value pairs in the suite to run the tests in parallel:
copy
1. parallel="{methods/tests/classes}"
“Find Button” of Selenium IDE is used to test the locator. Clicking on this button, you will see on screen
if your element locator is right or wrong.
AutoIT is used to handle window GUI and non-HTML popups in the application.
JDBC (Java Database Connectivity) API is required for Database Testing in Selenium WebDriver.
Here are some points that favor Python over Java to use with Selenium:
Java uses traditional braces to start and ends blocks, whilePython uses indentation
105) How can you run Selenium Server other than the default port 4444?
Selenium server could be run on java-jar selenium-server.jar-port other than its default port.
106) Explain how you can capture server side log Selenium Server?
To capture server side log in Selenium Server, you can use command: java –jar .jar –log selenium.log
107) What is a framework and what are the frameworks available in RC?
The framework is a collection of libraries and classes for helping testers to automate test cases. NUnit,
JUnit, TestNG, Bromine, RSpec, unit tests are some of the frameworks available in RC.
108) Explain how can you insert a start point in Selenium IDE?
in Selenium IDE right click on the command and the select “Set / Clear Start Point”
press “S” key on the keyboard and select the command in Selenium IDE
Object repository is an essential entity in any UI automation which allows a tester to store all object that
will be used in the scripts in one or more centralized locations rather than scattered all over the test
scripts.