npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

useractions

v0.7.0

Published

Library, that helps simulate user actions for write fast functional tests

Downloads

19

Readme

UserActions

Library, that helps simulate user actions for write fast functional tests fro browsers

Getting started

Npm

npm install useractions --save-dev

Table of contents


Add tests to webpage

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)


Run tests

Look to the example


Action methods

interact methods:

get methods:

core methods:

Methods API

click method

var click = userActions.click;
click('button#submit', optionalCallback);

event method

var event = userActions.event;
event({
  type: 'click',
  target: 'button#submit'
}, optionalCallback);

changeValue method

var changeValue = userActions.changeValue;
changeValue('input#login', 'John Doe', optionalCallback);

focusOn method

var focusOn = userActions.focusOn;
focusOn('input#password', optionalCallback);

blur method

var blur = userActions.blur;
blur('input#age', optionalCallback);

pickInSelect method

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);

directClick method

var directClick = userActions.directClick;

// this method calls .click() method of element directly (without events)
click('#myCheckbox', optionalCallback);

getText method

var getText = userActions.getText;
getText('div#selectedCar', function(err, text) {
  if (err) throw err;

  // work with text
});

getValue method

var getValue = userActions.getValue;
getValue('input#surname', function(err, value) {
  if (err) throw err;

  // work with value
});

findElement method

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
});

waitState method

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)

Configure timeouts

setDefaultRefreshTime method

// every waitState method or findElement process will try every second
userActions.setDefaultRefreshTime(1000);

setDefaultTimeout method

// every waitState method or findElement process will failed after 6 seconds
userActions.setDefaultTimeout(6000);

Promisified methods

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 =( */ };

Already found element

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));

TODO

  • [ ] 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

Other

userActions.version();

Returns version of library and bundled dependencies