Use test.assert in casperjs - casperjs

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();
});
});

Related

Mocha beforeEach not running

I have seen lots of questions about this but all of the fixes simply does not work with my code.
What am I doing wrong? My beforeEach doesnt get executed.
This is the unit test code:
var assert = require('assert');
var environmentConfiguration;
var fs = require('fs');
var expect = require('chai').expect;
describe('environmentConfiguration', function() {
beforeEach('some description', function() {
console.log("hello")
});
describe('#configFile null configFile', function() {
var result = environmentConfiguration.load(null)
var expectedConfiguration = JSON.parse(fs.readFileSync('./ISPRemotingService.config.json'));
it('should return current ISP environment configuration', function() {
assert(result, expectedConfiguration);
});
});
});
I have also applied simpler versions from Mocha's documentation and beforeEach doesn't gets executed.
Another exception was blocking the unit tests to even reach there. My bad

How to send the success of a test to testingBot from a Protractor project?

Following the testingBot example for protractor-based projects I got this code
var TestingBot = require('testingbot-api');
describe('Protractor Demo App', function () {
var tb;
beforeEach(function () {
tb = new TestingBot({
api_key: "master_key",
api_secret: "secret_007"
});
});
afterEach(function () {
browser.getSession().then(function (session) {
tb.updateTest({
'test[success]': true/*where do I get this 'test[success]' attribute? */
}, session.getId(), function () {
console.log("Hi! :D");
});
})
});
it('should have a title', function () {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
I need to send the success of the test back through the tb.updateTest() but I don't know where I get the value of a passed or failed test. For now the value is a static true. I'd appreciate a jasmine approach too.
You can use a custom reporter with Jasmine.
There you can hook into specDone or suiteDone which has a result parameter, containing the test's success state.
You can then use this state to write a custom report or send it to somewhere else.

how does phantomjs work with protractor?

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?

jasmine-reporters is not generating any file

i'm using jasmine-reporters to generate a report after protractor finish the tests,
this is my configuration file:
onPrepare: function(){
var jasmineReporters = require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps){
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + "-" + browserVersion + "-";
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter("protractor_output", true, true,prePendStr));
});
},
i don't get any error, the reporters installed, but i don't see any file in protractor_output folder.
Any idea what am i doing wrong?
The problem is with the jamsine version:
If you are trying to use jasmine-reporters with Protractor, keep in mind that Protractor is built around Jasmine 1.x. As such, you need to use a 1.x version of jasmine-reporters.
npm install jasmine-reporters#~1.0.0
then the configuration should be:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true)
);
}
If you are on a newer version of the Jasmine Reporter, then the require statement no longer puts the JUnitXmlReporter on the jasmine object, but does put it on the module export. Your setup would then look like this:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('xmloutput', true, true)
);
}
also you need to verify that xmloutput directory exist!
To complete the answer, if the output is still not generating,
Try adding these configuration line to your protractor exports.config object :
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
.......
}

jasmine-reporters option for Protractor's multiCapabilities option

I am using [jasmine-reporters] for xml report with Protractor.
Protractor's configuration for [jasmine-reporters] look like below,
onPrepare: function() {
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('../e2e_test_out', true, true, 'testresults.e2e.'));
},
above config working fine and gettting the result in 'e2e_test_out' directory with 'testresults.e2e.' prefix.
But when I use protractor's multiCapabilities option,
multiCapabilities: [{
'browserName': 'chrome'
}, {
'browserName': 'internet explorer'
}],
I am getting only one set of report. From that I could not understand the individual browser's result.
Is there any way to generate two diff reports / combined reports for both the browsers?
I found a solution that solved the same problem for me here:
https://github.com/angular/protractor/issues/60
In your protractor.conf file:
onPrepare: function(){
require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps){
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + "-" + browserVersion + "-";
jasmine.getEnv().addReporter(new
jasmine.JUnitXmlReporter("protractor_output", true, true,prePendStr));
});
}
This will result in reports like:

Resources