Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the wait and the page-loading handling #34

Open
helkv opened this issue Jun 22, 2018 · 1 comment
Open

Refactor the wait and the page-loading handling #34

helkv opened this issue Jun 22, 2018 · 1 comment

Comments

@helkv
Copy link

helkv commented Jun 22, 2018

When a new page is loaded and after certain actions the test-execution has to wait until all needed web-elements are present in the DOM. Sometimes a loading screen (.loaderWrapper) is displayed.

Actual Approach:

  • a globally set implicit wait time
  • many explicit waits in the page object classes to wait for single web-elements to be visible/clickable/...
  • some Thread.sleep()
  • some explicit waits in the page object classes to wait for the loading screen to disappear

Problems:

  • implicit and explicit waits should not be mixed
  • unnecessary explicit waits
    -> waits for certain elements which are not used afterwards (often used for a general approach, to check weather the new page is loaded and new actions can be executed on its elements)
  • Thread.sleep() should not be used in the tests
  • explicit waits for the loading screen only exist at certain points with long loading times
    -> no generic approach

TODO:

  • keep the explicit waits where useful and required
  • remove the implicit wait time if possible
  • replace Thread.sleep() with explicit waits (see also Replace Thread.sleep() calls with explicit waits #30)
  • use a more generic approach to handle the wait for the loading screen
    -> always wait for the loading screen if it is activated
helkv added a commit that referenced this issue Sep 4, 2018
- Intended for all selenium methods that are constantly used with the
same wrapping code
- For now contains waitForReloadOfCurrentPage- and waitForLoadOfNewPage-
method
helkv added a commit that referenced this issue Sep 5, 2018
- Add the waitForReloadOfElement method, which should be used to wait
for a partial reload of a page (if an element is reloaded because of an
ajax request).
@helkv
Copy link
Author

helkv commented Feb 14, 2019

General Waiting-Approaches proofed to be successful:

  1. Wait directly after a Selenium action for something to be loaded
    • Wait until an element is no longer attached to the DOM:
      WebElement elementToBecomeStale = driver.findelement(...);
      buttonElement.click()
      wait.until(ExpectedConditions.stalenessOf(elementToBecomeStale));
    • This can be appended by checking the loading status of the page (after the staleness-wait):
      wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
  2. Wait directly before a Selenium action for the element to be available
    • Wait until the element is visible
      wait.until(ExpectedConditions.elementToBeClickable(element));
    • Wait until the element is clickable
      wait.until(ExpectedConditions.visibilityOf(element));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant