I have a Gulp configuration file that runs Protractor/Jasmine like this:
.pipe($.protractor.protractor({ configFile: 'protractor.conf.js', args: args || ['--baseUrl', 'http://localhost:' + basePort] }))
But the report shown in the console are just dots, instead of the actual specs tests. How can I make Jasmine be verbose?
This was possible with the isVerbose option in Jasmine 1, but I can't find the equivalent for Jasmine 2.
What we are doing is setting these jasmine settings:
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
includeStackTrace: true,
defaultTimeoutInterval: 100000,
print: function() {}
}
And using jasmine-spec-reporter package that provides a nice and detailed test output:
onPrepare: function () {
var SpecReporter = require('jasmine-spec-reporter');
// jasmine spec reporter
jasmine.getEnv().addReporter(new SpecReporter({
displayStacktrace: 'all',
displayPendingSpec: true,
displaySpecDuration: true
}));
}
Related
I have recently installed the jasmine-spec-reporter package in order to produce more verbose and helpful logging during execution of test suites.
I want to be able to log expected and actual values for failed test cases and was wondering if I needed to explicitly have a statement in the form of expect(someCondition).toEqual(true); in order for me to see these values.
For example, I have a function like the following:
it('should log in', function(done) {
var customerNameElement;
customerNameElement = element.all(by.xpath('some_xpath')).first();
core.infoMessage(browser, JSON.stringify(params, undefined, 4));
login.login(browser, undefined, undefined, getWaitTime())
.then(function() {
return browser.wait(protractor.ExpectedConditions.and(
function() { return core.isUnobscured(browser, customerNameElement);
}, protractor.ExpectedConditions.elementToBeClickable(customerNameElement)), getWaitTime());
})
.catch(fail)
.then(done);
});
I can still log the failure to the console but not in the form that I'd like. Does jasmine-spec-reporter handle this or do I have to add the statement from above in each test case?
Also, does the fail keyword in the .catch() have any properties I can use to my advantage? It comes from:
// Type definitions for Jasmine 2.5.2 // Project: http://jasmine.github.io/
Thanks
you can try adding the below in protractor_config file:
let SpecReporter = require('jasmine-spec-reporter').SpecReporter;
exports.config = {
// your config here ...
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
}));
}
}
Also, add the print function in the jasmineNodeOptssection
jasmineNodeOpts: {
...
print: function() {}
}
I'm not using compass or codekit, just Gulp to compile my SASS files. And a .sass-cache folder gets generated. I'd rather it not and don't mind the extra nano secs it would take to compile, because it adds too much to my quick find in Sublime Text.
In the docs for gulp-ruby-sass I found the option for noCache however I'm not sure where to set it or what the syntax is. Would you know? Somewhere in my GulpFile?
https://www.npmjs.com/package/gulp-ruby-sass
noCache
Type: Boolean
Default: false
Here is my Gulp Task
gulp.task('web_css', function() {
return sass('bower_components/sass-smacss/sass/manage.scss', { style: 'compressed' })
.pipe(sass({ noCache: true }))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('assets/css/'))
});
This is a valid example of how to do it:
gulp.task('sass', function () {
return sass('bower_components/sass-smacss/sass/manage.scss',
{ noCache: true, style: 'compressed' }
)
.pipe(gulp.dest('path/to/your/css'))
);;
});
When you apply the sass function, you have to pass your option as a parameters.
I am getting my head around protractor and phantomjs. The test looks like this, it works fine with
just chrome:
describe('angularjs homepage', function () {
beforeEach(function () {
browser.driver.manage().window().setSize(1124, 850);
});
it('should greet the named user', function () {
browser.driver.get('https://angularjs.org/');
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
the protractor.config looks like this :
// An example configuration file.
exports.config = {
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs',
'phantomjs.binary.path': 'C:/ptor_testing/node_modules/phantomjs/lib/phantom/phantomjs.exe'
},
// For speed, let's just use the Chrome browser.
//chromeOnly: true,
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['example.spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000
},
seleniumAddress: 'http://localhost:4444/wd/hub'
};
When I run this i get:
Error: Error while waiting for Protractor to sync with the page: {"message":"Can't find variable: angular","name":"ReferenceError","line":4,"stack":"ReferenceError: Can't find variable: angular\n at :4\n at anonymous (:13)\n at Na (phantomjs://webpage.evaluate():14)\n at phantomjs://webpage.evaluate():15\n at phantomjs://webpage.evaluate():15\n at phantomjs://webpage.evaluate():16\n at phantomjs://webpage.evaluate():16\n at phantomjs://webpage.evaluate():16","stackArray":[{"sourceURL":"","line":4},{"sourceURL":"","line":13,"function":"anonymous"},{"sourceURL":"phantomjs://webpage.evaluate()","line":14,"function":"Na"},{"sourceURL":"phantomjs://webpage.evaluate()","line":15},{"sourceURL":"phantomjs://webpage.evaluate()","line":15},{"sourceURL":"phantomjs://webpage.evaluate()","line":16},{"sourceURL":"phantomjs://webpage.evaluate()","line":16},{"sourceURL":"phantomjs://webpage.evaluate()","line":16}],"sourceId":81819056}
How can I fix this?
I have set up a gulp-ruby-sass task in gulp, with some options.
Options 'precision' and 'style' work as expected, but I get no debugInfo or lineNumbers in the css (I do get them with compass).
My gulpfile.js:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass');
function errorLog(error)
{
console.log(error.toString());
this.emit('end');
}
// SASS
gulp.task('styles', function(){
gulp.src('scss/**/*.scss')
.pipe(sass({
debugInfo : true,
lineNumbers : true,
precision : 6,
style : 'normal'
}))
.on('error', errorLog)
.pipe(gulp.dest('css/'));
});
What am I doing wrong?
I was able to figure this out. The solution was two-fold for me. If I added the lineNumbers option, it would fail with a file not found error. This is probably because I am compiling both normal css (with line numbers) along with a minified version.
I needed to add the "container" option in order for it to work correctly.
Here's what my working gulp tasks look like:
gulp.task('styles', function()
{
return sass('app/assets/sass/app.scss', { style: 'expanded', lineNumbers: true, container: 'gulp-ruby-sass' })
.pipe(autoprefixer('last 15 version'))
.pipe(gulp.dest('public/css'));
});
gulp.task('styles-min', function()
{
return sass('app/assets/sass/app.scss', { style: 'expanded', container: 'gulp-ruby-sass-min' })
.pipe(autoprefixer('last 15 version'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('public/css'));
});
NOTE: The lineNumbers option is somewhat misleading because it's actually the path to the source sass/scss file AND the line number.
For the casperjs, I have:
var casper = require('casper').create({
loadImages:false,
verbose: true,
logLevel: 'debug',
});
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)');
casper.then(function(){
this.echo('step 1 is finished!^.^');
});
I want use casper.test.assert('Step1 is finished');
When I run the code, I cannot use casperjs myjs.js anymore, because the new version need to use casperjs test yourjs.js. But when I use the new one, still give me the error
You can’t override the preconfigured casper instance in this test environment
So, what show I do?
Do exactly what it says. You cannot create a casper instance when you run casper test myjs.js. It will be injected. Just change
var casper = require('casper').create({
loadImages:false,
verbose: true,
logLevel: 'debug',
});
to
casper.options.loadImages = false;
casper.options.verbose = true;
casper.options.logLevel = 'debug';
and use casper inside of test blocks:
casper.test.begin('some test name', function(test) {
casper.start(url);
casper.then(function() {
test.assert(this.getTitle()!=''); // straight forward
})
casper.run(function() {
test.done();
});
});