I can not find how to change reporter style in protractors runner using jasmine framework.
What I have right now is:
But I would like something more like:
Is there a way to add custom reporter for jasmine that would show current test running instead of DOTS and Fs?
I am building a jasmine reporter that does exactly what you want, jasmine-spec-reporter.
To configure in protractor.conf.js:
onPrepare: function(){
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
}
Add the isVerbose flag to the protractor config, it's false by default:
exports.config = {
. . .
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true
}
};
Add this dependency to your project:
npm install jasmine-spec-reporter --save-dev
And add this to your config file:
onPrepare: function(){
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
}
To extend #fer's answer:
You can add these settings to jasmineNodeOpts to both see the current test and get stack trace right when test fails:
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
realtimeFailure: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
},
Related
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);
});
I'm using Nightwatch JS to run my e2e tests with the Mocha runner.
I want to integrate an HTML reporter that with the suite.
I'm trying to use the nightwatch-html-reporter package. But as far as I understand there is a problem with the CLI commands (it's written in the Nightwatch docs that --reporter will not work when using mocha).
I also copied the code sample from nightwatch-html-reporter to my globals.js but it doesn't seem to work either.
The tests run but there is no output anywhere.
Here is my folder structure:
project
src
spec
e2e
globals
globals.js
tests
smoke
testFile.js
nightwatch.conf.js
Here is my conf file:
const seleniumServer = require('selenium-server-standalone-jar');
const chromeDriver = require('chromedriver');
module.exports = {
src_folders: ['src/spec/e2e/tests'],
output_folder: 'report',
page_objects_path: [
'src/spec/e2e/pageObjects'
],
globals_path: 'src/spec/e2e/globals/globals.js',
custom_commands_path: 'src/spec/e2e/customCommands',
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': chromeDriver.path
}
},
test_runner: {
type: 'mocha',
options: {
ui: 'bdd',
reporter: 'list'
}
},
test_settings: {
default: {
launch_url: 'http://URL',
silent: true,
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
args: [
"--no-sandbox",
"start-fullscreen"
]
}
}
}
}
};
And here is my global.js file:
var HtmlReporter = require('nightwatch-html-reporter');
var reporter = new HtmlReporter({
openBrowser: true,
reportsDirectory: __dirname + '/reports'
});
module.exports = {
reporter: reporter.fn
};
I don't think it will work with nightwatch-html-reporter as it is probably not a mocha reporter (but correct me if I'm wrong).
You want to use built in or custom mocha reporters when using nightwatch with mocha.
You can use a custom mocha html reporter like mochawesome but you'll have to hack around a bit and I offer no guarantees as I only tested those hacks lightly.
Here are the instructions to use mochawesome
(tested with
"mocha": "^5.2.0",
"mochawesome": "^3.1.1",
"nightwatch": "^0.9.21")
npm install mochawesome
Modify mochawesome node_modules\mochawesome *.js files to require mocha-nightwatch instead of mocha. (See instructions/explanations towards the end of the answer)
Presuming you're using a nightwatch.conf.js, configure your test runner to the equivalent of
test_runner : {
type : "mocha",
options : {
ui : "bdd",
reporter : require("mochawesome") // Please observe that you can pass a custom report constructor function here, not just reporter names
}
}
Run tests and observe that you still see the default console reporter (spec) but that at the end of the run you also see an output like:
[mochawesome] Report HTML saved to C:\projects\myWebApp\mochawesome-report\mochawesome.html
Open the html report.
This solution is hackish and fragile because nightwatch comes with it's own version of mocha.
When you install nightwatch you will see in your node_modules a mocha-nightwatch folder. This is the mocha that is being used by nightwatch.
However mochawesome doesn't use mocha-nightwatch. If you look at node_modules\mochawsome\dist\mochawesome.js you will see lines of code like:
var Base = require('mocha/lib/reporters/base');
var Spec = require('mocha/lib/reporters/spec');
This means is requires mocha, not mocha-nightwatch.
Those lines should ideally be: require('mocha-nightwatch/...).
So please change them in all *.js files that need fixing.
You could also fork mochawesome and make them like that ;)
Debugging notes:
Try putting some additional console.logs in node_modules\mocha-nightwatch\lib\mocha.js in the Mocha.prototype.reporter function. That's how I figured out what's going on.
If you use Mocha you can always go with mochawsome: https://www.npmjs.com/package/mochawesome
I haven't tried it myself but it looks pretty neat.
I am trying to run mocha with gulp with the configuration existed before.
moch.opts has the following line.
--timeout 999999
--ui tdd
--full-trace
--recursive
--compilers js:babel-register
how to add them here :
gulp.task('test', function() {
return gulp.src('sampleTest/*.js', { read: false })
.pipe(mocha());
});
I believe you can either create properties on the options object passed to gulp-mocha or you can just have it read the options file. In my case, I didn't want to duplicate things like --recursive or --require test/_init.js, but I did want to override the reporter, so I use the code shown below:
gulp.task('test', ['compile'], function() {
return gulp.src([], { read: false })
.pipe(mocha({
opts: 'test/mocha.opts',
reporter: 'min'
}))
.on('error', gutil.log);
});
You may want to modify this so that it doesn't assume the default path to test files (e.g. test/*.js), but in my simple case I didn't even need to pass a path to mocha. I'm just using gulp to trigger it (as if I had run on the command line something like mocha --opts test/mocha.opts --reporter min)
Options are passed directly to the mocha binary, so you can use any its command-line options in a camelCased form. this is the document link
gulp.task('test', ['compile'], function() {
return gulp.src([], { read: false })
.pipe(mocha({
timeout: 999999,
fullTrace: true,
reporter: 'min'
}))
.on('error', gutil.log);
});
add the setTimeout call after the mocha call
.pipe(mocha(),setTimeout(function() {
}, 999999))
While running a test suit, when something fails it also show the stack message like this
Failures:
1) Should validate labels
Message:
Failed: No element found using locator: By.cssSelector(".container h1")
Stack:
NoSuchElementError: No element found .........................
.........
......
....
can we switch off this stack output? I have tried
protractor conf.js --no-stackTrace
also updated conf.js file with settings
stackTrace: false,
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000,
includeStackTrace: false,
}
but its always showing stack output, how to fix it?
If you are using and old protractor (<=1.4 I think), setting both isVerbose and includeStackTrace to false would work for you:
jasmineNodeOpts: {
isVerbose: false,
includeStackTrace: false
}
Unfortunately, nowadays isVerbose or includeStackTrace would not be recognized in jasmineNodeOpts (explanation here):
Similar to jasmine 1.3, you may include jasmineNodeOpts in the config
file. However, because we changed the runner from
"https://github.com/juliemr/minijasminenode" to
"https://github.com/jasmine/jasmine-npm", the options have changed
slightly. Notably options print and grep are new, but we will no
longer support options isVerbose and includeStackTrace (unless, of
course, "jasmine-npm" introduces these options).
See also:
isVerbose has no effect
An elegant solution that I found was located on the protractor github at https://github.com/bcaudan/jasmine-spec-reporter/blob/master/docs/protractor-configuration.md
You can modify your jasmineNodeOpts like so
jasmineNodeOpts: {
...
print: function() {}
}
And that took care of the problem for me
I was successfully able to disable the Stacktraces in my test suite using the following setup in my "conf.js" file:
...
framework: 'jasmine',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
// If true, display spec names.
isVerbose : false,
// Use colors in the command line report.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace : false,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 60000,
// If true, print timestamps for failures
showTiming: true,
// Print failures in real time.
realtimeFailure: true
}
...
I found this GitHub issue (https://github.com/angular/protractor/issues/696) useful with this question. Setting both the "isVerbose" and "includeStackTrace" flags to 'false' worked for me.
includeStackTrace was removed in https://github.com/angular/protractor/commit/bf5b076cb8897d844c25baa91c263a12c61e3ab3
so the previous answers did not work for me.
The jasmine-spec-reporter has changed and no longer has a protractor-configuration.md file, so that advice no longer worked for me either.
However, despite the lack of a protractor-configuration.md file, I did find that jasmine-spec-reporter had the working solution for me.
I found that using the jasmine-spec-reporter in this way with Protractor 5.2.0 in my config file:
setup = function() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.TerminalReporter({
verbosity: 3,
color: true,
showStack: false }));
}
exports.config = {
onPrepare: setup
};
The key was to change the stackTrace parameter to false in the TerminalReporter
I'm trying to run Karma with the TeamCity reporter. But when I run the test suite, it fails with:
Error: No provider for "framework:qunit"! (Resolving: framework:qunit)
This works fine when the output is set to 'progress', but not when I add 'teamcity'.
My karma config looks as follows:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['qunit'],
files: [
'scripts/nml/marco/tests/tempTest.js'
],
exclude: [
],
reporters: ['progress', 'teamcity'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
captureTimeout: 60000,
singleRun: true
});
};
My test is still very simple:
(function () {
test('Test one equals one', function () {
equal(1, 1);
});
})();
Any ideas?
I figured out my problem. When I installed the TeamCity reporter, I did it to my current folder instead of the global karma folder. So I think the runner got confused with only a small set of files being in the current folder (and that overrode the global settings).
I was wrong, the tests did not pass any more when just running with the 'progress' reporter.