Protractor config file throws an error - syntax-error

I was running the same spec-test.js and config.js yesterday and it was working fine.
Today I tried and got the below error, This is happening on 2 out 3 machines:
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/FOLDERPATH/specs/spec-test.js:2:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
[launcher] Process exited with error code 100
I am using protractor 3.2.2, node 4.4.3
Any idea why the tests aren't executing.
PS: please ignore any file names mismatch/typos, since I have modified my code a little to ask on the forum. I have tried to run the below code but seeing the same error.
config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['specs/spec-test.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
debuggerAddress: '127.0.0.1:9000'
}
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 700000,
isVerbose: true
}
};
spec-test.js
var fs = require('fs');
var panel = require('../pageObjects/file1.js');
var panelHelper = require('../pageObjects/file2.js');
var panelApp = require('../pageObjects/file3.js');
describe("Just print Hello world", function() {
it('test 1', function() {
console.log("Hello World!");
});
});

You must have a syntax error in one of those require pageObject files, like a missing comma or something. I can't see anything wrong in your config. Also the fact that it starts the webDriver instance means it is getting past onPrepare and starting the spec, so it's not your config file.
It would throw a different error if you had an issue in your config i.e. ERROR - failed loading configuration file config/local.conf.js. I would carefully look through those pageObject files for syntax errors.

Related

Protractor - unable to get URL title, webdriver just hangs

just start messing around with Protractor for an upcoming project that may require front-end automation on an angular based website. After installing Protractor and running the given examples, tried to do a very simple test, like the following:
// test.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://www.google.co.uk');
expect(browser.getTitle()).toEqual('Google');
});
});
Problem is, the browser opens but then it just hangs until it closes with an error:
Failures:
1) Protractor Demo App should have a title
Message:
Failed: Cannot read property 'ver' of null
Stack:
TypeError: Cannot read property 'ver' of null
at executeAsyncScript_.then (/usr/local/lib/node_modules/protractor/built/browser.js:716:56)
at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:668:7
at process.internalTickCallback (internal/process/next_tick.js:77:7)
From: Task: Run it("should have a title") in control flow
at UserContext.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19)
From asynchronous test:
Error
at Suite.<anonymous> (/Users/rubensantos/Documents/protractor/test.js:3:5)
at Object.<anonymous> (/Users/rubensantos/Documents/protractor/test.js:2:1)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
1 spec, 1 failure
Finished in 4.056 seconds
[11:18:25] I/launcher - 0 instance(s) of WebDriver still running
[11:18:25] I/launcher - chrome #01 failed 1 test(s)
[11:18:25] I/launcher - overall: 1 failed spec(s)
[11:18:25] E/launcher - Process exited with error code 1
have no idea why this simple test does not work. Any help is welcome, thanks in advance
It would be a great decision to disable Control Flow due to this thread . In your protractor.conf.js file add SELENIUM_PROMISE_MANAGER: false line. After it you should resolve Promises by yourself. For example your test will look like:
describe('Protractor Demo App', function() {
it('should have a title', async function() {
await browser.get('http://www.google.co.uk');
expect(await browser.getTitle()).toEqual('Google');
});
});

Webpack migration 3 -> 4: Error: Cannot find module 'webpack/lib/optimize/CommonsChunkPlugin'

