How would I create a test suite where I have a test case that is dependent on a previous test case to start?
Example:
Test 1 Login with user X
Test 2 My account page (Comes after user logged in)
Test 3 "Follow up with other tests with the same user, but on other pages"
I've been through documentation of CasperJS writing_modules & other examples but I cannot find or understand how to set it up for my specific requirements. Or if it's even possible to do so.
Currently I have it setup as follows:
File 1 Suite
// Suite.js
var Suite;
Suite = require("./Login_User.js");
Suite.login_User("randomname","randompassword");
casper.then(function() { ;
this.test.pass("Hit the first then");
Suite = require("./MyAccount.js");
Suite.Enterprise();;
});
casper.run(function() {
return this.test.done();
});
File 2 Login Functionality
// Login_User.js (Test 2)
casper.test.begin("login page", function(test) {
casper.options.waitTimeout = 5000;
casper.on('remote.message', function(msg) {
this.echo('rem msg: ' + msg);
});
casper.on("page.error", function(msg) {
this.echo("Page Error: " + msg, "ERROR");
});
var url = "https://website.com";
casper.start(url, function() {
console.log("page loaded");
});
exports.login_User = function(username, password) {
casper.test.comment(username + "\n" + password);
casper.then(function() {
this.evaluate(function(username, password) {
$("cmpLogin_UserName").val(username);
$("cmpLogin_Password").val(password);
$("cmpLogin_LoginButton").click();
}, {
"username": username,
"password": password
})
casper.waitForUrl("https://website.com/myAccount.aspx", function() {
console.log("Logged in");
casper.capture("Loggedin.png");
});
});
casper.then(function(){
this.test.assertTitle("My Account", "Title is Login");
});
casper.run(function() {
test.done();
});
}
});
File 3 My Account Content
// MyAccount (Test 3)
casper.test.begin("Account page", function(test) {
casper.options.waitTimeout = 5000;
casper.on('remote.message', function(msg) {
this.echo('rem msg: ' + msg);
});
casper.on("page.error", function(msg) {
this.echo("Page Error: " + msg, "ERROR");
});
var url = "https://website.com/myAccount.aspx?";
casper.start(url, function() {
console.log("page loaded");
casper.capture("MyAccountEnt.png");
});
// It does not reach this section!!!
exports.Enterprise = function() {
casper.then(function() {
this.test.assertTitle("My Account", "My Account page");
this.test.pass("test test test");
});
casper.run(function() {
test.done();
});
}
});
Command line output https://i.stack.imgur.com/3mLy5.png