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

"angular could not be found on the window" error when running against a CEF client unless browser.get() is called #1992

Closed
ni-tterry opened this issue Mar 31, 2015 · 5 comments

Comments

@ni-tterry
Copy link

Hello! I am researching Protractor for testing a CEF client that runs Angular.

The client launches as expected when running protractor, but stops immediately because "angular could not be found on the window".

If I add a browser.get('http://url/to/test-server') call to my spec, the spec passes. However, this is not an expected user behavior (because the app just points to one site and the user can't open a new location) and I don't want it at the beginning of all of my tests!

Adding another browser call, like browser.wait(), does not make this work correctly.

Is there another way that I can wait for Angular to wake up inside my client without first performing some action that none of our users will be able to perform?

FWIW, I am currently using chromedriver and the python bindings for selenium to drive this client very successfully without a needing to call browser/driver.get().

Thanks for any help anyone can offer!

Here's a code snippet, with some path and server details obfuscated:

// conf.js
exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
      binary: '/path/to/cefclient',
      args: ['serverurl=http://url/to/test-server']
    }
  },
  specs: ['spec.js'],
}
// spec.js
describe('My cefclient', function() {
  beforeEach(function() {
    browser.wait(function() {
      return $('#Username').isPresent();
    }) // This wait() doesn't help me
    browser.get('http://url/to/test-server') // This get() helps me, but I'd prefer not to use it.
  });
  it('should have a title', function() {
    expect(browser.getTitle()).toEqual('Expected Page Title');
  });
});
@juliemr
Copy link
Member

juliemr commented Mar 31, 2015

You need some other way of waiting until not only the element is present, but Angular is loaded on the page. I don't know if there's a user-visible way to see if the page is still loading (like waiting until a spinner element is absent?) If that doesn't work, you could just manually wait until angular is present:

browser.wait(function() {
  return browser.executeScript('return !!window.angular');
});

Closing this as a question, not a general issue.

@ni-tterry
Copy link
Author

Thanks for getting back to me so quickly, and sorry for asking a general question here. I couldn't find any help elsewhere!

I am trying the wait you suggested, but it times out awfully quickly:

Error: Wait timed out after 157ms

We do load an offline page first that fetches the angular app from the server, so I've tried waiting for an element there to disappear but can't make that succeed (possibly due to operator error).

Your help is much appreciated! I think I need to do some more reading and experimenting.

@juliemr
Copy link
Member

juliemr commented Mar 31, 2015

Oh sorry, you can add a timeout:

browser.wait(function() {
  return browser.executeScript('return !!window.angular');
}, 5000); // 5000 is the timeout in millis

@ni-tterry
Copy link
Author

Ah, great! That's much better! Much obliged!

@usumoio
Copy link

usumoio commented Sep 10, 2015

@juliemr The timeout function you showed here worked perfectly for me. Thank you.

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

3 participants