Protractor jasmine empty test spec timeout issue - jasmine

I'm receiving very strange test spec behavior when trying to run my jasmine specs with protractor.
I have two empty specs that both should pass, however my first spec passes then all proceeding specs fail. I believe this may have something to do with the version levels, as when I did an update it caused my jasmine test cases to break.
Protractor 3.3.0
Jasmine 2.4.1
Test specs
it('test spec 1', function () {
});
it('test spec 2', function () {
});
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
'use strict';
exports.config = {
seleniumAddress: 'http://127.0.0.1:4723/wd/hub',
baseUrl: 'http://10.0.2.2:' + (process.env.HTTP_PORT || '8000'),
specs: [
'./e2e-test.js'
],
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
capabilities: {
deviceName:"Samsung S7",
platformName: 'Android',
'appium-version': '1.4.16',
platformVersion:'23',
app: 'C:/Users/egreen/Desktop/Android/foo/platforms/android/build/outputs/apk/android-debug.apk',
browserName:'',
udid:'988627534e4c383848',
autoWebview: true
},
// A callback function called when tests are started
onPrepare: function () {
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
require('jasmine-reporters');
var fs = require('fs'),
d = new Date(),
date = [
d.getFullYear(),
('0' + (d.getMonth() + 1)).slice(-2),
('0' + d.getDate()).slice(-2)
].join('-'),
time = [
('0'+d.getHours()).slice(-2),
(('0'+d.getMinutes()).slice(-2)),
('0'+d.getSeconds()).slice(-2)
].join('');
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'target/reports/mobile-app/'+date+'/'+time+'/',
screenshotsFolder: 'images'
})
);
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
};
Error gist

Updated :
Try to eliminate Jasmine2HtmlReporter.
Try to add :
describe("long asynchronous specs", function() {
beforeEach(function(done) {
done();
}, 10000);
// Your code here
afterEach(function(done) {
done();
}, 10000);
}
You can also have a look into : Jasmine Asynchronous Support
Or try to add time out here :
it('test spec 1', function () {
},1000);
it('test spec 2', function () {
},1000);

Related

Onprepare with jasmine-reporters causes failures while executing with IE

After some time trying to figure out why the beginning of my tests fails (only for IE, with chrome works just fine), I found out that it is caused by the on-prepare function when comes to this part of the code:
jasmine.getEnv().addReporter({
specDone: function (result) {
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
});
If i comment this part, the tests goes smoothly.
My login page is not Angular, so I turn off the sync for the login and turn on again, not sure if this could be related.
How can I force protractor to wait for this part to finish before continuing with the run?
I already tried to add this code in a promise (in conf file) to make protractor wait but even with this i get the jasmine timeout 'TimeoutError: Wait timed out after 20000ms', so I believe I did it wrong.
The error I get is:
Failed: Unable to determine type from: E. Last 1 characters read: E
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'xxxxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.2'
Driver info: driver.version: unknown
Full conf file:
var jasmineReporters = require('./lib/node_modules/jasmine-reporters');
var HTMLReport = require('./lib/node_modules/protractor-html-reporter-2');
var mkdirp = require('./lib/node_modules/mkdirp');
var fs = require('./lib/node_modules/fs-extra');
let date = require('./lib/node_modules/date-and-time');
var environmentToExecute = 'https://myportal'
exports.config = {
seleniumAddress: 'http://'+process.env.AUTOTEST_ADDRESS+'/wd/hub',
framework: 'jasmine2',
specs: ['all my specs'],
suites: {
//All my suites
},
allScriptsTimeout: 20000,
onPrepare: function () {
{
//Here I create the folders (removed to make it shorter)
}
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './execution_results/reports/xml/',
filePrefix: 'xmlresults'
}));
jasmine.getEnv().addReporter({
specDone: function (result) {
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + result.fullName+ '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
});
}
});
},
//HTMLReport called once tests are finished
onComplete: function()
{
//I removed this to make it shorter, but basically it is the function
// that comverts the xml in html and build the report
},
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
// If true, display spec names.
isVerbose: true,
defaultTimeoutInterval: 100000
},
params: {
//Other files like functions and so on...
},
login:{
//parameters to login
}
},
multiCapabilities:
[
{
'browserName': 'internet explorer',
'version': 11,
},
/*
//chrome, firefox...
*/
],
};//end of Conf.js
Thanks!
I also had issues with asynchronous actions in a Jasmine reporter recently and unfortunately could not figure out how to get them to await promise results properly before moving on. If anyone else has information on this I would greatly appreciate it also.
I did implement a work around using global variables and the AfterAll hook which is able to correctly await promises which may work for you.
I'm assuming that you only need the 'fullname' property of your result so you can try this.
Declare a global properties in your onPrepare and you can assigned this global variable values in your reporter. Assign it the spec fullname value inside of specStarted instead of specDone. Then you can create you screenshot inside you tests afterAll statements which are correctly able to await promise results.
onPrepare: function () {
global.currentlyExecutingSpec = 'tbd';
jasmine.getEnv().addReporter({
specStarted: function (result) {
currentlyExecutingSpec = result.fullName
}
})
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './execution_results/reports/xml/',
filePrefix: 'xmlresults'
}));
}
Inside your testFiles
afterEach(function(){
browser.getCapabilities().then(function (caps)
{
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream =
fs.createWriteStream('./execution_results/reports/results/screenshots/' + browserName + '-' + currentlyExecutingSpec + '.png');
stream.write(new Buffer.from(png, 'base64'));
stream.end();
});
};
});

mocha chaijs : $ is not defined

