OK, here it is. The setToken() command is my custom command.
Thanks!
var request = require("request"),
querystring = require("querystring"),
async = require("async");
function avAuthenticate(callback) {
var authParams = {
grant_type: 'password',
client_id: AV_CLIENT_ID,
client_secret: AV_CLIENT_SECRET,
username: AV_EMAIL,
password: AV_PASSWORD
};
request.get({
url: AV_BASE_URL + AV_AUTH_URL + "?" + querystring.stringify(authParams),
json: true
}, function(error, response, body) {
avToken = body.access_token;
callback(null, avToken);
});
}
function launchTests(options, callback) {
var url = AV_BASE_URL + "/monitor/systems";
options.browser
.url(AV_BASE_URL + "/login")
.setToken(options.token)
.url(url)
.waitForElementVisible('a#nav_section_link_systems', 5000)
.click("#system_actions_container button.dropdown-toggle")
.assert.cssClassPresent("#system_retrieveData", "disabled")
.click("#system_datatable td:nth-child(1) > input")
.click("#system_actions_container button.dropdown-toggle")
.assert.cssClassNotPresent("#system_retrieveData", "disabled")
.click("#system_actions_container button.dropdown-toggle")
.waitForElementVisible('#system_retrieveData', 100)
.click("#system_retrieveData")
.waitForElementVisible('.modal', 100)
.assert.containsText(".modal .modal-header h3", "Retrieve System data")
.end();
}
module.exports = {
"Monitor Systems": function(browser) {
var self = this,
tasks = [];
AV_BASE_URL = this.client.launch_url;
tasks.push(avAuthenticate);
tasks.push(function(token, callback) {
launchTests({
browser: browser,
token: token
}, callback);
});
async.waterfall(tasks, function(err, result) {
if (err) {
console.log("!! Err", err);
return;
}
});
}
};