Protractor - unable to get URL title, webdriver just hangs - automation

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');
});
});

Related

ReferenceError: ReadableStream is not defined while running jest tests

My web app reads local files using a custom ReadableStream (in-order that I won't need to have a max file size that the platform supports) and it works great, both for correctly formatted files and error files. My app is built using React-Redux-Saga.
I'm now attempting to add limited e2e tests to my code to test the state management. I'm testing that when sending redux actions the state updates correctly. I'm testing the saga's using the package redux-saga-tester.
While running the jest client tests that read local files using the ReadableStream I built, I got an error ReferenceError: ReadableStream is not defined. What I understood is that the jsdom environment that jest uses is missing the ReadableStream implementation. I than added the web-streams-polyfill package to polyfill the ReadableStream class.
Now the validate file test is passing as in the browser:
test('Select and validate log file', async () => {
const testFile = testFileBuilder.valid();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_VALIDATED);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeTruthy();
});
My problem is that when I run a second validation test with an invalid file the test passes but prints an error to the console.
The test:
test('Select an invalid file - JSON error', async () => {
const testFile = testFileBuilder.errorJSON();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_ERROR);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeFalsy();
expect(state.fileError).toBeTruthy();
});
The error that is printed after the test completes successfully:
e.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
at Request.client.on.err (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20)
at Request.emit (events.js:194:15)
at Request.onRequestError (/home/noams/dev/web/visual-log-viewer/client/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19) undefined
Any subsequent file validation tests fail.
I'd appreciate any advice of how to tackle this issue.

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.

Protractor config file throws an 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.

What line is causing this Protractor error?

Is there a way for Protractor to show in the console log what line the error occurred on? I just get this type of message:
Message:
Failed: Cannot call method 'click' of undefined
Stack:
Error: Failed: Cannot call method 'click' of undefined
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
1 spec, 1 failure
It's hard to figure out if I have so many click commands. I'm running Protractor 1.8.0.
Here is my protractor.conf.js :
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://11.111.1.11:4444/wd/hub',
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions': {
args: ['--test-type']
}
}],
specs: ['./tests/my_test/*_spec.js'],
onPrepare: function(){
global.EC = protractor.ExpectedConditions;
browser.manage().window().maximize();
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
filePrefix: 'tests_xmloutput',
savePath: './test_results_report'
}));
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
The complete error message would be:
Failures:
1) test name description
Message:
Failed: Cannot call method 'click' of undefined
Stack:
Error: Failed: Cannot call method 'click' of undefined
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
1 spec, 1 failure
Finished in 3.206 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
The content of the spec file/test would be:
HeaderNavigationPartialPage.myAppButton.click();
LeftNavigationPartialPage.myAppToolsLink.ERROR-ON-PURPOSE.click();
browser.wait(EC.elementToBeClickable(LeftNavigationPartialPage.myAppSearchLink), 10000);
LeftNavigationPartialPage.myAppSearchLink.click();
Here is a related issue at jasminewd project that protractor uses under-the-hood:
Stack traces for Jasmine2 don't include asynchronous events
The issue is now fixed, with jasmine upgrade to >=2.3.1.
What you should do is to upgrade protractor to >=2.1.0.
Old answer:
As a workaround, get back to jasmine 1.x:
exports.config = {
framework: 'jasmine',
...
}