Can I test a knockout app with Protractor?

I am working on a webpage using Knockout. I installed Protractor after watching this post about using Protractor in Angular pages , but it doesn't look like Protractor can β€œsee” any elements that are part of the 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 statement leads to this error, although the element is definitely in HTML.

 Message: NoSuchElementError: No element found using locator: By.id("ko-component") 

If I cannot use Protractor, then suggestions for other e2e testing frameworks are welcome.

+6
source share
1 answer

protractor is basically a wrapper around WedDriverJS (senenium javascript bindings). protractor simplifies and speeds up testing of an AngularJS page, knowing when angular will be installed, and the page is ready to interact with multiple angular pointers.

In other words, you can check out knockout pages with a protractor . In this case, you need to explicitly wait until the ko-component element is present when using <T26> 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!'); 
+9
source

Source: https://habr.com/ru/post/986608/


All Articles