groupon/testium

is evaluate() triggering something in the browser?

Closed this issue · 3 comments

Hi,

I'm currently writing some tests on some keyboard navigation on a webpage.
I was trying to change the following (coffeescript):

 truthy 'is visible', @browser.evaluate => # returns true
    @triggerKey(keyList.SPACE, 1)
     $('#ls-lang-list').is(':visible')

to

@browser.evaluate =>
    @triggerKey(keyList.SPACE, 1)
 @browser.waitForElementVisible('#ls-lang-list') # returns false

where @triggerKey(keyList.SPACE, 1) triggers a method that triggers a key for a certain amount of time. In my case the SPACE key opens a menu #ls-lang-list
The first code block works but the second one does not. Somehow evaluate() seems resets or trigger some event / (keystroke?) on the document.

another example:

truthy 'is visible', @browser.evaluate => # returns true
    @triggerKey(keyList.SPACE, 1)
     $('#ls-lang-list').is(':visible')

 truthy 'is visible', @browser.evaluate =>  #returns false
    $('#ls-lang-list').is(':visible')

Hi! I'm confused by the @triggerKey. The function will run in the browser, so a fat arrow won't do what you'd expect. Not sure why it's returning true though.

@aaarichter, the function you pass to browser.evaluate can have no external references; it will get marshalled, evaluated out of the file context in the browser, the response from the function will then get marshalled back to you, if it is JSON serializable, and decoded before it is passed to truthy. So, most likely, this.triggerKey() will be run with the window object as this.

closing.
Jan explained me what was wrong. thanks @jkrems