Learn selenium interview questions and answers from mindmajix

Page 1

Interview Questions & Answers


What is Selenium? • Selenium is one of the most powerful open source automation tool for web application testing (even we can say acceptance testing for web application) which lets you automate operations like — type, click, selection from a drop down etc of a web page. Primarily developed in Java Script and browser technologies such as DHTML and Frames and hence supports all the major browsers on all the platforms.


How is Selenium different from commercial browser automation tools? • 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.o).


• 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.


What is Selenium 1.0? • 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.


What is Selenium 2.0? • Selenium 2.0 also known as WebDriver is the latest offering of Selenium. It provides better API than Selenium 1.0 does not suffer from Java script security restriction which Selenium 1.o does supports more UI complicated UI operations like drag and drop.


There are tons of Selenium command, am I going to use all of them • This entirely bils down to operations you are carrying out with Selenium. Though, you would definitely be usingfollowing Selenium Commands more often – • Open: opens a web page. • Click/click And Wait: click on an element and waits for a new page to load. • Select: Selects a value from a drop down value. • VerifyTitle/assertTitle: verifies/asserts page title. • Verify/assert ElementPresent: verifies/asserts presence of element, in the page. • Verify/assert TextPresent: verifies/asserts expected text is somewhere on the page.


How do I edit tests in Selenium IDE2 • There are two ways to edit tests in Selenium IDE; one is the table view while other looking into the source code of recorded commands.


What is XPath? When would I have to use XPath in SeleniumIDE? •

• • • • • • • •

XPath is a way to navigate in xml document and this can be used to identify elements in a web page. You may have to use XPath when there is no name/id associated with element on page or only partial part of name/ide is constant. Direct child is denoted with – / Relative child is denoted with – // Id, class, names can also be used with XPath – //input[@name=’0 //input[@idAst-ibl //input[@class=’ 1st’] If only part of id/name/class is constant than “contains” can be used as – //input[contains(@id.’lst-ib’)]


What is CSS location strategy in Selenium? • • • • • • • • • • •

CSS location strategy can be used with Selenium to locate elements, it works using cascade style sheet locationmethods in which — Direct child is denoted with — (a space) Relative child is denoted with – > Id, class, names can also be used with XPath — css=input[name=’q’] css=input[idAst-ibl or input#1st-ib css=input[class=’ 1st’] or input.lst If only part of id/name/class is constant than “contains” can be used as — css=input[id*=’ lst-ib ‘A Element location strategy using inner text css = a:contains(`log out’)


What verification points are available with Selenium? • There are largely three type of verification points available with selenium: • – Check for page title • – Check for certain text • – Check for certain element (textbox, drop down, table etc)


Selenium testing – any way to speed up the selenium server load time? • It’s nice to have a new copy of a Firefox process each time, but a bit overkill to double the startup time by regenerating the Firefox profile. If you open a bug report on http://jira.openqa.org and email me at atrick@browsermob.com I’ll be happy to make sure we get a solution in place. • PS: I’ve solved this problem as a one-off for myself. We use the same Firefox profile and just nuke out the cache and cookies DB. But I really should just patch that change back to the Selenium source.


• It’s simply a matter of moving the code below outside of your test setup and into the fixture setup and keeping a global of the selenium instance (code assumes NUnit.) • [TestFixtureSetUp()] • public void FixtureSetup() • { • selenium = New DefaultSelenium(“localhost”, 4444, “*firefox”, “http://1 ocalhost/”); • selenium.Start(); • selenium.SetTimeout(“30000”); • selenium.Open(“/”);


• } • Your test setup should then look something like this: • [Setup()] • public void SetUpTest() • { • selenium.Open(“default.aspx”); • selenium.WaitForPageToLoad(“30000”); • }


How to set a global Base URL for every test case of one test suite in Selenium IDE? •

If you have a lot of test cases in a single suite, it’s a pain to change the Base URL for each. Instead, create a separate case for each Base URL you need to switch between. For example, I have store https: //testing. site. com/asmyEnvironment saved as test case SetEnvTesting. I create another case for my production site, SetEnvProduction. Then, insert the ${myEnvironment} at the beginning of each relative URL in your test cases. For example, open ${myEnvironment }/login . aspx. (This might be a pain if you’ve got a lot of tests already. I suggest just adding it from now on.) Then, simply put the set-environment test case at the beginning of your test suite. To switch your entire suite to another Base URL, simply put a different set-environment case at the start. Another nice thing is that you can switch environments in the middle of the suite by putting a different set-environment case in the middle.


Edit: Example of using a SetEnvironment test case.

1. How the Currentenvironment variable is used. You can do this for every case in the suite. Additionally, you can make every separate test suite use this same SetEnvironment case, so they all switch together. 2. That the Base Url becomes irrelevant. You’re overriding it, essentially. I hope that’s helpful! The test case HTML file is responsible for setting the base URL. From the Selenium IDE, you can override the base URL for a test case. A test suite, on the other hand, is only a bag for your test cases.


• Remove the base URL setting from each of the test case files referenced from your test suite. Then set the base URL by hand for the test suite and run the suite. • The line in Q. is in the head of each test case file: • <link href=”http://server-name/” rel=”selenium.base”/> • If it is missing, then the base URL overrides it automatically. • Found it exceedingly frustrating that couldn’t just have a blank Base URL and have it use whatever page I already had open as the start of the test. What is the point of being able to record relative URLs when it forces you to hardcode a base url that is prefixed to every relative already had open as the start of the test. What is the point of being able to record relative URLs when it forces you to hardcode a base url that is prefixed to every relative url (thus turning them into absoulte urls)?? • Extending on the other answers and from this Q.: In Selenium IDE, how to get the value of the base url


• You can store the current domain in a variable and then use that instead of a hard coded one. This lets you login to the server you want to run the tests on, hit play and it will run the tests without all this baseURL nonsense redirecting you to the wrong server. Just use these commands at the start of the first script in your suite:

And keep using the http://${host } / syntax for every truly relative URL you need in your script.


Selenium WebDriver and DropDown Boxes • You could try this: • IWebElement dropDownListBox = driver. FindElement(By. Ids”selection”)); • SelectElement clickThis = new SelectElement(dropDownListBox); • clickThis. SelectByText(“Germany”); • Try the following: • import org.openqa.selenium.support.ui.Select; • Select droplist = new Select(driver.findElement(By. Ids”selection”))); • droplist.selectByVisibleText(“Germany”);



For More Info Visit Selenium Interview Questions And Answers


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.