// _addNewFunc is just a function that adds this to the main DalekJS test at run-time
_addNewFunc("hasClass", function (__selector, __needle)
{
// generate a random name for this element
var name = "hasClass-" + new Date().getTime(),
nameElem = "span#"+name;
return this.dse_self
.execute(function(__selector, __needle, __name)
{
// create a new element to house the result
var newELEM = $('<span />').attr('id', __name).attr("data-has-class", "false");
$("body").append(newELEM);
// use jquery to test if the class exists
if($(__selector).hasClass(__needle))
{
// it exists, change the value
$(newELEM).attr('data-has-class', 'true');
}
}, __selector, __needle, name)
// test the elem if the data is true
.assert.attr(nameElem, 'data-has-class', 'true', __selector + " has the class, " + __needle)
// cleanup
.execute(function(__nameElem)
{
$(__nameElem).remove();
}, nameElem);
});
--
You received this message because you are subscribed to a topic in the Google Groups "DalekJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dalekjs/axX4A4dtHfI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dalekjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- -- linkedin.com/in/dancourse +44 (0) 7790 138 323 he...@dancourse.co.uk
// This class wraps and extends the Dalek JS test class
var _dse = {
// public
// Called first in every test to make it apply your custom functions
// from _addNewFunc
this.attachFuncs = function(__test)
{
return _applyFunctions(__test);
};
// private
// holds all the extra functions we want to add
var _aF = [];
// this applies all the extra methods defined below to the test & "dse" object
// and prepends them with, "dse_" so they're namespaced away from the
// core DalekJS methods
var _applyFunctions = function (__test)
{
// loop all the extra functions we want to add to the test suite
// and add them
for(var x in _aF)
{
var key = x,
value = _aF[x];
// namespace them
__test['dse_' + key] = value;
}
// create a reference to the original DalekJS test object
__test.theTest = __test;
return __test;
};
// used to add new custom functions to the stack
var _addNewFunc = function(__key, __func)
{
_aF[__key] = __func;
};
// Write you custom functions here
// this adds new core functionality, you access it in the tests with, "dse_hasClass"
_addNewFunc("hasClass", function (__selector, __needle) {....});
// this adds a repeat function that the test suite uses a a lot, "dse_login"
_addNewFunc("login", function(__username, __password) {
// input username
// input password
// click login
// wait until can see logged in message
};
// this logs you out from the site and calls the DalekJS done statement to end a test, "dse_logoutAndDone"
_addNewFunc("logoutAndDone", function() {
this.dse_self
.click("a.logout")
.done();
};
};
// DATA
var providers = {
"default:login": {
"username": "david",
"password": "tennant"
},
};
// Instantiate a new DalekJS Site Extras class
var dse = new _dse();
// TESTS
module.exports = {
'Default: Website loads': function (__test) {
// attaches and namespaces your custom functions to the DalekJS test object
dse.attachFuncs(__test)
// runs a normal Dalek Test
.assert.text("h1", 'Welcome to our website', "Can see welcome message")
.done()
},
'Default: Can Login': function (__test) {
// attaches and namespaces your custom functions to the DalekJS test object
dse.attachFuncs(__test)
// calls the custom login function, which is now
// attached to the DalekJS object as "dse_login"
.dse_login(providers["default:login"].username, providers["default:login"].password)
.assert.text("h1", "You are logged in", "Can see logged in welcome message")
// logs you out and calls done()
.dse_logoutAndDone();
},
};`