Smoketest - pure javascript smoke-test framework. (currently in beta)
Full documentation are not here yet, but base API presents
npm install smoketest --save-dev
bower install smoketest --save-dev
Or just fetch build under dist.
- Add tests to site
- Run tests
- Action methods
- Configure timeouts
- Promisified methods
- Already found element
- Other
For add framework and tests to your site, just add it right in simple script. Look to the example
But if you want add framework and tests without change your site files, you can use userscripts (tampermonkey / greasemonkey extensions) Look to the example
Just type in console smokeTest.runAll();
You can make typo in camelCase, it is no problem =)
interact methods:
get methods:
core methods:
var click = smokeTest.actions.click;
click('button#submit', optionalCallback);
var inputText = smokeTest.actions.inputText;
inputText('input#login', 'John Doe', optionalCallback);
var focusOn = smokeTest.actions.focusOn;
focusOn('input#password', optionalCallback);
var blur = smokeTest.actions.blur;
blur('input#age', optionalCallback);
var pickInSelect = smokeTest.actions.pickInSelect;
// You can pass option value
pickInSelect('select#car', 'mercedez', optionalCallback);
// You can pass option innerHTML
pickInSelect('select#car', 'Mercedez Benz', optionalCallback);
// Or a number of selected value
pickInSelect('select#car', 2, optionalCallback);
var getText = smokeTest.actions.getText;
getText('div#selectedCar', function (err, text) {
if (err) throw err;
// work with text
});
var getValue = smokeTest.actions.getValue;
getValue('input#surname', function (err, value) {
if (err) throw err;
// work with value
});
var findElement = smokeTest.actions.findElement;
// You can use with default timeout waiting for element presense
findElement('div#main', function (err, element) {
if (err) throw err;
// work with element
});
// Or you can specify need timeout
findElement('div#main', 3000, function (err, element) {
if (err) throw err;
// work with element
});
var waitState = smokeTest.actions.waitState;
waitState(function () {
// this is predicate, it must return boolean value
var loadedCarsInList = document.querySelectorAll('ul#cars>li').length;
return loadedCarsInList === 12;
}, function (err) {
// this is callback, it will called if predicate returns true, until timeout done
if (err) throw err;
// work with successfully loaded car list
}, 5000, 1000); // optional timeout and optional refresh time (wait 5 seconds and check predicate every second)
// every waitState method or findElement process will try every second
smokeTest.actions.setDefaultRefreshTime(1000);
// every waitState method or findElement process will failed after 6 seconds
smokeTest.actions.setDefaultTimeout(6000);
All action methods has promisified version, in example getText
:
var getText = smokeTest.actions.promised.getText;
getText('div#carDescription')
.then(function (text) { /* work with text =) */ })
.catch(function (err) { /* handle error =( */ };
All action methods (promisified too) you can use with already found element. It is comfortable for promise chaining:
var promiseActions = smokeTest.actions.promised;
var findElement = promiseActions.findElement;
var click = promiseActions.click;
findElement('#buttonForClick')
.then(button => click(button));
smokeTest.version();
Returns versions of framework and bundled libraries