Sunday 1 October 2017

Selenium Super 30 Interview Questions - 1

ad300
Advertisement

 

1.     Do you know how Ajax works? How you do make sure that the element is present after the Ajax Call.

               WebDriverWait wait = new WebDriverWait(driver, waitTime);

               wait.until(ExpectedConditions.presenceOfElementLocated(locator));

  2. How implicit wait works internally. What is the default value for implicit wait? 

v  Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script.  

v  Being easy and simple to apply, implicit wait introduces a few drawbacks as well. It gives rise to the test script execution time as each of the command would be ceased to wait for a stipulated amount of time before resuming the execution.

·        implicitlyWait(10, TimeUnit.SECONDS);

v  The implicit wait mandates to pass two values as parameters. The first argument indicates the time in the numeric digits that the system needs to wait. The second argument indicates the time measurement scale. Thus, in the above code, we have mentioned the “30” seconds as default wait time and the time unit has been set to “seconds”.

v  While execution, if WebDriver cannot find element to act upon immediately, it will wait for specified amount of time.

v  During this time, no attempt is made to find an element. After completion of specified time, WebDriver will try to find an element once. Exception is displayed if element is not found after that. So, implicit wait should be kept low.         

v  The default setting is 0.

  3. What is the difference between implicit and explicit wait.

Implicit wait :

v  Defined for the entire life of the browser

v  If not found will not attempt to find till the time specified. i.e. no polling.

Explicit wait :

v  Defined for the particular element we are looking for.

v  Polls every 500 milli seconds by default.

v  Default polling 500 milliseconds

  4. If the implicit wait is set to 30 seconds, but the element is found within 5 seconds itself so in that case will that implicit-wait  wait for entire 30 seconds before moving to the next line?

               No, it will not attempt to find until 30 seconds.

  5. Based on the above answer if they tell something about polling then we can ask how implicit wait is different than explicit wait as polling happens in both cases.

               Implicit wait polls only twice. Explicit polls every 500 milliseconds.           

  6. WebDriverWait is a class or interface?

               Class, Refer documentation

  7. How Wait, FluentWait and WebDriverWait are related?

               interface Wait<WebDriver>

               class FluentWait<T> extends Object implements Wait

               class WebDriverWait extends FluentWait

     (Wait is an interface which is implemented by FluentWait. WebDriverWait extends FluentWait)

  8. Why we had to move to Selenium Web-Driver from selenium RC. What were the limitations in RC and how WebDriver has overcome them?

v  Selenium RC's architecture is quite complex as compare to WebDriver. WebDriver controls the browser from the OS level whereas If we are using Selenium RC's we first need to launch a separate application called Selenium Remote Control (RC) Server before you can start testing.

v  If we are using WebDriver all we need is our programming language's IDE (like Eclipse, which contains your Selenium commands) and a browser.

v  Let’s understand how Selenium works: The Selenium RC Server acts as a "middleman" between Selenium commands and the browser. When we execute our test cases from our IDE, Selenium RC Server "injects" a Javascript program called Selenium Core into the browser. Once injected, Selenium Core will start receiving instructions relayed by the RC Server from your test program. When the instructions are received, Selenium Core will execute them as Javascript commands. The browser will obey the instructions of Selenium Core, and will relay its response to the RC Server. The RC Server will receive the response of the browser and then display the results to you. RC Server will fetch the next instruction from your test script to repeat the whole cycle.

v  WebDriver is much faster than Selenium RC since it speaks directly to the browser uses the browser's own engine to control it. Selenium RC is slower since it uses a Javascript program called Selenium Core. This Selenium Core is the one that directly controls the browser, not you.

v  WebDriver mimics the behavior of actual human tester. If there is field which is disabled, it is disabled for the WebDriver as well and cannot be accessed, but this is not the case with RC, disabled field can be accessed usingRC.

v  WebDriver can support the headless HtmlUnit browser. Selenium RC cannot support the headless HtmlUnit browser. It needs a real, visible browser to operate on.

9. Difference between absolute and relative XPATH. Difference between / and //.

An absolute xpath in HTML DOM starts with html e.g.

html/body/div[5]/div[2]/div/div[2]/div[2]/h2[1]

and a relative xpath finds the closed id to the DOM element and generates xpath starting from that element e.g.

.//*[@id='answers']/h2[1]/a[1]

10. Suppose I have a text field with id = 12XYZ34, where 12 and 34 are dynamic and may change but XYZ will remain same. How would you locate the element in such case?

We can find elements using the following XPATH code.

·        XPath: //input[contains(@id, 'XYZ')] For 12XYZ34

·        XPath: //input[starts-with(@id, 'XYZ')] For XYZ34

·        XPath: //input[ends-with(@id, 'XYZ')] For 12XYZ

 

 

Share This
Previous Post
Next Post

Welcome to my blog, I am Subhash Junas, I have been working on Core Java, Ruby, Selenium, Cucumber and on various automation technologies from past couple of years. I love to work on new challenges, solving problems and obstacles.

0 comments: