selenium webdriver interview questions

13
Selenium Webdriver Interview Questions Android App: https://goo.gl/NDkpj6 E-Mail: [email protected] Dear readers, these set of interview questions are designed in a way to help in cracking the automation testing with Selenium Webdriver. In this document we will try to cover all those topics which we generally use with Selenium Webdriver, such as Maven, TestNG etc. To download the android application for Selenium Webdriver Interview Questions, follow the below link: Selenium WebDriver Interview Questions Android Application 1. What is Selenium Webdriver? Ans: Selenium WebDriver is an open source web automation tool which provides support for multiple browser, platforms and languages. Brief History: Selenium developed by Jason Huggins in 2004. Later in 2006 an engineer from Google named Simon Stewart started working on WebDriver and thought to remove the limitation and merged Selenium with WebDriver in 2008, also known as Selenium 2.0. In 2009 Simon Stewart declared the reason why both of the projects were merged: “Why are the projects merging? Partly because Webdriver addresses some shortcomings in selenium (for example, by being able to bypass the JS sandbox, and we’ve got a gorgeous API), partly because selenium addresses some shortcomings in Webdriver (such as supporting a broader range of browsers) and partly because the main selenium contributors and I felt that it was the best way to offer users the best possible framework.” 2. Describe Selenium Tool Suite. Ans: Selenium is composed of multiple software tools: 1. Selenium 2: Also known as Selenium WebDriver, It supports the WebDriver API along with Selenium 1 technology underneath the WebDriver API for maximum flexibility in porting tests. In addition, Selenium 2 still runs Selenium 1's Selenium RC interface for backward compatibility. 2. Selenium 1: Also known as Selenium RC, It was the main Selenium project for a long time. Now Selenium 1 is deprecated and not actively supported. 3. Selenium IDE: Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed. 3. Why would you select Selenium as test tool for your project? Ans: There are multiple reason to select Selenium as test tool for my project: 1. is free and open source 2. have a large user base and helping communities 3. have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.) 4. have great platform compatibility (Windows, Mac OS, Linux etc.) 5. supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) 6. supports distributed testing 4. What are the different testing type we can perform with Selenium WebDriver? Ans: Selenium WebDriver supports following types of testing: 1. Functional Testing 2. Regressioin Testing

Upload: jai-singh

Post on 07-Jan-2017

297 views

Category:

Education


1 download

TRANSCRIPT

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

Dear readers, these set of interview questions are designed in a way to help in cracking the automation testing with Selenium Webdriver. In this document we will try to cover all those topics which we generally use with Selenium Webdriver, such as Maven, TestNG etc. To download the android application for Selenium Webdriver Interview Questions, follow the below link:

Selenium WebDriver Interview Questions Android Application

1. What is Selenium Webdriver?

Ans: Selenium WebDriver is an open source web automation tool which provides support for multiple browser, platforms and languages. Brief History: Selenium developed by Jason Huggins in 2004. Later in 2006 an engineer from Google named Simon Stewart started working on WebDriver and thought to remove the limitation and merged Selenium with WebDriver in 2008, also known as Selenium 2.0. In 2009 Simon Stewart declared the reason why both of the projects were merged: “Why are the projects merging? Partly because Webdriver addresses some shortcomings in selenium (for example, by being able to bypass the JS sandbox, and we’ve got a gorgeous API), partly because selenium addresses some shortcomings in Webdriver (such as supporting a broader range of browsers) and partly because the main selenium contributors and I felt that it was the best way to offer users the best possible framework.”

2. Describe Selenium Tool Suite. Ans: Selenium is composed of multiple software tools: 1. Selenium 2: Also known as Selenium WebDriver, It supports the WebDriver API along with Selenium 1 technology underneath the WebDriver API for maximum flexibility in porting tests. In addition, Selenium 2 still runs Selenium 1's Selenium RC interface for backward compatibility. 2. Selenium 1: Also known as Selenium RC, It was the main Selenium project for a long time. Now Selenium 1 is deprecated and not actively supported. 3. Selenium IDE: Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.

3. Why would you select Selenium as test tool for your project? Ans: There are multiple reason to select Selenium as test tool for my project: 1. is free and open source 2. have a large user base and helping communities 3. have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.) 4. have great platform compatibility (Windows, Mac OS, Linux etc.) 5. supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) 6. supports distributed testing

