diff options
Diffstat (limited to 'server/sonar-web/src/main/js/tests/e2e/lib.js')
-rw-r--r-- | server/sonar-web/src/main/js/tests/e2e/lib.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/server/sonar-web/src/main/js/tests/e2e/lib.js b/server/sonar-web/src/main/js/tests/e2e/lib.js index 20ba1903c6c..6650aa509de 100644 --- a/server/sonar-web/src/main/js/tests/e2e/lib.js +++ b/server/sonar-web/src/main/js/tests/e2e/lib.js @@ -22,8 +22,10 @@ exports.initMessages = function () { exports.changeWorkingDirectory = function (dir) { + var commandLineArgs = require('system').args; // Since Casper has control, the invoked script is deep in the argument stack - var currentFile = require('system').args[4]; + // commandLineArgs = casper/bin/bootstrap.js,--casper-path=.../casperjs,--cli,--test,[file(s) under test],[options] + var currentFile = commandLineArgs[4]; var curFilePath = fs.absolute(currentFile).split(fs.separator); if (curFilePath.length > 1) { curFilePath.pop(); // PhantomJS does not have an equivalent path.baseName()-like method @@ -33,6 +35,16 @@ exports.changeWorkingDirectory = function (dir) { }; +exports.testName = function () { + var head = Array.prototype.slice.call(arguments, 0); + return function () { + var tail = Array.prototype.slice.call(arguments, 0), + body = head.concat(tail); + return body.join(' :: '); + }; +}; + + var mockRequest = function (url, response) { return casper.evaluate(function (url, response) { return jQuery.mockjax({ url: url, responseText: response}); @@ -74,3 +86,12 @@ exports.setDefaultViewport = function () { exports.capture = function (fileName) { casper.capture(fileName, { top: 0, left: 0, width: WINDOW_WIDTH, height: WINDOW_HEIGHT }); }; + + +exports.waitForElementCount = function (selector, count, callback) { + return casper.waitFor(function () { + return casper.evaluate(function (selector, count) { + return document.querySelectorAll(selector).length === count; + }, selector, count) + }, callback); +}; |