I'm working on a web page that uses Knockout. I set up Protractor after seeing this post about using Protractor on non-Angular pages, but it doesn't seem like Protractor can 'see' any elements that are part of a KO component.
describe('a simple test', function () {
it('works', function () {
browser.ignoreSynchronization = true;
browser.get('profile');
expect(browser.getTitle()).toEqual('Title'); // this passes (outside KO)
expect(element(by.id('ko-component')).getText()).toEqual('Hello World!'); // this fails (inside KO)
});
});
The second assertion results in this error, even though the element is definitely in the HTML.
Message:
NoSuchElementError: No element found using locator: By.id("ko-component")
If I can't use Protractor, then suggestions for other e2e testing frameworks are welcome.
protractor
is basically a wrapper around WedDriverJS
(javascript selenium bindings). protractor
makes testing AngularJS page easier and more natural, knowing when angular is settled and a page is ready to be interacted with and introducing several angular-specific locators.
In other words, you can definitely test knockout
pages with protractor
. In this case, you need to explicitly wait until the ko-component
element is present by using presenceOf
Expected Condition:
var EC = protractor.ExpectedConditions;
var e = element(by.id('ko-component'));
browser.wait(EC.presenceOf(e), 10000);
expect(e.getText()).toEqual('Hello World!');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With