02. Selenium Interview Questions Part - 2

 1.  Difference between Absolute path & Relative path.
Absolute path will start with root path (/) and Relative path will from current path (//)
Absolute xPath : /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div[@id='main']/div[@id='Blog1']/div[1]/div[1]/div/div[1]/div/h3/a
Relative xPath : //h3/a[text()='Working on New Window']

2.  Tell me some TestNG Annotations.
@Test,@Parameters,@Listeners,@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest,
@DataProvider,@BeforeGroups,@AfterGroups,@BeforeClass,@AfterClass,
@BeforeMethod,@AfterMethod,@Factory

3.  What are desiredcapabilities?
Desired Capabilities help to set properties for the Web Driver. A typical use case would be to
set the path for the Firefox Driver if your local installation doesn't correspond to the default
settings.


4.  Difference between Web driver listener and  TestNG Listener.
TestNG and Web driver Listener have different interfaces to implement and call them. They both
modify respective behaviour. You can use Listeners in Annotation. Below 2 URL gives the
 detailed  list of listener and their interfaces.

5.  Which is the best way to locate an element?

Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.

Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.

If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.

6.  Why we refer Firefox driver to the web driver inheritance. 

web Driver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same program
then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
creating object of several class is not good. So we create the reference of WebDriver and
we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program

7.  What are the features of TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing (testing a class in isolation of the others) to integration testing (testing entire  systems made of several classes, several packages and even several external frameworks,  such as application servers). You can use test suite,annotations, automatically generation  of report and much more.

8.   What is the difference between thread.Sleep()  and selenium. Set Speed ("2000")?
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

 2. Waits for only once at the command given at sleep.

9.   In what situation selenium finding element get fails?
·         Element loading issue
·         Dynamic id of web element

10.   What is the difference between "GET" and "NAVIGATE" to open a web page in selenium
web driver?
Get method will get a page to load or get page source or get text that's all whereas navigate  will guide  through the history like refresh, back, forward.For example if we want to move forward and do some functionality and back to the home page this can be achieved  through navigate() only. driver.get will wait  till the whole page gets loaded and driver.navigate  will just redirect to that page and will not wait



5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. 4. Difference between Web driver listener and TestNG Listener.
    No
    URL's attached

    ReplyDelete
  3. Selenium is one of the most popular automated testing tool used to automate various types of applications. Selenium is a package of several testing tools designed in a way for to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms and for the same reason, it is referred to as a Suite.
    Selenium Interview Questions and Answers

    ReplyDelete
  4. Great Article, I have read your post this is really helpful. Thanks for sharing important information and post. Such a nice post
    Software Testing Training in Bangalore

    ReplyDelete