Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Issue with ExpectedConditions working with forked browser instances #3761

Closed
bitliner opened this issue Nov 22, 2016 · 8 comments · Fixed by #3766
Closed

Issue with ExpectedConditions working with forked browser instances #3761

bitliner opened this issue Nov 22, 2016 · 8 comments · Fixed by #3766

Comments

@bitliner
Copy link

bitliner commented Nov 22, 2016

Bug report

  • Node Version: v6.9.1
  • Protractor Version: 4.0.11
  • Angular Version: 1.5.6
  • Browser(s): chrome
  • Operating System and Version mac osx

Code of my test is as following:


beforeAll(function(){
  browser2=browser.forkNewDriverInstance();
  return user.login(browser2);
});

beforeEach(function(){
  return browser2.get('/other-page');
});

and user.login() is:

User.prototype.login=function(browserToUse){
  browser.runLogin()
    .then(function(){
      return browserToUse.wait(EC.urlContains('/home'), 5000*2,'Waiting ofr URL /home');
    });
}

It looks like that it executes instructions in the wrong order, that is:

  1. user.login(b)
  2. browser2.get('/other-page')
  3. browserToUse.wait(EC.urlContains('/home'), 5000*2,'Waiting ofr URL /home');

indeed, the 3rd instruction generates a time out exception. But the browser goes through /home URL, it is a problem of synchronization.

I wonder: how is it possible?

Which is the way to tell protractor: don't use your algorithm for ordering instructions, but I manage the order?

I am using .then() for each instruction, but it does not seem enough.

It is worth to note that:

  • this test (that includes the beforeAll) have other tests (describe and it) and that before it
  • when i run this test by itself, it does not go in timeout
  • when i run the whole file, it goes in timeout
@cnishina
Copy link
Member

cnishina commented Nov 22, 2016

beforeAll is the first to execute then beforeEach and not the other way around.

update:
(removing image because it does not answer the question and makes the issue much longer than needed)

This looks like a support question. Please ask your support questions on StackOverflow, Google Group discussion list, or Gitter. For more information please reference https://github.com/angular/protractor/blob/master/CONTRIBUTING.md#questions

Thank you!

@bitliner
Copy link
Author

bitliner commented Nov 22, 2016

@cnishina your example is wrong, you don't have promises in the beforeAll and beforeEach.

My example include them.

@bitliner
Copy link
Author

@cnishina cnishina reopened this Nov 22, 2016
@cnishina
Copy link
Member

Sorry about the initial close...I misread the issue. Alright I think I have an idea why this is breaking. I think the actual question / issue is "Does EC work on forked browser". Reviewing the EC code I believe it does not.

Could you use the initial browser object (without forking it)? My guess is that this does works. If it works on browser but not the forked browser, this is definitely a limitation on EC and should be fixed.

@cnishina
Copy link
Member

cnishina commented Nov 22, 2016

This works:

  it('should work with EC', () => {
    let title = 'My AngularJS App';
    let EC = protractor.ExpectedConditions;
    browser.get('http://www.protractortest.org/testapp/ng1/#/form');
    browser.wait(EC.titleIs('My AngularJS App'), 1000);
    browser.get('http://www.protractortest.org/testapp/ng1/#/async');
  });

This does not work: (update fix variablesbrowser2)

  it('should work with EC from a forked instance', () => {
    let browser2 = browser.forkBrowserInstance();
    let title = 'My AngularJS App';
    let EC = protractor.ExpectedConditions;
    browser2.get('http://www.protractortest.org/testapp/ng1/#/form');
    browser2.wait(EC.titleIs('My AngularJS App'), 1000);
    browser2.get('http://www.protractortest.org/testapp/ng1/#/async');
  });

Just some extra notes to self. ProtractorBrowser creates a static ExpectedConditions. ExpectedConditions uses (<Ptor>global.protractor).browser when referencing the browser. My initial thoughts are:

  • ExpectedConditions should not be static

  • a reference to the browser instance should be passed to a new ExpectedConditions in the ProtractorBrowser constructor

  • Using a forked instance of browser should get the EC with:

    let browser2 = browser.forkBrowserInstance();
    let EC = browser2.ExpectedConditions;
    browser2.wait(EC.titleIs('foobar'), 5000);
    

@cnishina
Copy link
Member

Confirmed. Will have a PR to fix this.

@bitliner
Copy link
Author

Thank you very much for your help.

Just a note: in your example, that does not work, the wait should be on browser2 in order to make it more similar to my example (of course a fix to make browser to work too is required).

@cnishina
Copy link
Member

@bitliner yup, I sort of modified the example above it and did a quick copy / paste / edit. I just updated the comment to reflect browser2 and not browser

@cnishina cnishina changed the title Protractor does not wait and synchronize well beforeAll and beforeEach Issue with ExpectedConditions working with forked browser instances Nov 22, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Nov 22, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Nov 26, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Nov 28, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Nov 30, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Dec 1, 2016
- Update sauce lab binary to run on travis.
- Disable expected conditions test that forks the browser. This issue appears to
  not be specific to sauce labs. Also can reproduce this with a local driver
  provider. Additional work is required around driver providers and the runner.
- Add TODO to enable test in the future when this is resolved.

closes angular#3761
cnishina added a commit that referenced this issue Dec 1, 2016
…3766)

- Update sauce lab binary to run on travis.
- Disable expected conditions test that forks the browser. This issue appears to
  not be specific to sauce labs. Also can reproduce this with a local driver
  provider. Additional work is required around driver providers and the runner.
- Add TODO to enable test in the future when this is resolved.

closes #3761
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants