Protractor - jasmine TypeError: cannot read property 'result' of undefined - jasmine

Recently i encounter an issue below, whenever i try to execute protractor tests remotely.
I receive an error message upon execution:
npm run e2e:remote
> hogs#0.1.22 e2e:remote /home/user/projects/project
> ./node_modules/protractor/bin/protractor e2e/protractor.remote.conf.js
[09:34:07] I/launcher - Running 1 instances of WebDriver
[09:34:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Jasmine started
/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120
return children && children[0].result.status;
^
TypeError: Cannot read property 'result' of undefined
at isAfterAll (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120:36)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5083:8)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5095:27)
at QueueRunner.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5191:28)
at onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4310:14)
at handleError (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4243:11)
at process.onerror (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2371:17)
at process.emit (events.js:223:5)
at process.emit (/home/user/projects/project/node_modules/protractor/node_modules/source-map-support/source-map-support.js:439:21)
at process.emit (/home/user/projects/project/node_modules/source-map-support/source-map-support.js:485:21)
Due to the above, i am unable to run tests at all at remote.
my protractor.conf.js:
require('dotenv').config();
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* #type { import("protractor").Config }
*/
exports.config = {
seleniumAddress: process.env.SELENIUM_SERVER_ADDRESS || `http://localhost:4444/wd/hub`,
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
// directConnect: true,
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 2,
},
//{
// browserName: 'firefox',
//},
],
maxSessions: -1,
baseUrl: process.env.REMOTE_URL || "",
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {},
},
onPrepare() {
process.env.USER_EMAIL = process.env.USER_EMAIL || '';
process.env.USER_PASSWORD = process.env.USER_PASSWORD || '';
require('ts-node').register({
project: 'e2e/tsconfig.json',
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
};
Tests run smoothly when i uncomment the directconnect, though in our project we are supposed to run tests through selenium grid, so it is vital that remote runs without it.
Jasmine version is 3.5.0,
Protractor is ver 5.4.3.

Related

Common tests are excluded in suite configuration of protractor

I could see the common tests are excluded in a suite configuration of protractor. Below is my config.js and there are two scenarios configured in suites.
I'm expecting the test to complete the scenario1 successfully and then Login again as part of scenario2. But, I could see the test ignores 'Login.js', 'CustomerSelection.js', 'Create.js' of Scenario2 and directly proceeds with 'ProductSelection.js'.
Any idea why is that so ? Am I missing anything in conf.js to work the way the scenarios configured ?
Config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine' ,
showColors: true,
suites : {
scenario1: [
'Login.js',
'CustomerSelection.js',
'Create.js',
'View.js',
],
scenario2: [
'Login.js',
'CustomerSelection.js',
'Create.js',
'ProductSelection.js',
]
},
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
print: function () {
},
includeStackTrace: true,
defaultTimeoutInterval: 700000
},
onPrepare: function() {
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(5000);
}
};
Below are the versions I'm using:
protractor: Version 5.4.0
Jasmine: Version 3.2.0
Node: v8.11.1
NPM: Version 5.6.0
If this tests are something that you run always before all. You can place them like this into View.js and ProductSelection.js as part of beforeAll, I'm placing login beforeAll (loginPage is page where my functions are placed, Login() is function in loginPage that logins in application if you send correct username and password to it) like this:
beforeAll(function() {
loginPage.Login(username, password);
});

Pass karma programmatically arguments

I am using karma with jasmine and the jasmine-spec-tags framework. When starting karma from CLI I use "karma start --tags=MY_TAG" to run only some tests with the tag MY_TAG. This works fine.
Now, I need to start karma programmatically. I tried the following code (note the client.args value at the end):
const server = new Server(
{
autoWatch: true,
browsers: [
'Chrome',
],
files: [
'./node_modules/babel-polyfill/dist/polyfill.js',
'./node_modules/es6-shim/es6-shim.min.js',
'./karma/karma.entry.js'
],
frameworks: ['jasmine', 'jasmine-spec-tags'],
phantomJsLauncher: {
exitOnResourceError: true
},
port: 9876,
preprocessors: {
'./karma/karma.entry.js': ['webpack', 'sourcemap']
},
reporters: ['dots'],
singleRun: false,
webpack: webpackConf,
webpackServer: {
noInfo: true
},
client:
{
args: ['--tags=SchedulingApiService']
}
});
server.start();
This does not work. Am I misunderstanding the client.args value? Would be glad about any help.
To solve this, the client part has to look like this:
client:
{
tags: 'SchedulingApiService'
}

Running multiple specs using Protractor results in a percentage of them timing out

Running multiple test specs using Protractor results in some of them timing out, giving the following error:
Jasmine spec timed out. Resetting the WebDriver Control Flow.
The failure is not consistent; not the same specs fail with each run but a percentage of the specs do and they vary from time to time. below is the config file for Protractor:
'use strict';
exports.config = {
baseUrl: 'http://www.example.com/',
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu"]
},
specs: 'specs/**/*Spec.js'
shardTestFiles: true,
maxInstances: 4
},
"scripts": {
"test": "protractor conf.js",
"test-in-parallel": "node -r parallel-protractor node_modules/.bin/protractor conf.js"
},
useAllAngular2AppRoots: true,
allScriptsTimeout: 30000,
getPageTimeout: 30000,
restartBrowserBetweenTests: true,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
browser.ignoreSynchronization = false;
}
};
Note: I have tried increasing the timeout interval for Jasmine but a percentage of the specs fail anyway (they just take a longer time to do so)

inject when used is giving errors while angular testing

My Module is :
var app = angular.module('customer',
[
'customerAPI',
'uldbfilters',
'ngRoute',
'ui.bootstrap',
'nvd3',
'chart.js',
'ui.bootstrap.datetimepicker',
'ui.dateTimeInput',
'LocalStorageModule',
'ngAnimate',
'ngMaterial'
]);
My karma config file is :
module.exports = function(config) {
config.set({
basePath: '',
frameworks: [
'jasmine',
'jasmine-matchers'
],
files: [
'../../static/bower_components/jquery/dist/jquery.js',
'../../static/bower_components/jquery-*/jquery-*.js',
'../../static/bower_components/jquery-*/**/jquery-*.js',
'../../static/bower_components/angular-charts/chart.js',
'../../static/bower_components/angular/angular.js',
'../../static/bower_components/angular-date-time-input/src/dateTimeInput.js',
'../../static/bower_components/angular-bootstrap-datetimepicker/src/js/datetimepicker.js',
'../../static/bower_components/angular-*/angular-*.js',
'../../static/bower_components/angular-*/**/*.js',
'../../static/rest/app/*.js',
'../../static/rest/app/client/**/*.js',
'test_suits_client/*.js'
],
exclude: [
'../../static/bower_components/angular-*/angular-*.min.js',
'../../static/bower_components/angular-*/**/*.min.js',
'../../static/bower_components/angular-*/**/index.js',
'../../static/bower_components/angular-*/**/gulpfile.js',
'../../static/bower_components/angular-*/**/karma.conf.js',
'../../static/bower_components/angular-*/**/Gruntfile.js',
'../../static/bower_components/angular-*/**/browserify.test.js'
],
preprocessors: {},
reporters: ['spec'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [
'Firefox'
],
singleRun: false,
concurrency: Infinity
}
My test suite is :
describe('Customer Application uldb module functionality', function() {
beforeEach(module('customer'));
var scope;
beforeEach(inject(function($rootScope){
scope = $rootScope.$new();
}));
it('Sample spec to test 2 + 2', function() {
expect(2 + 2).toEqual(4);
});
});
});
Now when i run karma, It is showing an exception of
minErr/<#/home/vhosts/uldb/static/bower_components/angular/angular.js:68:12
loadModules/<#/home/vhosts/uldb/static/bower_components/angular/angular.js:4640:15
forEach#/home/vhosts/uldb/static/bower_components/angular/angular.js:321:11
loadModules#/home/vhosts/uldb/static/bower_components/angular/angular.js:4601:5
createInjector#/home/vhosts/uldb/static/bower_components/angular/angular.js:4523:19
workFn#/home/vhosts/uldb/static/bower_components/angular-mocks/angular-mocks.js:3074:44
[3]http://localhost:9876/context.js:162:7
This problem is not regarding to $inject and it is purely based on your files loading in karma conf.js. I missed to load a library, in which current loading libraries is dependant on.

Protractor error selenium spring boot

vegan#vegan:~/hb-productupload/gateway/src/test/javascript$ gulp protractor
[15:47:24] Working directory changed to ~/hb-productupload/gateway
[15:47:51] Using gulpfile ~/hb-productupload/gateway/gulpfile.js
[15:47:51] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:47841
at ClientRequest.<anonymous> (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174:16)
at emitOne (events.js:90:13)
at ClientRequest.emit (events.js:182:7)
at Socket.socketErrorListener (_http_client.js:306:9)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at emitErrorNT (net.js:1265:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
at Function.webdriver.WebDriver.createSession (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
at new Driver (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/chrome.js:810:36)
at [object Object].DirectDriverProvider.getNewDriver (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/driverProviders/direct.js:68:16)
at [object Object].Runner.createBrowser (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:186:37)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:276:21
at _fulfilled (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:759:13)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1
[15:47:59] gulp-notify: [JHipster Gulp Build] Error: protractor exited with code 1
[15:47:59] Finished 'protractor' after 7.34 s
[15:47:59] E2E Tests failed
I am trying to run a simple
i updated chrme driver.
Then i made
npm install
bower install
gulp install
but did not work when i run
gulp protractor
I run with gulp for project but also i downloaded to my ubuntu and i can run as local. But same error for that local happens when i run
protractor protractor.conf.js
Ysterday i could run both, i made upgrade. now i cant work both.
this is conf file
var HtmlScreenshotReporter = require("protractor-jasmine2-screenshot-reporter");
var JasmineReporters = require('jasmine-reporters');
var prefix = 'src/test/javascript/'.replace(/[^/]+/g, '..');
exports.config = {
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
suites: {
login: './e2e/account/login/*.js'
},
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
onPrepare: function () {
// Disable animations so e2e tests run more quickly
var disableNgAnimate = function () {
angular
.module('disableNgAnimate', [])
.run(
[
'$animate',
function ($animate) {
$animate.enabled(false);
}
]
);
};
var disableCssAnimate = function () {
angular
.module('disableCssAnimate', [])
.run(
function () {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = 'body * {' +
'-webkit-transition: none !important;' +
'-moz-transition: none !important;' +
'-o-transition: none !important;' +
'-ms-transition: none !important;' +
'transition: none !important;' +
'}';
document.getElementsByTagName('head')[0].appendChild(style);
}
);
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
browser.addMockModule('disableCssAnimate', disableCssAnimate);
browser.driver.manage().window().setSize(1600, 1280);
}
};
this is in protractor config
{
"webdriverVersions": {
"selenium": "2.51.0",
"chromedriver": "2.25",
"iedriver": "2.51.0"
}
}
it was not 2.25 i updated but still same.
I changed chrome driver and selenium driver to latest and it worked.

Resources