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

Explicit Wait functionality? #53

Closed
johnjelinek opened this issue Aug 23, 2013 · 4 comments
Closed

Explicit Wait functionality? #53

johnjelinek opened this issue Aug 23, 2013 · 4 comments

Comments

@johnjelinek
Copy link

"An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code." http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits

Is it possible to do something like ptor.until(mycondition_to_continue_testing)?

@johnjelinek
Copy link
Author

Here's a little example, I think this test sucks:

it('should send and receive a message', function () {
  var input = ptor.findElement(protractor.By.input('newMessage'));
  var button = ptor.findElement(protractor.By.css('[ng-click="publish()"]'));
  var newMessageReceived = false;

  ptor.wait(function () {
    input.sendKeys('testing');
    button.click();

    ptor.findElements(
      protractor.By.repeater('message in messages').column('{{message}}'))
      .then(function (msgs) {
        msgs[0].getText().then(function (text) { // new messages are unshifted
          if (text === 'Waiting_Room -> testing') {
            newMessageReceived = true;
          }                
        });                
      });                  

    if (newMessageReceived) {       
      expect(newMessageReceived).toBe(true);
      return true;
    }
  }, 5000);
});

From what I can tell, the scenario is that on page load, there is a slight amount of time needed to make a connection to the pubsub server, but the test is already firing off messages (which don't get sent yet). I am waiting for responses come back from the server, but have noticed that they don't come through until about the 4th button.click(). Do you know a better way to do a test like this?

@johnjelinek
Copy link
Author

I confirmed that the problem is because the connection to the pubsub server doesn't finish initializing until about a second after page load. This test might be slightly better, please let me know if this is more appropriate or if there's a better way for protractor to handle this scenario.

it('should send and receive a message', function () {
  var input = ptor.findElement(protractor.By.input('newMessage'));
  var button = ptor.findElement(protractor.By.css('[ng-click="publish()"]'));

  waits(2000);
  setTimeout(function () {
    input.sendKeys('testing');
    button.click();

    setTimeout(function () {
      ptor.findElements(
        protractor.By.repeater('message in messages').column('{{message}}'))
        .then(function (msgs) {
          msgs[0].getText().then(function (text) { // new message is unshifted
            expect(text).toBe('Waiting_Room -> testing');
          });
        });
    }, 300);
  }, 1000);
});

@juliemr
Copy link
Member

juliemr commented Aug 27, 2013

Is there a way to tell if the pubsub is up and running more easily than clicking something and seeing what happens? You can use ptor.wait with any function, so if you do have mycondition_to_continue_testing_fn(), you can do:

ptor.wait(mycondition_to_continue_testing_fn());

var input = ptor.findElement(...)

Maybe there is a variable that gets initiated in the browser or somthing? Could you test for the pubsub with ptor.executeScript()? See https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#375 for the docs on that.

Otherwise, using ptor.sleep(2000) is preferable to using waits(2000).

@juliemr
Copy link
Member

juliemr commented Sep 12, 2013

Closing as there seem to be no further questions - please reopen if something else comes up.

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

2 participants