I'm trying to setting up automated test.
I'm using zombiejs for the browser, mochaJs for the test framework and chaiJs for assertion. I want to use chai-jq for jquery assertion:
var expect = require('chai').expect
var chai = require("chai");
var chaiJq = require('chai-jq');
Browser = require('zombie'),
browser = new Browser();
chai.use(chaiJq);
describe('Test', function(){
before(function(done) {
browser.visit('http://localhost/login.php', done);
});
describe('Connexion au site', function() {
before(function(done) {
browser
.fill('login', 'foo')
.fill('password', 'bar')
.pressButton('Connexion', done);
});
it('should be successful (code 200)', function() {
browser.assert.success(200);
});
});
describe('', function() {
browser.visit('http://localhost/activites/nationales/accueil.php');
it('contain text', function() {
var $elem = $("<div id=\"hi\" foo=\"bar time\" />");
expect($elem)
// Assertion object is `$elem`
.to.have.$attr("id", "hi").and
// Assertion object is still `$elem`
.to.contain.$attr("foo", "bar");
});
});
When I run the test i've got the error ReferenceError: $ is not defined

error when running protractor with jasmine-reporters

I've installed jasmine reporters using this command:
npm install --save-dev jasmine-reporters#^2.0.0
this is the important part of the config file:
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
defaultTimeoutInterval: 360000,
includeStackTrace: true
},
framework: 'jasmine2',
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults',
filePrefix: 'xmloutput'
}));
browser.ignoreSynchronization = true;
}
when running the test, after s while I get this:
Failed: Cannot call method 'results' of undefined
Stack:
Error: Failed: Cannot call method 'results' of undefined
at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:102:16
at [object Object].promise.ControlFlow.runInFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
at [object Object].promise.Callback_.goog.defineClass.notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
at [object Object].promise.Promise.notify_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)
any ideas?
UPDATE:
after updating protractor to 2.1.0, I'm getting a little different error:
Failed: Cannot call method 'results' of undefined
Stack:
TypeError: Cannot call method 'results' of undefined
at Object.exports.takeScreenshotOnFailure (/Users/myuser/Workspace/Spark/FrontEnd/test/spec/e2e/global/screenshots.js:23:13)
at Object.<anonymous> (/Users/myuser/Workspace/Spark/FrontEnd/test/spec/e2e/CreateApp/createAppTest.js:23:16)
From: Task: Run afterEach in control flow
at Array.forEach (native)
screenshots.js:
var fs = require('fs');
var spec=jasmine.getEnv().currentSpec;
function capture(name) {
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('screenshots/' + name + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
})
}
exports.takeScreenshot = function (spec) {
capture(spec.description.split(' ').join('_'));
};
exports.takeScreenshotOnFailure = function (spec) {
if (spec.results().passed()) return;
capture(spec.description.split(' ').join('_'));
};
conf.js (relevant part):
jasmineNodeOpts: {
isVerbose: true,
showColors: true,
defaultTimeoutInterval: 360000,
includeStackTrace: true
},
framework: 'jasmine2',
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: '/TestResults',
filePrefix: 'xmloutput'
}));
browser.ignoreSynchronization = true;
}
This actually sounds closely related to What line is causing this Protractor error?, upgrade protractor to 2.1.0 or a newer version:
npm install protractor#^2.1.0
Also, since you are on jasmine2, you need to handle spec failures differently, see:
How can I get screenshots of failures?

Mocha multiple test in order

Mocha multiple test in order
I am writting test with mocha like this
describe('application', function(){
describe('First set of test', function(){
var socket;
before(function(done) {
var opts = {
'reconnection delay' : 0,
'reopen delay' : 0,
'forceNew' : true
};
socketio = io.connect(SOCKET_URL, opts);
done();
socketio.on('connect', function() {
console.log('worked...');
});
socketio.on('disconnect', function() {
console.log('disconnected...');
})
});
it('first test should be true', function(done){
expect(variable_one).to.be.false;
done();
});
it('second test should be true', function(done){
client.hget(hash, "status", function(err, result){
expect(variable_two).to.be.true;
done();
})
});
it('thrid test should be true', function(done){
client.hget(hash, "status", function(err, result){
expect(variable_three).to.be.true;
done();
})
});
});
});
What I need is that test should be nested in order, to set the before variables is not enough because the third test depends on the second and the second on the first one. With the done variable are all running in parallel.
Is there a posible way to achieve this?
Thank you

Mocha doesn't fail on assert(false)

When using mocha to test a model of a sails app, It doesn't seem to run tests inside a callback:
var assert = require('assert');
describe('Dataset', function() {
describe('create', function() {
it('should create a new dataset', function() {
Dataset.create({
'name': 'testDataSet',
'description': 'This dataset exists for testing purposes only.',
'visibility': 'private',
'data': {
"foo": {
"barn": "door",
"color": "green"
}
}
}, function(err, dataset) {
assert(false);
});
});
});
});
This test is called by a script that initializes sails for it.
when Running this test, it passes, even though it should fail.
$: mocha
1 passing (875ms)
Also it never seems to run the callback containing assert(false). Placing assert false at any other location yields the exepcted results, also sails seems to be running properly.
Any help is greatly appreciated.
Your code is asynchronous, so you should use callback in your testing function:
var assert = require('assert');
describe('Dataset', function() {
describe('create', function() {
it('should create a new dataset', function(done) {
Dataset.create({
'name': 'testDataSet',
'description': 'This dataset exists for testing purposes only.',
'visibility': 'private',
'data': {
"foo": {
"barn": "door",
"color": "green"
}
}
}, function(err, dataset) {
if (err) throw err;
done();
});
});
});
});
Add assert call wherever you need.
There are a lot of examples here.

Resources