Waiting Strategies

 1. Explain the types of waits in selenium.

implicit wait: it sets a numeric value for the wait and it applies to the whole script. That means the script delays the given amount of waiting time.

Explicit wait: It applies only to a specific element until a specific condition is met it will wait. The time given in the wait is the maximum amount of time it waits until the condition is met.

Fluent wait: It gives more flexibility for waiting. It provides polling frequency and conditions such as ignoring errors.

2. How to add implicit wait in selenium?

  1. it waits a specified amount of time before throwing a NoSuchElementException.
driver.manage().timeouts().implicitlyWait(3, Timeunit.SECONDS);

3. How to add explicit wait?

//WebDriverWait(driver, time)
//here default unit is seconds
//time is long
WebDriverWait wait = new WebDriverWait(driver,10)
wait.until(ExpectedConditions.elementIsVisible(By.id('row'));

4. Can you provide an example of fluent wait?

  1. It provides a frequency of checking: polling interval
  2. Provide specific conditions like ignoring exceptions during the polling interval
Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30).
pollingEvery(Duration.ofSeconds(5)
.ignoring(NoSuchelementException.class);

WebElement element = wait.until(ExpectedConditions.
presenceOfElementLocated(By.id("exampleElement")));
element.click();

 5. Explain the concept of ExpectedConditions.

ExpectedConditions is a class that provides a set of predefined conditions checked during waiting time such as the element is clickable, visible etc…

6. What are the sample of expected conditions?

  1. ‌ elementToBeClickable(WebElement element or By locator)
  2.  stalenessOf(WebElement element)
  3.  visibilityOf(WebElement element)
  4.  visibilityOfElementLocated(By locator)
  5.  invisibilityOfElementLocated(By locator)
  6.  attributeContains(WebElement element, String attribute, String value
  7.  alertIsPresent()
  8.  titleContains(String title)
  9.  titleIs(String title)
  10.  textToBePresentInElementLocated(By, String)
  11.  elementSelectionStateToBe()
  12.  elementToBeSelected()
  13.  frameToBeAvaliableAndSwitchToIt() 
  14.  invisibilityOfElementWithText() 
  15.  presenceOfAllElementsLocatedBy()
  16.  presenceOfElementLocated()
  17.  textToBePresentInElement() 
  18.  textToBePresentInElementValue() 
  19.  visibilityOfAllElements()
  20.  visibilityOfAllElementsLocatedBy()

7. Difference between thread.sleep() and explicit wait()

thread. sleep() is a static wait which pauses the entire execution within the specified period.

explicit wait: it will continue the script execution as soon as the condition is met.

8. How to handle timeout in selenium?

  1. Use implicit wait
  2. WebDriverWait like explicit wait
  3. Use pageLoadTimeout
  4. Use setScriptTimeOut

9. How to deal with dynamic wait in selenium?

  1. Use explicit wait with expected conditions are met before proceeding with the next step. 
  2. So it will make sure we are waiting only the necessary time and it avoids unnecessary long waits.

10. How to handle synchronization issues?

  1. Synchronous — task is executed in an order, one after another
  2. Asynchronous — tasks are executed simultaneously
  3. To handle synchronization we can use waits
  4. Thread.sleep(2000);
  5. Implicit wait
  6. Explicit wait
  7. Fluent wait

11. How do you handle network latency?

  1. Implicit wait
  2. Explicit wait
  3. Fluent wait
  4. setPageLoadTimeout (Sets the amount of time to wait for a page load to complete before throwing an error)

12. What is pageLoadTimeout()?

  1. Maximum time allowed to load the page completely
  2. Sets the amount of time to wait for a page load to complete before throwing an error
  3. Seconds is the default unit of measurement
driver.manage().timeouts().pageLoadTimeout(Duration(10))

13. What are the diffrent types of waiting in Selenium 

Implicit wait

  • This provide default waiting time EX: 10 seconds

Explicit wait

  • This is used to halt the execution until specific conditions are met or the maximum time is elapsed

14.What does setScriptTimeout mean?

  1. When we load a website, Javascript may take some time to complete the whole page loading
  2. So we want to make sure that selenium scripts wait a considerable amount of time until asynchronous javascript finishes execution
  3. If script execution exceeds the specified time it will throw a timeout exception
  4. we can set setScriptTimeout(10, Time.SECONDS)
  5. This means asynchronous javascript needs to execute within this time frame (10 seconds)
  6. JavaScriptExecutor is the interface. 
  7. It uses the executeAsyncScript() method to execute asynchronous javascript scripts


No comments:

Post a Comment

Cucumber

What is Cucumber? Definition : Cucumber is an open-source tool that supports BDD . Purpose : Bridges the communication gap between business ...