module.exports = {
"Test end-to-end new incident flow" : function(client) {
var async = require('async');
var incident_log = require("crypto").randomBytes(32).toString('hex');
var incident_name;
async.series([
function first(callback) {
console.log('first');
var incident_name;
client
.page.admin_home().fetchPage()
.page.admin_home().login()
.page.admin_home().clickIncidentsTab()
.page.incidents_home().verifyPage()
.page.incidents_home().clickNewButton()
.page.new_incident().verifyPage()
.page.new_incident().createIncident(incident_log)
.page.incident_detail().verifyPage()
.page.incident_detail().getIncidentName(function(result) {
incident_name = result.value
console.log(result.value)
});
callback(null, 'first');
},
function second(callback) {
console.log('second');
var sfdb = require('sfdb.js')
var query = "SELECT Id, Name FROM Incident WHERE Name like '%"+incident_name+"%'";
sfdb.query(client.globals, query, function(data) {
console.log(require('util').inspect(data))
});
callback(null, 'second');
}
],
function(err, results) {
console.log(results)
});
client.end();
}
};Running: Test end-to-end new incident flow
first
second
[ 'first', 'second' ]
{ totalSize: 0, done: true, records: [] }
✔ Element <#Login> was visible after 72 milliseconds.
✔ Testing if element <#Login> is visible.
✔ Element <img.chatter-photo> was visible after 6776 milliseconds.
✔ Testing if attribute title of <span.chatter-avatarSmall> equals "Panda Tester".
✔ Element <#AllTab_Tab> was visible after 17 milliseconds.
✔ Element <.pbTitle> was visible after 1202 milliseconds.
✔ Testing if element <.pbTitle> contains text: "Recent Incidents".
✔ Element <.pbButton> was visible after 80 milliseconds.
✔ Testing if element <.pbButton> is present.
✔ Element <.pageDescription> was visible after 1045 milliseconds.
✔ Testing if element <.pageDescription> contains text: "New Incident".
✔ Element <.mainTitle> was visible after 4920 milliseconds.
✔ Testing if element <.mainTitle> contains text: "Incident Detail".
✔ Element <h2.pageDescription> was visible after 20 milliseconds.
I-0240
OK. 14 total assertions passed. (25.724s)Since the function second gets executed while the function first is still running; hence, the database query returns:
{ totalSize: 0, done: true, records: [] }{ totalSize: 1, done: true, records: [Id: 'xxxxxx', Name: 'I-0240'] }What am I done wrong? What is the proper way to execute steps/functions in nightwatch test sequentially?
Please help and thanks!
var incident_log = require("crypto").randomBytes(32).toString('hex');
var incident_name;
module.exports = {
"Test end-to-end new incident flow - Step 1" : function(client) {
console.log('first');
client
.page.admin_home().fetchPage()
.page.admin_home().login()
.page.admin_home().clickIncidentsTab()
.page.incidents_home().verifyPage()
.page.incidents_home().clickNewButton()
.page.new_incident().verifyPage()
.page.new_incident().createIncident(incident_log)
.page.incident_detail().verifyPage()
.page.incident_detail().getIncidentName(function(result) {
incident_name = result.value
console.log(result.value)
});
},
"Test end-to-end new incident flow - Step 2" : function(client) {
console.log('two');
var sfdb = require('sfdb.js')
var query = SELECT Id, Name FROM Incident WHERE Name like '%"+incident_name+"%'";
sfdb.query(client.globals, query, function(data) {
console.log(require('util').inspect(data))
});
client.end();
}
};Running: Test end-to-end new incident flow - Step 1
first
✔ Element <#Login> was visible after 78 milliseconds.
✔ Testing if element <#Login> is visible.
✔ Element <img.chatter-photo> was visible after 10140 milliseconds.
✔ Testing if attribute title of <span.chatter-avatarSmall> equals "Panda Tester".
✔ Element <#AllTab_Tab> was visible after 19 milliseconds.
✔ Element <.pbTitle> was visible after 1384 milliseconds.
✔ Testing if element <.pbTitle> contains text: "Recent Incidents".
✔ Element <.pbButton> was visible after 21 milliseconds.
✔ Testing if element <.pbButton> is present.
✔ Element <.pageDescription> was visible after 967 milliseconds.
✔ Testing if element <.pageDescription> contains text: "New Incident".
✔ Element <.mainTitle> was visible after 2622 milliseconds.
✔ Testing if element <.mainTitle> contains text: "Incident Detail".
✔ Element <h2.pageDescription> was visible after 20 milliseconds.
I-0241
OK. 14 assertions passed. (30.874s)
Running: Test end-to-end new incident flow - Step 2
two
{ totalSize: 1, done: true, records: [Id: 'xxxxxx', Name: 'I-0241'] }
No assertions ran.
OK. 14 total assertions passed. (34.659s)