4. What are the different testing type we can perform with Selenium WebDriver?

Ans: Selenium WebDriver supports following types of testing: 1. Functional Testing 2. Regressioin Testing

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

5. What are the limitations of Selenium WebDriver?

Ans: Following are the limitations of Selenium WebDriver: 1. Selenium supports testing of only web based applications 2. Reports can only be generated using third party tools like TestNG or Junit. 3. As Selenium is a free tool, thus there is no ready vendor support though the user can find numerous helping communities. 4. User is expected to possess prior programming language knowledge.

6. What is Selenese?

Ans: Selenese is the language which is used to write scripts in Selenium IDE.

7. Mention five different types of exception you have encountered in Selenium WebDriver?

Ans: Different types of exception:

1. NoSuchElementException 2. WebDriverException 3. TimeoutException 4. NoSuchWindowException 5. StaleElementException

8. What are the different types of Driver implementations?

Ans: Following are the different types of driver implementations: 1. FirefoxDriver 2. ChromeDriver 3. IntenetExplorerDriver 4. HtmlUnitDriver 5. RemoteWebDriver 6. SafariDriver 7. WebDriverBackedSelenium

9. Which WebDriver implementation is fastest and why?

Ans: HTMLUnitDriver is fastest and most lightweight implementation of WebDriver. HTMLUnit does not execute test on Browser but sends plain HTTP requests which makes test execution faster. Pros: 1. Fastest implementation of WebDriver. 2. A pure Java implementation so it is platform independent. 3. Supports JavaScript. Cons: 1. Emulates other Browser's JS behavior.

10. How does WebDriver drive browser as compared to Selenium-RC?

Ans: Selenium WebDriver makes direct calls to the browser using each browser's native support for automation. Whereas, Selenium-RC injects JavaScript functions to the browser when it's loaded and then use JavaScript to drive the application under test.

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

11. What is Automation testing?

Ans: Automation testing or Test Automation is a process to simulate user actions of application under test. Automation testing with help of available testing tools such as, Selenium WebDriver helps in creating automated test scripts and reduces the execution time, increases the efficiency and removes manual intervention.

12. Which languages Selenium IDE can export the script? Ans: From the Selenium IDE test scripts cab be exported in following languages: 1. Java 2. Python 3. Ruby 4. C#

13. What is the difference between "GET" and "NAVIGATE" to open a web page in selenium web driver?

Ans: Get method will get page to load, get a page source or get the text of an element whereas navigate will guide through history like refresh, back and forward.

14. What is difference between driver.close() and driver.quit()?

Ans: driver.close(): It is used to close the browser or page currently in focus. driver.quit(): It is used to shut down the Webdriver and close all instances associated to Webdriver.

15. What are the different verification points in Selenium Webdriver?

Ans: There are largely three types of verification point in selenium Webdriver: 1. Verification for Page title 2. Verification for certain text 3. Verification for certain element such as text field, button, drop down, table etc.

16. What difference is between assert and verify commands?

Ans : Assert: Assert command checks whether given condition is true or false and when it fails test will abort. Verify: Verify command checks whether the given condition is true or false and will continue the execution whether it is true or false.

17. What are locators?

Ans: Locators can be termed as address to elements on the page, which makes possible to identify element uniquely on the page.

18. What are the different locators available in Selenium Webdriver?

Ans: Following are the different types of locators available in Selenium WebDriver: 1. ID 2. Name 3. ClassName 4. Xpath 5. CSS Selector 6. LinkText

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

7. PartialLinkText 8. TagName

19. What is XPath?

Ans: XPath, the XML path language, is a query language for selecting nodes from an XML document. It enables to traverse through every node across the entire page and help in finding element with reference to another element on page.

20. Why ID is most preferable way to identify the element?

Ans: Using the ID attribute is most preferable way to identify the element. W3C recommends that every developer should provide id attribute to elements which are unique on the page. While processing the DOM (Document Object Model), browsers use id as the preferred way to identify the element and this provides the fastest locator strategy.

21. What difference is between findElement() and findElements() method?