I'm trying to migrate from webpack 3 to webpack 4.
The issue I have is with CommonsChunkPlugin, when I try to run webpack (npm run webpack-dev-server -- --config config/webpack.dev.js), I have the following error:
module.js:529
throw err;
^
Error: Cannot find module 'webpack/lib/optimize/CommonsChunkPlugin'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/antoinepissot/DEV/Reports/config/webpack.common.js:17:28)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
What is causing this issue ?
I looked at the change log on webpack github and found that CommonsChunkPlugin has been removed
But when I look at the webpack documentation, I can find CommonsChunkPlugin for version 4.1.1
My gut feeling is telling me that CommonsChunkPlugin is deprecated and we should use optimization.splitChunks.
Did anyone experienced the issue and found a good tutorial to migrate from version 3 to 4 ?
As Vardius pointed out in his comment, CommonsChunkPlugin was removed.
In webpack 4, this behaviour is done using "optimization" field at the root of webpack config.
For instance, this is how my webpack.config.js looks like now:
module.exports = function () {
return {
resolve: ...
module: ...
plugins: ...
optimization: {
namedModules: true, // old NamedModulesPlugin()
splitChunks: { // old CommonsChunkPlugin
chunks: "all"
},
runtimeChunk: true,
concatenateModules: true // old ModuleConcatenationPlugin
}
}

Reference error By is not defined

I try to access a class using selenium and the keyword by , and the following error occurs :
ReferenceError: By is not defined
at Object.<anonymous> (C:\selenium\hello_world.js:11:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
The program is very simple
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
var client = webdriverio.remote(options);
client
.init()
.url('https://mail.google.com')
.findElement(By.className("TnvOCe k6Zj8d XraQ3b")).click()
.end();
You are using webdriverio, not Selenium. Code should be as follow.
client
.init()
.url('https://mail.google.com')
.click('.TnvOCe.k6Zj8d.XraQ3b')
.end();
You can find webdriverio API here.

Implement cucmber with protracor test

I have tried to implement very simple cucumber with protractor example ,but get errors in feature file ,Here is my code
i'm useing node version v6.10.2 , protractor version Version 5.1.1 and cucumber version 2.4.0
protractor.conf.js file
var prefix = 'src/test/javascript/'.replace(/[^/]+/g,'..');
exports.config = {
seleniumServerJar: prefix + 'node_modules/protractor/selenium/selenium-server-standalone-2.52.0.jar',
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
frameworkPath: require.resolve('protractor-cucumber-framework'),
directConnect: true,
baseUrl: 'http://localhost:8099/',
cucumberOpts: {
require: 'step_definitions/stepDefinitions.js',
format: 'summary'
},
specs: [
'features/*.feature'
]
};
the feature file that get error
Feature: Running Protractor and Cucumber
Scenario: Protractor and Cucumber Test
Given I go to home page
the stepDefinition js file
module.exports = function() {
this.Given(/^I go to home page$/, function(site, callback) {
browser.get(site)
.then(callback);
});
}
but when i going to run by $ gulp protractor I get the following error
[16:01:21] Using gulpfile ~/git/adap_gateway/gulpfile.js
[16:01:21] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
[launcher] Error: /home/ali/git/adap_gateway/src/test/javascript/features
/attack.feature:1
(function (exports, require, module, __filename, __dirname) { Feature:
Running Protractor and Cucumber
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /home/ali/git/adap_gateway/node_modules/jasmine/lib/jasmine.js:71:5
[launcher] Process exited with error code 100
[16:01:21] gulp-notify: [JHipster Gulp Build] Error: protractor exited
with code 100
[16:01:22] Finished 'protractor' after 936 ms
[16:01:22] E2E Tests failed
Can anyone please help me to fix the error?
Maybe you could try to set the framework property as 'custom' instead of requiring cucumber-protractor-framework.
I'm using the same stack and this is my configuration:
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
Hope this will help you.

Cucumber with Protractor

I'm trying to make very simple cucumber with protractor example ,but get errors in feature file ,Here is my code
protractor.conf.js file
var prefix = 'src/test/javascript/'.replace(/[^/]+/g,'..');
exports.config = {
seleniumServerJar: prefix + 'node_modules/protractor/selenium/selenium-server-standalone-2.52.0.jar',
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
frameworkPath: require.resolve('protractor-cucumber-framework'),
directConnect: true,
baseUrl: 'http://localhost:8099/',
cucumberOpts: {
require: 'step_definitions/stepDefinitions.js',
format: 'summary'
},
specs: [
'features/*.feature'
]
};
feature file
Feature: Running Protractor and Cucumber
Scenario: Protractor and Cucumber Test
Given I go to home page
stepDefinition js file
module.exports = function() {
this.Given(/^I go to home page$/, function(site, callback) {
browser.get(site)
.then(callback);
});
}
but when i going to run by $ gulp protractor I get the following error
[16:01:21] Using gulpfile ~/git/adap_gateway/gulpfile.js
[16:01:21] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
[launcher] Error: /home/ali/git/adap_gateway/src/test/javascript/features
/attack.feature:1
(function (exports, require, module, __filename, __dirname) { Feature:
Running Protractor and Cucumber
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /home/ali/git/adap_gateway/node_modules/jasmine/lib/jasmine.js:71:5
[launcher] Process exited with error code 100
[16:01:21] gulp-notify: [JHipster Gulp Build] Error: protractor exited
with code 100
[16:01:22] Finished 'protractor' after 936 ms
[16:01:22] E2E Tests failed
Can anyone please help me to fix the error?
You need to set the framework to custom as shown here. It defaults to jasmine which is what is trying to execute that feature file.