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

waitForJavascript #34

Closed
acroix opened this issue Feb 12, 2014 · 1 comment
Closed

waitForJavascript #34

acroix opened this issue Feb 12, 2014 · 1 comment

Comments

@acroix
Copy link
Contributor

acroix commented Feb 12, 2014

Hi,

According to your commands like waitForElementVisible , I tried to do a waitForJavascript command

My problem is that I can't find a way to do the same as you (call the function back in order to check the value)

Here is what I did
This is simple test to wait for a true return after 2 seconds

Command

CommandAction.prototype.command = function(browserFunction, milliseconds, callback) {

    this.startDate = Date.now();
    this.callback = callback || function() {};
    this.browserFunction = browserFunction;
    this.milliseconds = milliseconds;

    this._check()

    return this;
}

CommandAction.prototype._check = function() {
    console.log('check')
    var self = this;

    this.client.execute(this.browserFunction, [], function(result){
        console.log('result', result)
        if( result.value === true && result.status === 0  ){
            console.log('suceeed!!!')
            self.callback(true) 
            return self.emit('complete');
        } else if( Date.now() - this.startDate < this.milliseconds ){
            console.log('looping')
            setTimeout(function() {
                self._check()
            }, 500);
        } else {
            console.log('failed!!!')
            self.callback(false)  
            return self.emit('complete');
        }
    })
}

Bash output

Running:  test javascript execution
check
result { status: 0,
  sessionId: '478c717e-a3b4-44eb-9f44-a4fab7fdb63b',
  value: false,
  state: null,
  class: 'org.openqa.selenium.remote.Response',
  hCode: 764998737 }
failed!!!
false
No assertions ran.

My client test

<body>
    <h1>Test waitForJs</h1>

    <script>

    window.value = false;
    console.log('current value', window.value);

    setTimeout(function() {
        window.value = true;
        console.log('current value', window.value);
    }, 2000);

    </script>

</body>
@acroix acroix closed this as completed Feb 13, 2014
@acroix
Copy link
Contributor Author

acroix commented Feb 13, 2014

Find a solution

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

No branches or pull requests

1 participant