Ans: findElement() and findElements() methods are used in selenium to locate the elements. findElement(): The findElement() method returns a WebElement object based on a specified search criteria or throws up an exception if it does not find any element matching the search criteria. findElements(): The findElements() method returns a list of WebElements matching the search criteria. If no elements are found, it returns an empty list.

22. What are different methods to locate elements with partial match?

Ans: CSSSelector and XPath provides a way to locate elements matching partial attribute values using following functions: 1. starts-with() 2. ends-with() 3. contains()

23. What are XPath axes?

Ans: XPath axes helps to locate elements based on their relationship with another element. Following are few examples how to use axes: table: Product Price Qty product1 $100 12 product2 $200 3 1. ancestor: Selects all ancestors(parent, grandparent and so on) of the current node. Eg: //td[text()='sksdroid']/ancestors::table It will get the table element. 2. descendant: Selects all descendants (children, grandchildren, and so on) of the current node. Eg: /table/descendant::td/input This will get the input element from the third column of the second row from the table. 3. following: Selects everything in the document after the closing tag of the current node. Eg: //td[text()='Product1']/following::tr This will get the second row from the table.

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

4. following-sibling: Selects all siblings after the current node. Eg: //td[text()='Product1']/followingsibling::td This will get the second column from the second row immediately after the column that has Product 1 as the text value. 5. preceding: Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes, and namespace nodes. Eg: //td[text()='$150']/preceding::tr This will get the header row. 6. precedingsibling: Selects all siblings before the current node. Eg: //td[text()='$150']/precedingsibling::td This will get the first column of third row from the table.

24. What are the ways to locate elements using advanced CSS Selectors?

Ans: Following are the some structural pseudo-classes which is used to locate elements: 1. :first-child Eg: form#loginForm:first-child this will locate the first element under the form. 2. last-child Eg: form#loginForm:last-child this will locate the last element under the form. 3. nth-child(2) Eg: form#loginForm:nth-child(2) this will locate the second child element under the form.

25. Can you show how to launch Firefox Webdriver instance and open google?

Ans: WebDriver driver = new FirefoxDriver();

driver.get("http://www.google.com");

26. How can you maximize the browser?

Ans: WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

27. How can you click on an element?

Ans: WebDriver driver = new FirefoxDriver();

driver.findElement(By.id("submit")).click();

28. How can you write something in a textbox?

Ans: WebDriver driver = new FirefoxDriver();

driver.findElement(By.id("user_id")).sendKeys("sksdroid");

29. How can you clear a textbox? Ans: WebDriver driver = new FirefoxDriver();

driver.findElement(By.id("user_id")).clear();

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

30. How to select a radio button using webdriver?

Ans: WebDriver driver = new FirefoxDriver(); WebElement radioEle = driver.findElement(By.id("male")); radioEle.click();

31. How can you verify that radio button is selected?

Ans: WebDriver driver = new FirefoxDriver();

WebElement radioEle = driver.findElement(By.id("male")); radioEle.isSelected(); It will return a boolean value whether radio button is selected or not.

32. How to capture the title of a page?

Ans: WebDriver driver = new FirefoxDriver();

String pageTitle = driver.getTitle();

33. How to get page source using webdriver?

Ans: WebDriver driver = new FirefoxDriver();

String pageSource = driver.getPageSource();

34. How to fetch the current URL using webdriver?

Ans: WebDriver driver = new FirefoxDriver();

driver.getCurrentUrl();

35. How can you find if an element in displayed on the screen?

Ans: WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc. 1. isDisplayed() 2. isSelected() 3. isEnabled() Example: isDisplayed(): boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed(); isSelected(): boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed(); isEnabled(): boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

36. How can we get a text of a web element?

Ans: getText() method is used to retrieve the inner text of the specified web element.

Eg: String Text = driver.findElement(By.id(“Text”)).getText();

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

37. How to select value in a dropdown?

Ans: Value in the drop down can be selected using WebDriver’s Select class. Example: selectByValue: Select selectByValue = new Select(driver.findElement(By.id(“Select_One”))); selectByValue.selectByValue(“Android”); selectByVisibleText: Select selectByVisibleText = new Select (driver.findElement(By.id(“Select_Two”))); selectByVisibleText.selectByVisibleText(“iOS”); selectByIndex: Select selectByIndex = new Select(driver.findElement(By.id(“Select_Three”))); selectByIndex.selectByIndex(3);

