Giter Site home page Giter Site logo

Comments (4)

johnjelinek avatar johnjelinek commented on May 6, 2024

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?

from protractor.

johnjelinek avatar johnjelinek commented on May 6, 2024

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);
});

from protractor.

juliemr avatar juliemr commented on May 6, 2024

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).

from protractor.

juliemr avatar juliemr commented on May 6, 2024

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

from protractor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.