Selenium and Web Driver Interview Questions and Answers
A. Selenium is a suite of tools for browser automation (i.e. automated Web testing). It is composed of
- Selenium IDE: A tool for recording and playing back. This is a Fire-fox plugin.
- WebDriver and RC provide the APIs for a variety of languages like Java, .NET, PHP, etc. A Java example is shown below. The WebDriver and RC work with most browsers.
- Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites.
Q. How would you go about using selenium for your web testing?
A. The example below shows the steps involved in testing a simple login page with selenium + Web Driver. The pages have HTML snippets as shown below
Login page:
...
<form method="POST" action="some/url">
<input type="text" name="username">
<input type="text" name="password">
<\form>
...
Login response page
... <table> <tr> <td>John</td>< /tr> </table> ...
STEP 1: Configure your Maven to include the required jar file selenium-java-x.x.x.jar.
<properties> <junit.version>4.4</junit.version> <selenium.version>2.7.0</selenium.version> <slf4j.version>1.5.2</slf4j.version> </properties> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> </dependencies>
The selenium-java-x.x.x.jar will transitively bring in the other relevant driver jars for different browsers.
STEP 2: It is a best practice to have separate page objects as these page objects can be shared by multiple JUnit test cases. If a particular page element changes, you will have to change it only in one place, which is page object, and not in all JUnit test cases where a paricular element is used. The JUnit test cases will depend on the page objects and should not refer to the page elements directly.
package fsg.wrap.systemtest; import org.openqa.selenium.WebDriver; public class SystemTestPage { protected WebDriver driver; protected SystemTestPage(WebDriver driver) { this.driver = driver; } }
You can have your page objects extend the above generic SystemTestPage class.
package com.systemtest.page; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import fsg.wrap.systemtest.SystemTestPage; public class LoginPage extends SystemTestPage { @FindBy(name = "username") @CacheLookup private WebElement userNameInput; @FindBy(name = "password") @CacheLookup private WebElement passwordInput; @FindBy(xpath ="//input[@type=\"submit\"]") @CacheLookup private WebElement submitButton; public LoginPage(WebDriver driver){ super(driver); } public void login(String userName, String password) { userNameInput.sendKeys(userName); userNameInput.sendKeys(password); submitButton.submit(); } public String getUserName(String userName) { WebElement element = driver.findElement(By.xpath("//td[text()=" + userName + "]")); return element.getText(); } }
STEP 3: Write the JUnit class using the page objects defined above and assert the results. These JUnit test cases can be run to test your web pages.
package com.unittests; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.WebDriverWait; import com.systemtest.page.LoginPage; public class LoginTest { private static final String BASE_URL = "http://localhost:7001/login/login.htm"; private static final String USER_NAME = "John"; private static final String PASSWORD = "aa44" private WebDriver driver; private WebDriverWait wait; private LoginPage loginPage; // the page object @Before public void setUp() { driver = new FirefoxDriver(); wait = new WebDriverWait(driver, 5); driver.get(BASE_URL); loginPage = PageFactory.initElements(driver, LoginPage.class); } @Test public void testLogin() throws Exception { loginPage.login(USER_NAME, PASSWORD); Assert.assertEquals(MAC, loginPage.getUserName(USER_NAME)); } @After public void tearDown() { driver.quit(); } }
Q. What are selenium locators? What tools do you use to locate them?
A. Selenium Locators are the way of finding the HTML element on the page to perform a Selenium action on. The example above has a line asshown below to extract the username element from the Login response page. This uses an XPath expression to locate the element.
public String getUserName(String userName) { WebElement element = driver.findElement(By.xpath("//td[text()=" + userName + "]")); return element.getText(); }
The XPath expression will be something like //td[[text()=John] which looks for a td element with text value "John".
The annotation in the above example is also a locator by name as shown below
@FindBy(name = "username") @CacheLookup private WebElement userNameInput;
This will match the HTML snippet
<input type="text" name="username">
You could also find by tagName, id, css, etc.
There are handy tools to identify the HTML elements or locators.
- Selenium IDE, which is a Firefox plugin useful in identifying the locators, debugging, etc.
- The Fire-bug plugin, which allows you to inspect the elements by right clicking on the page and then selecting "Inspect Element". Google chrome provides a similar functionality to inspect element out of the box.
Q. In your experience, what are some of the challenges with Selenium?
A. In general, badly written test cases whether junit tests or web tests, the biggest complaint is about writing test cases that are not maintainable. Unmaintainable automated test cases can take more time than manual tests. So, it is important to write quality test cases by clearly separting the page objects from the test cases as demonstrated in the Q&A above. The use of the locators need to be carefully thought through. For example, some frameworks like JSF dynamically generate HTML element IDs. So, if IDs are used in your tests, then the test cases may fail if the IDs have changed. The solution to this problem is to use XPath to find the relevant HTML elements. The ClickAndWait action will not work for AJAX calls, and use "waitForElement" instead.
Q1. What is Selenium?
Ans. Selenium is a set of tools that supports rapid development of test automation scripts for web
based applications. Selenium testing tools provides a rich set of testing functions specifically
designed to fulfil needs of testing of a web based application.
Q2. What are the main components of Selenium testing tools?
Ans. Selenium IDE, Selenium RC and Selenium Grid
Q3. What is Selenium IDE?
Ans. Selenium IDE is for building Selenium test cases. It operates as a Mozilla Firefox add on and provides an easy to use interface for developing and running individual test cases or entire test suites. Selenium-IDE has a recording feature, which will keep account of user actions as they are performed and store them as a reusable script to play back.
Q4. What is the use of context menu in Selenium IDE?
Ans. It allows the user to pick from a list of assertions and verifications for the selected location.
Q5. Can tests recorded using Selenium IDE be run in other browsers?
Ans. Yes. Although Selenium IDE is a Firefox add on, however, tests created in it can also be run in other browsers by using Selenium RC (Selenium Remote Control) and specifying the name of the test suite in command line.
Q6. What are the advantage and features of Selenium IDE?
Ans. 1. Intelligent field selection will use IDs, names, or XPath as needed
2. It is a record & playback tool and the script format can be written in various languages including : C#, Java, PERL, Python, PHP, HTML
3. Auto complete for all common Selenium commands
4. Debug and set breakpoints
5. Option to automatically assert the title of every page
6. Support for Selenium user-extensions.js file
Q7. What are the disadvantage of Selenium IDE tool?
Ans. 1. Selenium IDE tool can only be used in Mozilla Firefox browser.
2. It is not playing multiple windows when we record it.
Q8. What is Selenium RC (Remote Control)?
Ans. Selenium RC allows the test automation expert to use a programming language for maximum flexibility and extensibility in developing test logic. For example, if the application under test returns a result set and the automated test program needs to run tests on each element in the result set, the iteration / loop support of programming language’s can be used to iterate through the result set, calling Selenium commands to run tests on each item. Selenium RC provides an API and library for each of its supported languages. This ability to use Selenium RC with a high level programming language to develop test cases also allows the automated testing to be integrated with the project’s automated build environment.
Q9. What is Selenium Grid?
Ans. Selenium Grid in the selenium testing suit allows the Selenium RC solution to scale for test suites that must be run in multiple environments. Selenium Grid can be used to run multiple instances of Selenium RC on various operating system and browser configurations.
Q10. How Selenium Grid works?
Ans. Selenium Grid sent the tests to the hub. Then tests are redirected to an available Selenium RC, which launch the browser and run the test. Thus, it allows for running tests in parallel with the entire test suite.
Q 11. What you say about the flexibility of Selenium test suite? [/b]
Ans. Selenium testing suite is highly flexible. There are multiple ways to add functionality to Selenium framework to customize test automation. As compared to other test automation tools, it is Selenium’s strongest characteristic. Selenium Remote Control support for multiple programming and scripting languages allows the test automation engineer to build any logic they need into their automated testing and to use a preferred programming or scripting language of one’s choice. Also, the Selenium testing suite is an open source project where code can be modified and enhancements can be submitted for contribution.
Q12. What test can Selenium do?
Ans. Selenium is basically used for the functional testing of web based applications. It can be used for testing in the continuous integration environment. It is also useful for agile testing
Q13. What is the cost of Selenium test suite?
Ans. Selenium test suite a set of open source software tool, it is free of cost.
Q14. What browsers are supported by Selenium Remote Control?
Ans. The test automation expert can use Firefox, IE 7/8, Safari and Opera browsers to run tests in Selenium Remote Control.
Q15. What programming languages can you use in Selenium RC?
Ans. C#, Java, Perl, PHP, Python, Ruby
Q16. What are the advantages and disadvantages of using Selenium as testing tool?
Ans. Advantages: Free, Simple and powerful DOM (document object model) level testing, can be used for continuous integration; great fit with Agile projects.
Disadvantages: Tricky setup; dreary errors diagnosis; can not test client server applications.
Q17. What is difference between QTP and Selenium?
Ans. Only web applications can be testing using Selenium testing suite. However, QTP can be used for testing client server applications. Selenium supports following web browsers: Internet Explorer, Firefox, Safari, Opera or Konqueror on Windows, Mac OS X and Linux. However, QTP is limited to Internet Explorer on Windows.
QTP uses scripting language implemented on top of VB Script. However, Selenium test suite has the flexibility to use many languages like Java, .Net, Perl, PHP, Python, and Ruby.
Q18. What is difference between Borland Silk test and Selenium?
Ans. Selenium is completely free test automation tool, while Silk Test is not. Only web applications can be testing using Selenium testing suite. However, Silk Test can be used for testing client server applications. Selenium supports following web browsers: Internet Explorer, Firefox, Safari, Opera or Konqueror on Windows, Mac OS X and Linux. However, Silk Test is limited to Internet Explorer and Firefox.
WebDriver or Selenium 2.0
1: What is Selenium 2.0? I have heard
this buzz word many
times.
Answer:
Selenium 2.0 is a consolidation of two web testing tools:
a) Selenium RC and
b) WebDriver,
It claims to give best of both words: Selenium and WebDriver.
2: Why are two tools being combined as Selenium 2.0?
Answer:
Selenium 2.0 promises to give much cleaner API than Selenium RC
and at the same time not being restricted by JavaScript Security
restriction like same origin policy.
3: So everyone is going to use Selenium 2.0?
Answer:
Well no, for example if you are using Selenium Perl client driver than
there is no similar offering from Selenium 2.0 and you would have to
stick to Selenium 1.0 till there is similar library available for Selenium
2.0
4: So how do I specify my browser configurations with
Selenium 2.0?
Answer:
Selenium 2.0 offers following browser/mobile configuration:
a) AndroidDriver,
b) ChromeDriver,
c) EventFiringWebDriver,
d) FirefoxDriver,
e) HtmlUnitDriver,
f) InternetExplorerDriver,
g) IPhoneDriver,
h) IPhoneSimulatorDriver,
i) RemoteWebDriver
And all of them have been implemented from interface WebDriver.
To be able to use any of these drivers, you need to instantiate their
corresponding classes.
5: How is Selenium 2.0 configuration different from Selenium
1.0?
Answer:
In case of Selenium 1.0, you need Selenium jar file pertaining to one
library; for example, in case of Java you need Java client driver and
also Selenium server jar file. With Selenium 2.0, you need language
binding (i.e. Java, C#, etc) and Selenium server jar if you are using
Remote Control or Remote WebDriver.
times.
Answer:
Selenium 2.0 is a consolidation of two web testing tools:
a) Selenium RC and
b) WebDriver,
It claims to give best of both words: Selenium and WebDriver.
2: Why are two tools being combined as Selenium 2.0?
Answer:
Selenium 2.0 promises to give much cleaner API than Selenium RC
and at the same time not being restricted by JavaScript Security
restriction like same origin policy.
3: So everyone is going to use Selenium 2.0?
Answer:
Well no, for example if you are using Selenium Perl client driver than
there is no similar offering from Selenium 2.0 and you would have to
stick to Selenium 1.0 till there is similar library available for Selenium
2.0
4: So how do I specify my browser configurations with
Selenium 2.0?
Answer:
Selenium 2.0 offers following browser/mobile configuration:
a) AndroidDriver,
b) ChromeDriver,
c) EventFiringWebDriver,
d) FirefoxDriver,
e) HtmlUnitDriver,
f) InternetExplorerDriver,
g) IPhoneDriver,
h) IPhoneSimulatorDriver,
i) RemoteWebDriver
And all of them have been implemented from interface WebDriver.
To be able to use any of these drivers, you need to instantiate their
corresponding classes.
5: How is Selenium 2.0 configuration different from Selenium
1.0?
Answer:
In case of Selenium 1.0, you need Selenium jar file pertaining to one
library; for example, in case of Java you need Java client driver and
also Selenium server jar file. With Selenium 2.0, you need language
binding (i.e. Java, C#, etc) and Selenium server jar if you are using
Remote Control or Remote WebDriver.
Selenium Interview questions – 3
11: What are two modes of views in
Selenium IDE?
Answer:
Selenium IDE can be opened either in side bar (View > Side bar >
Selenium IDE) or as a pop up window (Tools > Selenium IDE). While
using Selenium IDE in browser side bar it cannot record user
operations in a pop up window opened by application.
12: Can I control the speed and pause test execution in Selenium
IDE?
Answer:
Selenium IDE provides a slider with Slow and Fast pointers to control
the speed of execution.
13: Where do I see the results of Test Execution in Selenium IDE?
Answer:
Result of test execution can be views in log window in Selenium IDE:
14: Where do I see the description of commands used in Selenium
IDE?
Answer:
Commands of description can be seen in Reference section:
15: Can I build test suite using Selenium IDE?
Answer:
Yes, you can first record individual test cases and then group all of
them in a test suite. Following this entire test suite could be executed
instead of executing individual tests.
Answer:
Selenium IDE can be opened either in side bar (View > Side bar >
Selenium IDE) or as a pop up window (Tools > Selenium IDE). While
using Selenium IDE in browser side bar it cannot record user
operations in a pop up window opened by application.
12: Can I control the speed and pause test execution in Selenium
IDE?
Answer:
Selenium IDE provides a slider with Slow and Fast pointers to control
the speed of execution.
13: Where do I see the results of Test Execution in Selenium IDE?
Answer:
Result of test execution can be views in log window in Selenium IDE:
14: Where do I see the description of commands used in Selenium
IDE?
Answer:
Commands of description can be seen in Reference section:
15: Can I build test suite using Selenium IDE?
Answer:
Yes, you can first record individual test cases and then group all of
them in a test suite. Following this entire test suite could be executed
instead of executing individual tests.
October 19, 2011 @ 1:53 pm
Selenium Interview Questions – 2
6: Which language is used in Selenium
IDE?
Answer:
Selenium IDE uses HTML sort of language called Selenese. Though
other languages (Java, C#, PHP etc) cannot be used with Selenium
IDE, Selenium IDE lets you convert test in these languages so that
they could be used with Selenium 1.0 or Selenium 2.0
7: What is Selenium 1.0?
Answer:
Selenium 1.0 or Selenium Remote Control (popularly known as
Selenium RC) is library available in wide variety of languages. The
primary reason of advent of Selenium RC was incapability of
Selenium IDE to execute tests in browser other than Selenium IDE
and the programmatical limitations of language Selenese used in
Selenium IDE.
8: What is Selenium 2.0?
Answer:
Selenium 2.0 also known as WebDriver is the latest offering of
Selenium. It provides:
a) better API than Selenium 1.0
b) does not suffer from Java Script security restriction which
Selenium 1.0 does
c) supports more UI and complicated UI operations like drag and drop
9: What are the element locators available with Selenium which
could be used to locate elements on web page?
Answer:
There are mainly four locators used with Selenium:
a) html id
b) html name
c) XPath locator and
d) CSS locators
10: What is Selenium Grid?
Answer:
Selenium Grid lets you distribute your tests on multiple machines and
all of them at the same time. Hence you can execute test on IE on
Windows and Safari on Mac machine using the same test script (well,
almost always). This greatly helps in reducing the time of test
execution and provides quick feedback to stack holders.
Answer:
Selenium IDE uses HTML sort of language called Selenese. Though
other languages (Java, C#, PHP etc) cannot be used with Selenium
IDE, Selenium IDE lets you convert test in these languages so that
they could be used with Selenium 1.0 or Selenium 2.0
7: What is Selenium 1.0?
Answer:
Selenium 1.0 or Selenium Remote Control (popularly known as
Selenium RC) is library available in wide variety of languages. The
primary reason of advent of Selenium RC was incapability of
Selenium IDE to execute tests in browser other than Selenium IDE
and the programmatical limitations of language Selenese used in
Selenium IDE.
8: What is Selenium 2.0?
Answer:
Selenium 2.0 also known as WebDriver is the latest offering of
Selenium. It provides:
a) better API than Selenium 1.0
b) does not suffer from Java Script security restriction which
Selenium 1.0 does
c) supports more UI and complicated UI operations like drag and drop
9: What are the element locators available with Selenium which
could be used to locate elements on web page?
Answer:
There are mainly four locators used with Selenium:
a) html id
b) html name
c) XPath locator and
d) CSS locators
10: What is Selenium Grid?
Answer:
Selenium Grid lets you distribute your tests on multiple machines and
all of them at the same time. Hence you can execute test on IE on
Windows and Safari on Mac machine using the same test script (well,
almost always). This greatly helps in reducing the time of test
execution and provides quick feedback to stack holders.
Selenium Interview Questions -1
1: What is Selenium?
Answer:
Selenium is a browser automation tool which lets you automated
operations like: type, click, and selection from a drop down of a web
page.
2: How is Selenium different from commercial browser
automation tools?
Answer:
Selenium is a library which is available in a gamut of languages i.e.
Java, C#, Python, Ruby, PHP etc while most commercial tools are
limited in their capabilities of being able to use just one language.
More over many of those tools have their own proprietary language
which is of little use outside the domain of those tools. Most
commercial tools focus on record and replay while Selenium
emphasis on using Selenium IDE (Selenium record and replay) tool
only to get acquainted with Selenium working and then move on to
more mature Selenium libraries like Remote control (Selenium 1.0)
and Web Driver (Selenium 2.0).
Though most commercial tools have built in capabilities of test
reporting, error recovery mechanisms and Selenium does not provide
any such features by default, but given the rich set of languages
available with Selenium, it very easy to emulate such features.
3: What are the set of tools available with Selenium?
Answer:
Selenium has four set of tools:
a) Selenium IDE,
b) Selenium 1.0 (Selenium RC),
c) Selenium 2.0 (WebDriver) and
d) Selenium Grid.
Selenium Core is another tool but since it is available as part of
Selenium IDE as well as Selenium 1.0, it is not used in isolation.
4: Which Selenium Tool should I use?
Answer:
It entirely boils down to where you stand today in terms of using
Selenium. If you are entirely new to Selenium then you should begin
with Selenium IDE to learn Selenium location strategies and then
move to Selenium 2 as it is the most stable Selenium library and
future of Selenium. Use Selenium Grid when you want to distribute
your test across multiple devices. If you are already using Selenium
1.0 than you should begin to migrate your test scripts to Selenium 2.0
5: What is Selenium IDE?
Answer:
Selenium IDE is a Firefox plug-in which is (by and large) used to
record and replay test in Firefox browser. Selenium IDE can be used
only with Firefox browser.
Answer:
Selenium is a browser automation tool which lets you automated
operations like: type, click, and selection from a drop down of a web
page.
2: How is Selenium different from commercial browser
automation tools?
Answer:
Selenium is a library which is available in a gamut of languages i.e.
Java, C#, Python, Ruby, PHP etc while most commercial tools are
limited in their capabilities of being able to use just one language.
More over many of those tools have their own proprietary language
which is of little use outside the domain of those tools. Most
commercial tools focus on record and replay while Selenium
emphasis on using Selenium IDE (Selenium record and replay) tool
only to get acquainted with Selenium working and then move on to
more mature Selenium libraries like Remote control (Selenium 1.0)
and Web Driver (Selenium 2.0).
Though most commercial tools have built in capabilities of test
reporting, error recovery mechanisms and Selenium does not provide
any such features by default, but given the rich set of languages
available with Selenium, it very easy to emulate such features.
3: What are the set of tools available with Selenium?
Answer:
Selenium has four set of tools:
a) Selenium IDE,
b) Selenium 1.0 (Selenium RC),
c) Selenium 2.0 (WebDriver) and
d) Selenium Grid.
Selenium Core is another tool but since it is available as part of
Selenium IDE as well as Selenium 1.0, it is not used in isolation.
4: Which Selenium Tool should I use?
Answer:
It entirely boils down to where you stand today in terms of using
Selenium. If you are entirely new to Selenium then you should begin
with Selenium IDE to learn Selenium location strategies and then
move to Selenium 2 as it is the most stable Selenium library and
future of Selenium. Use Selenium Grid when you want to distribute
your test across multiple devices. If you are already using Selenium
1.0 than you should begin to migrate your test scripts to Selenium 2.0
5: What is Selenium IDE?
Answer:
Selenium IDE is a Firefox plug-in which is (by and large) used to
record and replay test in Firefox browser. Selenium IDE can be used
only with Firefox browser.
More......>>
No comments:
Post a Comment