38. What are the different types of navigation commands?

Ans: Following are the navigation commands:

1. navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history. Example: driver.navigate().back(); 2. navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history. Example: driver.navigate().forward(); 3. navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements. Example: driver.navigate().refresh(); 4. navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL. Example: driver.navigate().to(“https://google.com”);

39. How to click on a hyper link using linkText?

Ans: driver.findElement(By.linkText(“Images”)).click();

The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page. The above mentioned link can also be accessed by using the following command. driver.findElement(By.partialLinkText(“Ima”)).click(); The above command find the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

40. How to find elements with same property and store it in a list?

Ans: Multiple elements having same attribute value on page can be located by using findElements() method and can be stored in a list, find below the sample code for the same:

import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class FindMultipleElements { WebDriver driver; @BeforeTest public void launchURL(){ driver = new FirefoxDriver(); driver.get("www.google.com"); } @Test public void findAllElements(){ List<WebElement> appsList = driver.findElements(By.xpath(".//*[@class='gb_o']")); for(int i=0;i<appsList.size();i++){ System.out.println(appsList.get(i).getText()); } } @AfterTest public void tearDown(){ driver.quit(); } }

41. How to assert title of the web page?

Ans: Assert.assertTrue(driver.getTitle().equals("Google"), "Title is incorrect");

Below are the few questions related to Architecture: 42. Explain Selenium Webdriver Architecture.

Ans: Selenium Webdriver uses browser's native support for automation (Which is different for every browser.), It controls the browser from OS level. Selenium Webdriver architecture mainly divided into three parts: 1. Language Bindings 2. Selenium Webdriver API, and 3. Drivers

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

Selenium Webdriver supports various languages which can be used to implement the automation framework using Selenium Webdriver API. Let’s say you have written code using Java bindings against the Selenium Webdriver API and that binding code will issue commands across JSON wire protocol (This is a rest-base web service that is able to interpret those commands by manipulating DOM elements on the page). Finally the driver (It is a executable which runs your tests on one of the driver) waiting for commands executes it on specified browser.

43. What is Webdriver API?

Ans: The Webdriver API is the part of the system that you interact all the time while automating. The Webdriver API as compared to Selenium RC API is different in many ways. This is now more manageable. This is made up of the Webdriver and the WebElement objects. driver.findElement(By.name("q")) and element.sendKeys("Hello World!!")

44. What is Webdriver SPI?

Ans: The WebDriver SPI stands for WebDriver Stateless Programming Interface, it is a mechanism that breaks down what the element is, by using a unique ID, and then calling a command that is relevant. All the API calls above then call down. Webdriver API calls: driver.findElement(By.name("q")) element.sendKeys("Hello World!!") The above written code will look like when once it is in the SPI: findElement(using="name", value="q") sendKeys(element="webdriverID", value="Hello World!!")

45. What is JSON wire protocol?

Ans: The Webdriver developers created a transport mechanism called the JSON wire protocol. This protocol is able to transport all the necessary elements to the code that controls it. It uses a REST like API as the way to communicate.

Below are the questions related to TestNG: 46. What is TestNG?

Ans: TestNG is an open-source automated testing framework inspired from Junit and Nunit but introducing some new functionalities that make it more powerful and easier to use. Functionalities such as use of annotations for dependency testing, test in groups, email-able reporting, multithreaded testing, data-driven testing, flexible plugin API etc.. TestNG is designed to cover all categories of tests such as Unit, Functional, end-to-end and Integration.

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

47. What are the advantages of TestNG over Junit?

Ans: Advantages of TestNG includes: 1. TestNG is easy to understand. 2. TestNG allows grouping of test cases which is not possible in Junit. 3. TestNG support additional annotations like, @Before & @After Suite, @Before & @After Test and @Before & @After Group. 4. By using TestNG it is possible to run tests in parallel. 5. TestNG allows you to determine the dependent test cases.

48. What is testng.xml used for?

Ans: TestNG.xml is a configuration file for managing the tests and also describes the runtime definition of a test suite. It allows flexible configuration of the tests to be run. This file makes it easy to define all your test suites and their properties in one file. It is always recommended to use testng.xml once your test become larger and requires configuration of multiple test at one place. The testng.xml file will have following hierarchy: 1. The root tag of this file <suite> 2. <suite> tag can contain one or more <test> tags 3. <test> tag can contain one or more <classes> tags 4. <classes> tag can contain one or more <method> tags Refer the below testng.xml sample: <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1" verbose="1" > <test name="Nopackage" > <classes> <class name="NoPackageTest" /> </classes> </test> <test name="Regression1"> <classes> <class name="test.sample.ParameterSample"/> <class name="test.sample.ParameterTest"/> <methods> <include name="testMethod" /> </methods> </classes> </test> </suite>

49. What are the different ways to invoke TestNG?

Ans: You can invoke TestNG in several different ways: 1. With a testng.xml file 2. With ant 3. from the command line

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

50. Describe the use of parallel attribute of <test> tag.

Ans: The parallel attribute on the <suite> tag can take one of following values: <suite name="My suite" parallel="methods" thread-count="5"> TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified. <suite name="My suite" parallel="tests" thread-count="5"> TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests. <suite name="My suite" parallel="classes" thread-count="5"> TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread. <suite name="My suite" parallel="instances" thread-count="5"> TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.

51. What is timeout test in TestNG?

Ans: The timeout test in TestNG is time allotted to perform the testing. If the test fails to finish in that specified time limit, TestNG will abandon the further testing and will mark it as failed.

Below are the questions related to Maven: 52. What is Maven?

Ans: Maven, a Yeddish word meaning 'accumulator of knowledge', was originally started as an attempt to simplify the build processes in the Jakarta Turbine Project. Definition: Maven is a project management and comprehension tool. Based on the concept of page object model (POM), maven can manage a project's build, reporting and documentation.

53. What are the main objectives of Maven?

Ans: Maven's primary goal is to allow a developer to comprehend the complete state of the development effort in the shortest period of time. To attain this goal there are serveral areas of concern that Maven attempts to deal with: 1. Making the build process easy. 2. Providing the uniform build system. 3. Providing quality project information. 4. Providing guidelines for the best practices development. 5. Allowing transparent migration to the new features.

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

54. What are the different aspects managed by Maven?

Ans: Following are the different aspects managed by maven: 1. Builds 2. Documentations 3. Reporting 4. SCMs 5. Release 6. Distribution

55. How can you say that maven uses convention over configuration?

Ans: "Convention over configuration (aka Coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing the flexibility." It is said that maven uses convention over configuration because in maven, developers are not required to create build process themselves. Developers do not have to mention each and every configuration details.

56. What is POM?

Ans: POM or page object model is a fundamental unit of Maven. It is an XML file that contains information about the project and configuration details used by maven to build the project. It resides in the base directory of the project as pom.xml.

57. What information does POM contain?

Ans: Following are the configuration information contained by POM: 1. Project dependencies 2. Plugins 3. Goals 4. Build profiles 5. Project version 6. Developers 7. Mailing list

58. What is maven artifact?

Ans: An artifact is a file, usually a JAR, that gets deployed to a Maven repository. A maven build produces one or more artifacts, such as a compiled JAR and source JAR. Each artifact has a Group Id, an artifact Id and a version string. The three together uniquely identify the artifact.

59. What is Maven build life cycle and name three lifecycle of Maven.

Ans: A build lifecycle is a well-defined sequence of phases which define the order in which the goals are to be executed. Following are the three lifecycles: 1. clean 2. default 3. site

Selenium Webdriver Interview Questions

Android App: https://goo.gl/NDkpj6

E-Mail: [email protected]

60. What are the phases in Maven? Ans: Following are the build phases: 1. validate 2. complile 3. test 4. package 5. integration-test 6. verify 7. install 8. deploy

61. What is the command to check the maven version?

Ans: Type the following command on cmd:

mvn –version

Please follow the below link and stay updated about new questions added in the interview kit.

To download the android application for Selenium Webdriver Interview Questions, follow the below link:

Selenium WebDriver Interview Questions Android Application References: http://www.seleniumhq.org/ http://testng.org/ https://maven.apache.org/