I've just downloaded nightwatch v2.4.1 and created a custom command (one that I'd previously create a while ago in v1.7, which worked).
So in my nightwatch.conf.js file I have custom_commands_path: ['config/commands']
In my config/commands folder I have a script called cmpDissmissal, with the code;
module.exports = function() {
this.pause(5000);
this.elements('css selector', '[id*=sp_message_container]', function (cmpPresent) {
if (cmpPresent.value.length === 0) {
console.log('no cmp');
} else {
this.element('css selector', 'iframe[id*="sp_message_iframe"]', function (result) {
var mainFrame = result.value;
this.frame(mainFrame, function () {
this.waitForElementPresent('.message-container', 10000, false);
this.click('button[title="ACCEPT AND CLOSE"]');
this.pause(5000);
this.frameParent();
});
});
}
});
return this;
};
and in my test script I have this;
it('clear cmp', function(browser) {
browser.cmpDimissal();
});
However, when I run the test, I get the following error;
browser.cmpDimissal is not a function
Am I doing something obviously wrong with the latest nightwatch release, as this used to work in v1.7.x
Many thanks.
Related
I have the following code in my index.js file. This was my attempt to implement an external task worker for Camunda in node js after cloning this repo.
var Workers = require('camunda-worker-node');
var Backoff = require('camunda-worker-node/lib/backoff');
try {
console.log('In try ');
console.log(Backoff)
var engineEndPoint = process.env.ENGINE_URL || 'http://localhost:8080/engine-rest';
}
catch (e) {
console.log(e)
}
console.log("Out of try");
var uuid = require('uuid');
var workers = new Workers(engineEndPoint);
try {
Backoff(workers);
}
catch (e) {
console.log(e);
}
workers.subscribe('FightTribe', ['name'], function (context, callback) {
console.log("in worker subscribe");
if (Math.random() > 0.9) {
console.log('German Tribe Fighter, The Battle is lost.');
return callback(null, {
variables: {
legionStatus: "defeated"
}
});
}
console.log('German Tribe Fighter, The Battle is WON.');
callback(null, {
variables: {
legionStatus: 'Victorious'
}
})
});
My camunda process engine is up and running. On starting up index.js the process hangs at the function call Backoff(workers).
In an attempt to debug i placed console.log("in worker subscribe") in workers.subscribe, but the execution never reaches there.
I have attached my working directory. I am not sure what the issue is.
I am trying to write a nightwatch test script with conditions in the test script. My code so far
module.exports = {
tags: ['getting-started'],
set_url: function (browser) {
browser.url('http://www.google.com');
browser.pause(5000);
browser.assert.title('Google');
if (browser.expect.element('#main').to.be.present) {
browser.pause(5000);
browser.setValue('input[type=text]', ['Night Watcher', browser.Keys.ENTER]);
browser.pause(5000);
if(browser.assert.containsText('#main', 'The Night Watch')){
console.log('search has the right result'); // for example
}else{
console.log('No result found');
}
}
browser.end();
}
}
But the browser.expect.element('#main').to.be.present and browser.assert.containsText('#main', 'The Night Watch') returns an object and is not actually the result I am interested with.
But the browser.expect.element('#main').to.be.present and browser.assert.containsText('#main', 'The Night Watch') returns an object and is not actually the result I am interested with.
I am using page objects...If you don't use page objects then just say browser.elements. The following solution worked for me
.waitForElementPresent('#main', 1000)
.api.elements('css selector','input[type=text]',function(result){
console.log("123");
if(result.value) {
console.log("======================================");
this.setValue('input[type=text]', ['Night Watcher', this.Keys.ENTER]);
}
})
.waitForElementPresent('#main', 1000, function(res) {
if(res.value) {
console.log('search has the right result');
}else{
console.log('No result found');
}
})
Following was the output that I got from the code.. Hope this helps you.. The code could be more optimized though.
Heading
This is very basic :
module.exports = {
tags: ['getting-started'],
set_url: function(browser) {
browser.url('http://www.google.com')
.pause(5000)
.assert.title('Google')
.waitForElementPresent('#main', 3000, function(result) {
if (result.value === true) { // '#main is present
this
.setValue('input[type=text)', 'Night Watcher')
.click('#search') //instead of enter, you can click search button
.getText("#main", function(result) {
console.log(result.value);
// You can continue here
});
}
})
.end();
}
};
I defined the simple gulp task that can be run in terminal with gulp load. The purpose is to get number of users that does not have location property set.
However, after the number returned succesfully, the process hangs in terminal and I need to ctrl-c to stop it. Note, This is not a async call and uses mongoose plug-in to access DB.
gulp.task('load', function () {
dbCall.getUserNumberWithoutLocation();
});
var getUserNumberWithoutLocation = function() {
var query = User.find({ 'location': null });
query.exec(function(err, users) {
for (var i = 0; i < users.length; i++) {
console.log(users[i].location);
}
console.log(users.length);
})
};
Despite the prompt still does not return after gulp.task done (which probably is my local machine issue), I put my code here. The callback function is passed into the inner getUserNumberWithoutLocation function, in which the it is called once User.find is completed.
gulp.task('load', ['style'], function (callback) {
dbCall.getUserNumberWithoutLocation(callback);
});
exports.getUserNumberWithoutLocation = function(callback) {
var query = User.find({'location': null});
query.exec(function(err, users) {
console.log(users.length);
if (err) {
return callback(err);
}
callback();
});
};
I have an weird error and can't find the cause of it for the last few hours...
I have a meteor app, that scrapes some webpages for information and everything works fine as long as I use reuqest and cheerio for static pages, but now I have a dynamic site and I wanted to use phantomjs, casperjs and spookyjs for this one, but here I get some bug...
My code is as follows, I import the npm modules at the start:
if (Meteor.isServer) {
var cheerio = Meteor.npmRequire('cheerio');
var request = Meteor.npmRequire('request');
var phantomJS = Meteor.npmRequire('phantomjs');
var spooky = Meteor.npmRequire('spooky');
And sometime later I want to use spooky to scrape some webpage:
spooky.start("https://www.coursera.org/");
spooky.then( function () {
this.fill("form", {email: user, password: pass}, true);
});`
But as soon as I call the method I get the following error message:
20150224-21:16:39.100(-5)? Exception while invoking method 'getLecturesCoursera' TypeError: Object function Spooky(options, callback) {
....
I20150224-21:16:39.281(-5)? } has no method 'start'
I20150224-21:16:39.281(-5)? at [object Object].Meteor.methods.getLecturesCoursera (app/moocis.js:72:14)
I am doing something completly wrong and I have no clue why it isn't working...
I tried to verify that spookyjs and phantomjs are installed correctly in my app, but that isn't as easy as it sounds for someone who uses them for the first time...
Like normally with spooky you have to create a new Spooky Object before you can start and run it...
if (Meteor.isServer) {
Meteor.startup( function () {
var Spooky = Meteor.npmRequire('spooky');
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true,
ignoreSslErrors: true,
sslProtocol: 'tlsv1'
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start(
'https://www.google.com');
spooky.then(function () {
this.emit('hello', 'Hello, from ' + this.evaluate(function () {
return document.title;
}));
});
spooky.run();
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
spooky.on('hello', function (greeting) {
console.log(greeting);
});
spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});
})
}
Grunt notify: https://github.com/dylang/grunt-notify is great. However, it seems a bit limited. As far as I can tell all my messages need to be pre-generated. So the first question is how can I generate notifications?
Next, It seems that grunt notify triggers based on error or success of some task. I guess based on std in/out/err? The problem where this breaks down is if some task doesn't use these. grunt compass doesn't use stderr if there are compile errors. So how can I run grunt notify when it has an error? This then leads to the next question. How can I grab the console output or stderr from a grunt task?
First of all, use growl. It is easy and flexible to use. To install growl:
npm install growl --save-dev
Then you need to hook into the stderr/out stream of the process. This way you can create a notification each time a new message arrives at the stderr/out stream.
This is what I've created. I've made a CommonJs module which adds hooks to:
grunt.fail.warn(), grunt.fail.fatal()
grunt.log.warn(), grunt.log.error()
grunt.warn()
process.stderr.write()
process.stdout.write() (error lines)
(child) process.stderr.write()
(child) process.stdout.write() (error lines)
It works more or less, but it may need some tweaking.
tasks/lib/notify.js
(function (module) {
var grunt = require('grunt'),
growl = require('growl'),
Buffer = require('buffer').Buffer;
function notify(obj, title) {
if (obj) {
var message = Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj);
var msg = grunt.log.uncolor(message);
if (msg.length > 0) {
growl(msg, {
title: title,
image: 'Console'
});
}
}
}
// add a hook to grunt.fail.warn(), grunt.fail.fatal()
['warn', 'fatal'].forEach(function (level) {
grunt.util.hooker.hook(grunt.fail, level, function(obj) {
notify(obj);
});
});
// add a hook to grunt.log.warn(), grunt.log.error()
['warn', 'error'].forEach(function (level) {
grunt.util.hooker.hook(grunt.log, level, function(obj) {
notify(obj, level);
});
});
// add a hook to grunt.warn()
grunt.util.hooker.hook(grunt, 'warn', function(obj) {
notify(obj, 'warn');
});
// add a hook to process.stderr.write()
grunt.util.hooker.hook(process.stderr, 'write', function(obj) {
var messages = grunt.log.uncolor((Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj))).split('\n');
messages.forEach(function (message) {
notify(message, 'stderr');
});
});
// add a hook to process.stdout.write() (only error lines)
grunt.util.hooker.hook(process.stdout, 'write', function(obj) {
var messages = grunt.log.uncolor((Buffer.isBuffer(obj) ? obj.toString() : (obj.message || obj))).split('\n');
messages.forEach(function (message) {
if (message && message.indexOf('error ') > -1) {
notify(message, 'stdout');
}
});
});
// add a hook to child process stdout/stderr write() (only error lines)
grunt.util.hooker.hook(grunt.util, 'spawn', {
post: function(child) {
child.stderr.on('data', function (data) {
var messages = grunt.log.uncolor(data.toString()).split('\n');
messages.forEach(function (message) {
notify(message, 'stderr');
});
});
child.stdout.on('data', function (data) {
var messages = grunt.log.uncolor(data.toString()).split('\n');
messages.forEach(function (message) {
if (message && message.indexOf('error ') > -1) {
notify(message, 'stdout');
}
});
});
}
});
}) (module);
Then you need to include it in your Gruntfile.js with a require statement:
module.exports = function (grunt) {
grunt.initConfig({
...
});
require('./tasks/lib/notify');
...
};
PS I've placed the file in tasks/lib/notify.js, but feel free to place it somewhere else.