Jasmine HTML2 Reporter - jasmine

I have been using Jasmine2-HTML-Reporter and it's been fine. Produces a multi-spec report with screenshots - just as I need.
However, something seems to have gone awry! Now I will only get a report for the first Spec and nothing for any other spec. Also, the system used to delete the previous report/screenshot but now this has to be done manually.
I really cannot think what's changed in the rest of the package to cause this!!
Here's the entry in the conf.js files...identical for each conf file. I've tried adding the various switches - no effect at all!
Thanks
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
//seleniumAddress: 'http://localhost:444/wd/hub',
params: require ('Models/Baths.js'),
directConnect: true,
capabilities: {
cssSelectorsEnabled: true,
'browserName': 'chrome',
specs:['Specs/001-First.js',
'Specs/003-Exp.js'
],
allScriptsTimeout: 120000,
getPageTimetout: 30000,
framework: 'jasmine2',
showColors: true,
isVerbose: true,
onPrepare: function() {
Jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
takeScreenshots: true,
savePath: './Reports',
fileName: 'B&Q'
})
);
var SpecReporter = require ( 'jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter( new SpecReporter( {
displayStacktrace: true,
displayFailureSummary: true,
displayPendingSummary: true,
displaySuccessfulSpec: true,
displayFailedSpec: true,
displaySpecDuration: true,
displaySuiteNumber: false,
colors: {
success: 'green',
failure: 'red',
pending: 'yellow'
},
customProcessors: []
} ));
}
}
};

Try with below conf file, it should work for you.
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var log4js = require('log4js');
var params = process.argv;
var args = process.argv.slice(3);
exports.config = {
//seleniumServerJar: './node_modules/gulp-protractor/node_modules/protractor/selenium/selenium-server-standalone-2.48.2.jar',
seleniumAddress: 'http://localhost:4444/wd/hub',
allScriptsTimeout: 100000,
framework: 'jasmine2',
onPrepare: function () {
browser.manage().timeouts().implicitlyWait(11000);
var width = 768;
var height = 1366;
browser.driver.manage().window().setSize(768, 1366);
browser.ignoreSynchronization = false;
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: __dirname+'/qualityreports/testresults/e2e',
takeScreenshots: false,
filePrefix: 'automationReport',
consolidate: true,
cleanDestination: false,
consolidateAll: true
})
);
},
suites:{
example:['./test/e2e/specs/**/*Spec.js',]
},
capabilities: {
'browserName': 'chrome'
},
resultJsonOutputFile:'./results.json',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 100000
}
};

Related

how to utilize process.stdout.write instead of console.log in winston?

