The main goal I try to achieve is to run the e2e tests of an angular-cli generated app on multiple browsers which currently fails because as soon as I add a second browser I get Unexpected token import errors when I run tests.
Please provide us with the following information:
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Mac OS X El Capitan (10.11.4).
- Versions. Please run
ng --version. If there's nothing outputted, please
run in a Terminal:
node --version
And paste the result here.
$ ng --version
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.5
node: 5.9.1
os: darwin x64
$ node --version
v5.9.1
- Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
- Create an app with angular-cli:
ng new testfoo- Change protractor.conf.js like this to make tests run in multiple browsers:
diff --git a/config/protractor.conf.js b/config/protractor.conf.js
index 57f4f87..76b4df8 100644
--- a/config/protractor.conf.js
+++ b/config/protractor.conf.js
@@ -6,9 +6,10 @@ exports.config = {
specs: [
'../e2e/**/*.e2e.ts'
],
- capabilities: {
- 'browserName': 'chrome'
- },
+ multiCapabilities: [
+ { 'browserName': 'chrome' },
+ { 'browserName': 'firefox' }
+ ],
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
- The log given by the failure. Normally this include a stack trace and some more information.
$ ng serve &
$ ng e2e
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
> [email protected] pree2e /Users/u1235/tmp/angularclitest/testfoo
> webdriver-manager update
selenium standalone is up to date.
chromedriver is up to date.
> [email protected] e2e /Users/u1235/tmp/angularclitest/testfoo
> protractor "config/protractor.conf.js"
[14:02:58] I/launcher - Running 2 instances of WebDriver
[14:02:59] I/testLogger -
------------------------------------
[14:02:59] I/testLogger - [chrome #01] PID: 4694
[chrome #01] Specs: /Users/u1235/tmp/angularclitest/testfoo/e2e/app.e2e.ts
[chrome #01]
[chrome #01] [14:02:58] I/direct - Using ChromeDriver directly...
[chrome #01] [14:02:59] I/runnerCli - Unexpected token import
[14:02:59] I/testLogger -
[14:02:59] E/launcher - Runner process exited unexpectedly with error code: 1
[14:02:59] I/launcher - 1 instance(s) of WebDriver still running
[14:03:00] I/testLogger -
------------------------------------
[14:03:00] I/testLogger - [firefox #11] PID: 4695
[firefox #11] Specs: /Users/u1235/tmp/angularclitest/testfoo/e2e/app.e2e.ts
[firefox #11]
[firefox #11] [14:02:58] I/direct - Using FirefoxDriver directly...
[firefox #11] [14:03:00] I/runnerCli - Unexpected token import
[14:03:00] I/testLogger -
[14:03:00] E/launcher - Runner process exited unexpectedly with error code: 1
[14:03:00] I/launcher - 0 instance(s) of WebDriver still running
[14:03:00] I/launcher - chrome #01 failed with exit code: 1
[14:03:00] I/launcher - firefox #11 failed with exit code: 1
[14:03:00] I/launcher - overall: 2 process(es) failed to complete
[14:03:00] E/launcher - Process exited with error code 100
Some end-to-end tests failed, see above.
5. Mention any other details that might be useful.
Interestingly it works if multiCapabilities is used with only one browser, no matter which.
Had the same problem, but fixed it by adding the following to protractor.conf.js
onPrepare: function () {
require('ts-node').register({
project: 'e2e'
});
}
@raymondkarstensen Thanks, that works for me.
How odd... we already have require('ts-node').register({ project: 'e2e' }); in the beforeLaunch callback, which according to https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L223-L227 should run before onPrepare. I need to investigate this further.
Actually I moved it from beforeLaunch to onPrepare.
Had the same problem, too.
After moving require('ts-node').register({ project: 'e2e' }) from beforeLaunch to onPrepare, Protractor worked fine with multiple browser finally!
Thanks @raymondkarstensen
moving from onPrepare is also worked for me. More over I am using sauce lab to test my test cases and now its able to connect to sauce lab and start testing.
@angular/cli: 1.0.0-rc.1
node: 6.9.1
os: darwin x64
onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
}
I can confirm using browserstack local + multiCapabilities i had the same issue. I turned off direct connect too from some console complaining it did.
@angular/cli 1.0.0
node: 6.9.5
El Capitan 10.11.5
Same as @raymondkarstensen, moving to the Prepare stage worked a treat. Is there a consequence to this?
It looks like this is the key reason for needing it in onPrepare when using multiCapabilities.
If multiple capabilities are being run, this will run once per capability
https://github.com/angular/protractor/blob/master/lib/config.ts#L407
beforeLaunch only runs once and only once, so I'm guessing each capability requires it's own typescript compiler.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Had the same problem, but fixed it by adding the following to protractor.conf.js
onPrepare: function () { require('ts-node').register({ project: 'e2e' }); }