Cannot test Angular2 quick start app in Dev Mode using protractor and webdriver-manager or --elementExplorer
I was having a problem accessing or testing the app my company is developing in Angular2 using protractor and jasmine. So I decided to get as simple as possible and go through the Angular2 quick start guide.
The following modifications were made:
In package.json
"devDependencies": { ..., "protractor": "^3.3.0", ... }
After running npm start I connected to localhost:3000 in Google Chrome, opened the Developer Tools and the Console tab and verified
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
From there, I attempted to run a simple protractor test by starting webdriver-manager udpate; webdriver-manager start and then, in a different terminal protractor conf.js. (See Angular2ProtractorTest.zip )
I received the following error:
$ protractor conf.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
F
Failures:
1) Protractor Demo App should my Angular 2 text
Message:
Failed: Error while waiting for Protractor to sync with the page: "Could not find testability for element."
Stack:
Error: Failed: Error while waiting for Protractor to sync with the page: "Could not find testability for element."
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:101:16
at Promise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
1 spec, 1 failure
Finished in 0.935 seconds
I then tried the following:
$ protractor --elementExplorer
Starting selenium standalone server...
Selenium standalone server started at http://192.168.17.125:59091/wd/hub
------- Element Explorer -------
Starting WebDriver debugger in a child process. Element Explorer is still beta, please report issues at github.com/angular/protractor
Type <tab> to see a list of locator strategies.
Use the `list` helper function to find elements by strategy:
e.g., list(by.binding('')) gets all bindings.
Starting debugger agent.
Debugger listening on port 5858
> browser.get('http://localhost:3000')
> element(by.css('my-app h1')).getText()
Error while waiting for Protractor to sync with the page: "Could not find testability for element."
>
Of course, ensuring that my selector was good, I performed the following in the Developer Tools:
> $('my-app h1')
<- <h1>My First Angular 2 App</h1>
Let me know if you need any other information.
Tests performed on MacOS 10.11.4
$ npm ls --depth=0
[email protected] /Users/jgosnell/Projects/angular2play
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
@machtyn Could you provide a sample of your angular2 app? Also did this used to work in previous versions of protractor?
See the attached file for my project files (minus the node_modules folder).
Also, I can get protractor to work on Angular 1 pages (such as the sample calculator for the Protractor demo). But I have not had it work on Angular 2 pages.
Please close this ticket as not a bug.
It was unclear to me where to put the useAllAngular2AppRoots: true option. I put that into my conf.js file and everything works as expected. (Answer was discovered on this page: http://stackoverflow.com/questions/33541103/protractor-with-angular2 )
I've tested this against protractor 3.3.0 and angular 2 beta.15 and beta.16.
conf.js file
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
useAllAngular2AppRoots: true
}