I am using winston library to log nodeJS application.
I would love to utilize process.stdout.write instead of console.log. I noticed that the problems with the output formatting in the AWS Lambda docker images only occur with console.log.
Is there a transport for Winston that exists that can utilize process.stdout.write instead of console.log?
If not, is there an alternative to this without overwriting console transport?
here is my current code sample :
const winston = require('winston');
const appRoot = require('app-root-path');
const options = {
file: {
level: 'info',
filename: `${appRoot}/logs/app.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
},
};
const logger = new winston.Logger({
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console),
],
exitOnError: false,
});
logger.stream = {
write: (message: string) => logger.info(message),
};
module.exports = logger;

Download file to given absolute path in Firefox using Protractor

Im using Protractor for E2E testing. During automation, I need to download files to C:\Automation folder in my system. But below code is not working.
Note:During automation execution,The Save as popup opens(but i have to disable that in future) and I manually click "Save" option. It saves in default location ie Downloads folder.How do I make it save in my given path.
let profile = require('firefox-profile');
let firefoxProfile = new profile();
//_browser = 'chrome';
_browser = 'firefox';
// _browser = 'internet explorer';
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference('browser.download.dir', "C:\\Automation");
exports.config = {
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': _browser,
'shardTestFiles': false,
'maxInstances': 1,
'acceptInsecureCerts': true,
'moz:firefoxOptions': {
'profile': firefoxProfile
}},
beforeLaunch: function () {...}
}
It looks like you may just be missing a couple of preferences for it to work with firefox. Try adding these and see if that helps.
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference( "browser.helperApps.neverAsk.saveToDisk",
/* A comma-separated list of MIME types to save to disk without asking goes here */ );
this will save to downloads folder inside your project. You can try to tweak it to save to desired folder. You have to specify which types of files are suppose to be downloaded without prompt. JSON and csv are already there.
var q = require('q');
var path = require('path');
var sh = require("shelljs");
var cwd = sh.pwd().toString();
var FirefoxProfile = require('selenium-webdriver/firefox').Profile;
var makeFirefoxProfile = function(preferenceMap) {
var profile = new FirefoxProfile();
for (var key in preferenceMap) {
profile.setPreference(key, preferenceMap[key]);
}
return q.resolve({
browserName: 'firefox',
marionette: true,
firefox_profile: profile
});
};
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
getMultiCapabilities: function() {
return q.all([
makeFirefoxProfile(
{
'browser.download.folderList': 2,
'browser.download.dir': (path.join(cwd, 'downloads')).toString(),
'browser.download.manager.showWhenStarting': false,
'browser.helperApps.alwaysAsk.force': false,
'browser.download.manager.useWindow': false,
'browser.helperApps.neverAsk.saveToDisk': 'application/octet-stream, application/json, text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext, text/plaintext'
}
)
]);
},
allScriptsTimeout: 1000000,
specs: ['./tmp/**/*.spec.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 1000000,
showColors: true
},
onPrepare: function() {
browser.driver.getCapabilities().then(function(caps) {
browser.browserName = caps.get('browserName');
});
setTimeout(function() {
browser.driver.executeScript(function() {
return {
width: window.screen.availWidth,
height: window.screen.availHeight
};
}).then(function(result) {
browser.driver.manage().window().setPosition(0,0);
browser.driver.manage().window().setSize(result.width, result.height);
});
});
}
};

Protractor beforeAll() not running

I was trying to run a test that had worked the day before and got an error message saying
- Error: Error while waiting for Protractor to sync with the page: "window.angular is undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
I added a console.log("hi") in one of my beforeAll() calls and there was no output in the console, so I suspect the error is that beforeAll() is not invoked for some reason.
I'm using the latest jasmine framework in my conf file and some of my tests run when I don't include the beforeAll(), but not all of them. This test was working fine yesterday and I ran it again today without any changes, so I'm not sure what the problem might be. Does anyone else know?
I'll include my conf.js file and part of the test I'm running.
My conf.js file
let SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
framework: 'jasmine',
directConnect: true,
allScriptsTimeout: 50000,
rootElement: 'html',
untrackOutstandingTimeouts: true,
// suites: {
//HealthCheck: './specs/Health Check/**.js',
//ContectCheck: './specs/Content Check/**.js',
// },
specs: [
// 'specs/submitFeedback.js',
'specs/createTeacherAndStudentOld.js',
// 'specs/temp.js',
// 'specs/manipTeste.js',
],
capabilities: {
browserName: 'chrome'
},
params: {
screenWidth: 1920,
screenHeight: 1080,
siteURL: 'https://alpha.khmath.com',
marketingSiteURL: 'https://knowledgehook.com',
portalUsername: '',
portalPassword: '',
classRedemptionCode: 'testcode1',
contentCheckCourse: 'Grade 9 Academic',
homeWorkCourse: 'Grade 9 Applied',
gameShowCourse: 'Grade 9 Applied',
term: '2016-2017 Full Year',
gameShowSiteUrl: 'https://alpha.khmath.com/play'
},
jasmineNodeOpts: {
defaultTimeoutInterval: 7200000,
print: function() {}
},
onPrepare: function () {
global.helper = require('./helper.js');
global.completeQuestionHelper = require('./pages/student/completeQuestionHelper.js');
global.fs = require('fs');
global.https = require('https');
global.LoginPage = require('./pages/loginPage.js');
global.RegistrationPage = require('./pages/registrationPage.js');
global.TeacherGameShowPage = require('./pages/teacher/teacherGameShowPage.js');
global.TeacherHomePage = require('./pages/teacher/teacherHomePage.js');
global.TeacherMissionPage = require('./pages/teacher/teacherMissionPage.js');
global.TeacherPurchasePage = require('./pages/teacher/teacherPurchasePage.js');
global.TeacherStudentsPage = require('./pages/teacher/teacherStudentsPage.js');
global.TeacherStudentSummaryPage = require('./pages/teacher/teacherStudentSummaryPage.js');
global.TeacherReportPage = require('./pages/teacher/teacherReportPage.js');
global.StudentHomePage = require('./pages/student/studentHomePage.js');
global.StudentAllSkillsPage = require('./pages/student/studentAllSkillsPage.js');
global.StudentSkillPage = require('./pages/student/studentSkillPage.js');
global.StudentGameplayPage = require('./pages/student/studentGameplayPage.js');
global.StudentMissionPage = require('./pages/student/studentMissionPage.js');
global.StudentPortfolioPage = require('./pages/student/StudentPortfolioPage.js');
global.GameShowStudentGameplayPage = require('./pages/gameshow/gameShowStudentGameplayPage.js');
global.GameShowStudentRegistrationPage = require('./pages/gameshow/gameShowStudentRegistrationPage.js');
global.GameShowTeacherGameplayPage = require('./pages/gameshow/gameShowTeacherGameplayPage.js');
global.loginPage = new LoginPage(browser);
global.registrationPage = new RegistrationPage(browser);
global.teacherGameShowPage = new TeacherGameShowPage(browser);
global.teacherHomePage = new TeacherHomePage(browser);
global.teacherMissionPage = new TeacherMissionPage(browser);
global.teacherPurchasePage = new TeacherPurchasePage(browser);
global.teacherStudentsPage = new TeacherStudentsPage(browser);
global.teacherStudentSummaryPage = new TeacherStudentSummaryPage(browser);
global.teacherReportPage = new TeacherReportPage(browser);
global.studentHomePage = new StudentHomePage(browser);
global.studentAllSkillsPage = new StudentAllSkillsPage(browser);
global.studentSkillPage = new StudentSkillPage(browser);
global.studentGameplayPage = new StudentGameplayPage(browser);
global.studentMissionPage = new StudentMissionPage(browser);
global.studentPortfolioPage = new StudentPortfolioPage(browser);
global.gameShowStudentGameplayPage = new GameShowStudentGameplayPage(browser);
global.gameShowStudentRegistrationPage = new GameShowStudentRegistrationPage(browser);
global.gameShowTeacherGameplayPage = new GameShowTeacherGameplayPage(browser);
global.EC = protractor.ExpectedConditions;
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
},
colors: {
enabled: false,
},
prefixes: {
successful: "O ",
failed: "X ",
},
}));
},
};
My spec file
beforeAll(function () {
console.log('hi');
helper.setBrowserParams(browser);
browser.get(browser.params.siteURL);
});
it('should register a teacher and create a premium class', function () {
//Click Register
loginPage.registerBtn.click();
...
`

Gulp watch task not running karma jasmine tests

I'm trying to setup a gulp watch task to run all test under a set of folder, I can get the gulp tasks to run successful:
[10:20:15] Finished 'karma' after 5.86 s
[10:20:15] Starting 'default'...
[10:20:15] Finished 'default' after 9.45 ms
But no notification of any test passing?
Here is my karma.config:
var webpack = require("webpack"),
path = require("path");
module.exports = function (config) {
config.set({
basePath: "",
frameworks: ["jasmine"],
files: [
"./App/src/tests/**/*.js"
],
preprocessors: {
"./App/src/tests/**/*.js": ["webpack"]
},
webpack: {
module: {
loaders: [
{ test: /\.js$/, loader: "jsx-loader" }
]
},
plugins: [
new webpack.ResolverPlugin([
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
])
],
resolve: {
root: [path.join(__dirname, "./bower_components"), path.join(__dirname, "./src")]
}
},
webpackMiddleware: {
noInfo: true
},
plugins: [
require("karma-webpack"),
require("karma-jasmine"),
require("karma-chrome-launcher")
],
reporters: ["dots"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
singleRun: false
});
};
Here is my karma.js:
var gulp = require('gulp');
var karma = require('gulp-karma');
function handleError(err) {
this.emit('end');
}
gulp.task('karma', function() {
return gulp
.src('./App/src/tests/**/*.js')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on("error", handleError);
});
Gulpfile:
var gulp = require('gulp'),
requireDir = require('require-dir');
requireDir('./gulp-tasks');
gulp.task('default', ['browserify','css','karma'], function () {
gulp.watch('../App/src/**/*.js', ['browserify']);
gulp.watch('../App/src/**/*.css', ['css']);
gulp.watch('../App/src/tests/**/*.js', ['karma']);
});

How to test Durandal.js viewmodel containing i18next implementation?

I'm new to both Durandal.js and Javascript testing with Jasmine, and need some help. I have managed to get a testing environment up and running with Karma and Jasmine, but I struggle to figure out how to test my viewmodels that contains i18next dependencies.
Here's a stripped down example of my setup:
main.js
requirejs.config({
paths: {
'models': 'models',
'text': '../lib/require/text',
'durandal': '../lib/durandal/js',
'plugins': '../lib/durandal/js/plugins',
'transitions': '../lib/durandal/js/transitions',
'knockout': '../lib/knockout/knockout-2.3.0',
'bootstrap': '../lib/bootstrap/js/bootstrap.min',
'jquery': '../lib/jquery/jquery-1.9.1',
'i18next': '../lib/i18next/i18next.amd.withJQuery-1.7.1.min'
}
});
define(['plugins/router', 'durandal/system', 'durandal/app', 'durandal/binder', 'durandal/viewLocator', 'knockout', 'jquery', 'i18next'], function (router, system, app, binder, viewLocator, ko, $, i18n) {
app.configurePlugins({
router: true
});
app.start().then(function () {
// Setup of i18n
i18n.init({
detectFromHeaders: false,
fallbackLng: 'en',
preload: ['nb', 'en'],
supportedLngs: ['nb', 'en'],
resGetPath: 'locales/__lng__.json',
useCookie: true,
}, function () {
binder.binding = function (obj, view) {
$(view).i18n();
};
viewLocator.useConvention();
app.setRoot('viewmodels/shell');
});
});
});
shell.js
define(['plugins/router', 'durandal/app', 'i18next'], function (router, app, i18n) {
return {
router: router,
activate: function () {
return router.map([
{ route: '', title: i18n.t('pageTitle'), moduleId: 'viewmodels/ViewModel', nav: true }
]).buildNavigationModel().mapUnknownRoutes('viewmodels/ViewModel', 'unknown').activate({
pushState: false,
hashChange: true
});
}
};
});
test.js (own require.js config)
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/.*\.spec\.js$/.test(file)) {
tests.push(file);
}
}
}
//Workaround for the timestamp issue
for (var file in window.__karma__.files) {
window.__karma__.files[file.replace(/^\//, '')] = window.__karma__.files[file];
}
require.config({
baseUrl: 'base',
paths: {
'models': 'app/models',
'viewModels': 'app/viewmodels',
'specs': 'tests/specs/',
'text': 'lib/require/text',
'durandal': 'lib/durandal/js',
'plugins': 'lib/durandal/js/plugins',
'transitions': 'lib/durandal/js/transitions',
'knockout': 'lib/knockout/knockout-2.3.0',
'jquery': 'lib/jquery/jquery-1.9.1',
'i18next': 'lib/i18next/i18next.amd.withJQuery-1.7.1.min',
},
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
});
karma.conf.js
// Karma configuration
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: [
{ pattern: 'lib/jquery/jquery-1.9.1.js', watched: false, included: true, served: true },
{ pattern: 'tests/jasmine/jasmine-jquery.js', watched: false, served: true, included: true },
{ pattern: 'tests/specs/**/*.js', included: false },
{ pattern: 'tests/sinon.js', included: false },
{ pattern: 'lib/**/*.js', included: false, served: true },
{ pattern: 'app/**/*.js', included: false, served: true },
'tests/test.js',
//Serve the fixtures
{ pattern: 'app/**/*.html', watched: true, served: true, included: false },
{ pattern: 'app/**/*.json', watched: true, served: true, included: false },
{ pattern: 'tests/**/*.json', watched: true, served: true, included: false }
],
preprocessors: [
{ '**/*.html': '' }
],
// list of files to exclude
exclude: [
'foundation/*.js',
'require.js',
'init.js',
'jasmine/jasmine.js',
'jasmine/jasmine-html.js',
'node_modules/**/*.html'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
//browsers: ['Chrome', 'Firefox', 'IE'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
ViewModel (i18next):
define(["i18next"], function (i18n) {
var pageTitle = i18n.t("pageTitle");
return {
pageTitle: pageTitle
};
});
Spec (i18next)
define(['viewModels/ViewModel'], function (ViewModel) {
describe("Viewmodel test", function () {
it("should be testable", function () {
expect(true).toEqual(true);
});
it("should have title", function () {
expect(ViewModel.pageTitle).not.toBeEmpty();
});
});
});
Test runner output
PhantomJS 1.9.2 (Mac OS X) ERROR
ReferenceError: Can't find variable: initialized
at /Users/xxx/dev/projectXYZ/lib/i18next/i18next.amd.withJQuery-1.7.1.min.js:5
PhantomJS 1.9.2 (Mac OS X): Executed 0 of 0 ERROR (0.312 secs / 0 secs)
ViewModel (wo/i18next):
define([], function () {
var pageTitle = "This is the page title";
return {
pageTitle: pageTitle
};
});
Spec (wo/i18next)
define(['viewModels/ViewModel'], function (ViewModel) {
describe("Viewmodel test", function () {
it("should be testable", function () {
expect(true).toEqual(true);
});
it("should have title", function () {
expect(ViewModel.pageTitle).toEqual("This is the page title");
});
});
});
Test runner output (wo/i18next)
PhantomJS 1.9.2 (Mac OS X): Executed 2 of 2 SUCCESS (0.312 secs / 0.164 secs)
I guess I have to somehow initialize i18next, but I dont know how.
Any help would be much appreciated.
Regards,
Remi
UPDATE
This is what I ended up doing:
test.js:
'i18next-original': 'lib/i18next/i18next.amd.withJQuery-1.7.1.min',
'i18next': 'tests/i18n-test'
i18n-test.js:
define(['i18next-original'], function (i18noriginal) {
'use strict';
i18noriginal.init({
lng: 'nb',
detectFromHeaders: false,
fallbackLng: 'en',
preload: ['nb', 'en'],
supportedLngs: ['nb', 'en'],
resGetPath: 'base/locales/__lng__.json',
useCookie: false,
debug: false,
getAsync: false
});
return i18noriginal;
});
karma.conf.js:
{ pattern: 'tests/i18n-test.js', included: false, served: true },
Hallais Remi!
You can initialize i18next in beforeEach like this:
define(['viewModels/ViewModel', 'i18next'], function (ViewModel, i18n) {
describe("Viewmodel test", function () {
beforeEach(function() {
var initialized = false;
runs(function() {
i18n.init({
detectFromHeaders: false,
fallbackLng: 'en',
preload: ['nb', 'en'],
supportedLngs: ['nb', 'en'],
resGetPath: 'locales/__lng__.json',
useCookie: true
}, function () { initialized = true; });
});
waitsFor(function() {
return initialized;
}, 'i18n to initialize', 100);
});
it("should be testable", function () {
expect(true).toEqual(true);
});
it("should have title", function () {
expect(ViewModel.pageTitle).not.toBeEmpty();
});
});
});
For focusing the test on code inside the viewModel itself you can consider instead to mock the i18n object used in your viewModel.
testr.js might help you mock require.js dependencies: https://github.com/medallia/testr.js

Resources