0

I'm learning GEB in IntelliJ and have two issues.

  1. When I click button on the top of the page I'm redirected to very bottom of the page. After this I need to do assertion that the site slided down.

    I try to do assertion in this example:

    assert page.element_on_the bottom.isDisplayed() == true
    
    // element_on_the bottom {$('css_selector)
    

    The above assertion always returns true even I don't click button to slide down. I need to check if element is visible on the part of website which is actually displayed on my monitor screen. Is there a way to do this?

  2. I try to use waitFor statement in example:

    waitFor{page.element.isDisplayed()}
    

    but it doesn't work:

    geb.waiting.WaitTimeoutException: condition did not pass in 5.0 seconds (failed with exception)

    instead of this I use:

    Thread.sleep(3000) //which is not desirable here 
    

    and then my test passes. I think my element don't trigger any js or ajax script actions. I'm not sure how to use waitFor that should wait for all elements to load.

mskfisher
  • 3,291
  • 4
  • 35
  • 48
larry
  • 1
  • 1
  • 2

2 Answers2

1

Element doesn't have to be in view for is isDisplayed() to return true - it will return true as long as the element is visible on page, e.g. it's display property is not set to hidden. You will need to detect your scroll position using javascript because WebDriver does not expose scroll information. See this response for how to detect that scroll is at the bottom of the page and see this section of the Book of Geb for how to execute javascript code in the browser.

What is the exception and its stacktrace that you're getting from your waitFor {} call? It probably contains the clue on what is actually going on.

Community
  • 1
  • 1
erdi
  • 6,944
  • 18
  • 28
0

For your first problem, can you please try the following as displayed should work fine for the visibility and present should be good to check the presence of the css selector in the DOM:

waitFor { page.element_on_the bottom.isDisplayed() }

or

waitFor { page.element_on_the bottom.displayed() }

For the second problem, you need to edit your Gebconfig file, like below as the waiting time you have right now is 5 seconds that's why it's failing whereas your sleep time is way more than 5 seconds:

waiting {
    timeout = 30
    retryInterval = 0.1
}

or, you can also try that at the same line of the code as below:

waitFor (30, 0.1) {page.element.isDisplayed()}

Please let us know if that worked fine or not! On another note, why don't you simply write the function name from the imported class instead of always writing className.functionName()? Best of luck and Cheers!!

Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51