You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
Saw there was discussion about using coffeescript to write protractor tests, however, I didn't see any that involved ES6. I see the current pattern is to write tests in ES6 and have a gulp task compile them into a separate directory and then have protractor use the compiled files for testing. It would be nice to have something similar to karma-babel-preprocessor to write tests with where we don't need a gulp task.
Many ES6 features are already available in node, provided you have the right flags. What features, specifically, are you looking for? I wonder if the ideal way to do this is to wait for es6 features to hit node so that compilation can be avoided altogether.
I was looking to use classes and arrow functions, which don't seem to be stable. Since coffeescript seems to be supported out of the box, is it possible to have ES6 also be supported by using babel or traceur?
Stumbled across this issue after finding my own solution for the same thing. It seems my (somewhat basic) needs are fulfilled by adding require('babel/register'); to the prototractor configuration file. I can then use ES6 to write my tests 👍
@jamieconnolly Thanks for the tip! I totally forgot about doing it this way; this is how we used to have to do it for running coffeescript tests before it was built in.
@jamieconnolly that method allows us to use ES6 to write our tests, however if there are any errors it doesn't report the line numbers correctly. Do you know how to utilize source maps in this case?
@stringbeans I've also had the same problem. require('babel/register') generates and installs source maps by itself, but everything is done on the fly. Protractor also try to install source maps, but checking source files from disk which are not changed at all. Looks like this line overrides good source maps loaded by require('babel/register') so as a workaround I'm invoking that hook later in onPrepare function.
Hi, came here looking for solution to the proper line numbering problem. Just want to confirm that @PinkyJie method of moving babel/register to onPrepare() worked for our project, too. Thanks! :)
Can some one tell me what is wrong in my onPrepare function as I am not able to use ES6. Also getting syntax error saying can't use let or arrow functions.
onPrepare: () => {
require("babel-register");
require("babel-core/register")({presets: ["es2015"]});
let origFn = browser.driver.controlFlow().execute;
browser.driver.controlFlow().execute = function () {
let args = arguments;
origFn.call(browser.driver.controlFlow(), function () {
return protractor.promise.delayed(this.delayBrowserTimeInSeconds * 100);
});
return origFn.apply(browser.driver.controlFlow(), args);
};
browser.driver.manage().window().setSize(window.screen.availWidth, window.screen.availHeight);
browser.driver.manage().window().maximize();
}
You are reacting on a closed issue and secondly asking a question that is not related to Protractor. I don't think it's that wise to do that.
Having said that, your error suggests that you are on a version of node that is equal to 4.x. Protractor requires 6.9 at least. If you upgrade you will see this will solve your initial problem.
Secondly. Are you using babel to transpile your ES6 to ES5? If so, then your code isn;t logic,m because you are running an arrow function (ES6) to call Babel to transpile ES6 to ES5. Or am I wrong?
Activity
juliemr commentedon Apr 16, 2015
See also #1214
Many ES6 features are already available in node, provided you have the right flags. What features, specifically, are you looking for? I wonder if the ideal way to do this is to wait for es6 features to hit node so that compilation can be avoided altogether.
jonricaurte commentedon Apr 16, 2015
I was looking to use classes and arrow functions, which don't seem to be stable. Since coffeescript seems to be supported out of the box, is it possible to have ES6 also be supported by using babel or traceur?
juliemr commentedon Apr 16, 2015
I'd prefer not to build preprocessors in to the core framework - I think doing this as a gulp task makes the most sense for now.
jonricaurte commentedon Apr 17, 2015
Ok, that works for me.
jamieconnolly commentedon May 9, 2015
Stumbled across this issue after finding my own solution for the same thing. It seems my (somewhat basic) needs are fulfilled by adding
require('babel/register');to the prototractor configuration file. I can then use ES6 to write my tests 👍datatypevoid commentedon Jul 20, 2015
@jamieconnolly Your solution works perfectly for my end to end testing needs. Thanks!
jonricaurte commentedon Jul 21, 2015
@jamieconnolly Thanks for the tip! I totally forgot about doing it this way; this is how we used to have to do it for running coffeescript tests before it was built in.
stringbeans commentedon Sep 22, 2015
@jamieconnolly that method allows us to use ES6 to write our tests, however if there are any errors it doesn't report the line numbers correctly. Do you know how to utilize source maps in this case?
tsubik commentedon Oct 7, 2015
@stringbeans I've also had the same problem.
require('babel/register')generates and installs source maps by itself, but everything is done on the fly. Protractor also try to install source maps, but checking source files from disk which are not changed at all. Looks like this line overrides good source maps loaded byrequire('babel/register')so as a workaround I'm invoking that hook later inonPreparefunction.Other option could be add some config for protractor to disable loading source maps.
PinkyJie commentedon Nov 3, 2015
@tsubik Works for me, thanks!
dfguo commentedon Nov 25, 2015
@tsubik i still couldn't get proper line number after moving
require("babel/register");toonPrepare. Did you manage to get it working for you?PinkyJie commentedon Nov 26, 2015
@dfguo My full protractor.config.js is here https://github.com/PinkyJie/angular1-webpack-starter/blob/master/protractor.config.js, check this to see if it could help.
vredchenko commentedon Dec 16, 2015
Hi, came here looking for solution to the proper line numbering problem. Just want to confirm that @PinkyJie method of moving
babel/registertoonPrepare()worked for our project, too. Thanks! :)0xR commentedon Dec 17, 2015
For me putting
babel/registerin onPrepare didn't work. Running protractor 2.2.0.0xR commentedon Dec 17, 2015
As a workaround this seems to help:
require('babel/register')({retainLines: true});See https://babeljs.io/docs/usage/options/
nsteenbeek commentedon Jan 7, 2016
Since Babel 6 you have to use require("babel-core/register")({presets: ["es2015"]}) to get it working.
PeterStegnar commentedon Nov 11, 2016
require("babel/register"); Is old name.
You should use: require("babel-register");
hirunatan commentedon Dec 7, 2016
Thanks @nsteenbeek and @PeterStegnar, searched a lot of sites, but this was what i needed. Now it works!
PeterStegnar commentedon Dec 7, 2016
@hirunatan no problem, happy to help!
adityagautam commentedon Jun 21, 2017
Can some one tell me what is wrong in my onPrepare function as I am not able to use ES6. Also getting syntax error saying can't use let or arrow functions.
wswebcreation commentedon Jun 22, 2017
@adityagautam
You are reacting on a closed issue and secondly asking a question that is not related to Protractor. I don't think it's that wise to do that.
Having said that, your error suggests that you are on a version of node that is equal to 4.x. Protractor requires 6.9 at least. If you upgrade you will see this will solve your initial problem.
Secondly. Are you using babel to transpile your ES6 to ES5? If so, then your code isn;t logic,m because you are running an
arrowfunction (ES6) to call Babel to transpile ES6 to ES5. Or am I wrong?geyuqiu commentedon Jun 1, 2018
Since babel 7 it is now
after
of course :)