Library, that helps simulate user actions for write fast functional tests fro browsers
npm install useractions --save-dev
- Add tests to webpage
- Run tests
- Action methods
- Configure timeouts
- Promisified methods
- Already found element
- Todo section
- Other
For add tests to your webpage, just add it right in simple script. Look to the example
But if you want add lib and tests without change your webpage files, you can use userscripts (tampermonkey / greasemonkey extensions)
interact methods:
- click method
- event method
- changeValue method
- focusOn method
- blur method
- pickInSelect method
- directClick method
get methods:
core methods:
var click = userActions.click;
click('button#submit', optionalCallback);
var event = userActions.event;
event({
type: 'click',
target: 'button#submit'
}, optionalCallback);
var changeValue = userActions.changeValue;
changeValue('input#login', 'John Doe', optionalCallback);
var focusOn = userActions.focusOn;
focusOn('input#password', optionalCallback);
var blur = userActions.blur;
blur('input#age', optionalCallback);
var pickInSelect = userActions.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 directClick = userActions.directClick;
// this method calls .click() method of element directly (without events)
click('#myCheckbox', optionalCallback);
var getText = userActions.getText;
getText('div#selectedCar', function(err, text) {
if (err) throw err;
// work with text
});
var getValue = userActions.getValue;
getValue('input#surname', function(err, value) {
if (err) throw err;
// work with value
});
var findElement = userActions.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 = userActions.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
userActions.setDefaultRefreshTime(1000);
// every waitState method or findElement process will failed after 6 seconds
userActions.setDefaultTimeout(6000);
All action methods has promisified version, in example getText
:
var getText = userActions.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 = userActions.promised;
var findElement = promiseActions.findElement;
var click = promiseActions.click;
findElement('#buttonForClick')
.then(button => click(button));
- make possible es6 imports, not only IIFE
- console-browser integration for test runs
- step synchronization for non SPA websites (or crossdomain websites)
- headless chrome usage examples
- test runs results keeping
- test runs results statistics
- fix stacktrace after waiting recursive functions
userActions.version();
Returns version of library and bundled dependencies