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

@netsells/simulate-user

v2.3.0

Published

Library for simulating user interactions using JavaScript in the browser

Downloads

1

Readme

npm version Build Status codecov Mutation testing badge

@netsells/simulate-user

Library for simulating user interactions using JavaScript in the browser

Installation

yarn add @netsells/simulate-user

Usage

import SimulateUser from '@netsells/simulate-user';

const sim = new SimulateUser();

const el = await sim.find({ query: 'a', text: 'Click me' });
await el.click();

Documentation

Classes

Functions

Typedefs

DebugUser

Helper class for providing debug information.

Kind: global class

new DebugUser(...args)

Setup the class.

| Param | Type | | --- | --- | | ...args | any |

debugUser.build(...args) ⇒ Proxy.<object>

Generate a instance using the same class constructor and debug emitter.

Kind: instance method of DebugUser

| Param | Type | | --- | --- | | ...args | any |

debugUser.emit(callback, ...args)

Emit and log an event.

Kind: instance method of DebugUser

| Param | Type | | --- | --- | | callback | string | | ...args | any |

debugUser.on(...args)

Listen to a debug event.

Kind: instance method of DebugUser

| Param | Type | | --- | --- | | ...args | any |

SimulateUser

Simulate a user.

Kind: global class

new SimulateUser(node)

Create a SimulateUser class for a page element.

| Param | Type | | --- | --- | | node | HTMLElement |

simulateUser.visible ⇒ boolean

Check if the node is visible.

Kind: instance property of SimulateUser

simulateUser.hidden ⇒ boolean

Check if the node is hidden.

Kind: instance property of SimulateUser

simulateUser.nextElementSibling ⇒ SimulateUser | null

NextElementSibling but returns a wrapper.

Kind: instance property of SimulateUser

simulateUser.options ⇒ Array.<string>

Get all select option values.

Kind: instance property of SimulateUser

simulateUser.text ⇒ string

Get trimmed text content.

Kind: instance property of SimulateUser

simulateUser.directText ⇒ string

Get text content which is a direct child of this node.

Kind: instance property of SimulateUser

simulateUser.parentElement ⇒ SimulateUser

Get the parentElement in a wrapper.

Kind: instance property of SimulateUser

simulateUser.className ⇒ string

Proxy for className.

Kind: instance property of SimulateUser

simulateUser.value ⇒ string

Proxy for value.

Kind: instance property of SimulateUser

simulateUser.htmlFor ⇒ string

Proxy for htmlFor.

Kind: instance property of SimulateUser

simulateUser.tag ⇒ string

TagName but lower case.

Kind: instance property of SimulateUser

simulateUser.build(...args) ⇒ Proxy.<SimulateUser>

Generate a instance using the same class constructor and debug emitter.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | ...args | any |

simulateUser.sleep(timeout) ⇒ Promise.<undefined>

Returns a promise which resolves in a certain amount of milliseconds.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | timeout | number |

simulateUser.timeout(func, limit) ⇒ Promise.<*>

Returns a promise which times out if the passed in promise doesn't resolve in time.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | func | function | | limit | number |

simulateUser.getEventOptions(options) ⇒ object

Get options for an event.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | options | object |

simulateUser.querySelectorAll(query) ⇒ Array.<SimulateUser>

Proxy for querySelectorAll but returns an array of wrappers instead of nodes.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | query | string | Array.<string> |

simulateUser.getElementById(id) ⇒ SimulateUser | null

GetElementById but returns a wrapper.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | id | string |

simulateUser.getElementsByName(name) ⇒ Array.<SimulateUser>

GetElementsByName but returns an array of wrappers.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | name | string |

simulateUser.closest(...args) ⇒ SimulateUser | null

Closest but returns a wrapper.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | ...args | any |

simulateUser.all(options) ⇒ SimulateUser | null

Search through page elements as a user would, using text.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | options | SearchProperties |

simulateUser.first(options) ⇒ SimulateUser | null

Get the first element of a query to all.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | options | SearchProperties |

simulateUser.find(options, limit) ⇒ SimulateUser

Get the first element of a query to all, but throws an error if it's not found. Will wait for an element to appear (e.g. If a form is updating).

Kind: instance method of SimulateUser
Throws:

  • Error

| Param | Type | Description | | --- | --- | --- | | options | SearchProperties | | | [options.similar] | boolean | If no exact matches found, fall back to a fuzzy search. | | limit | number | |

simulateUser.field(label, [findOptions]) ⇒ SimulateUser | null

Get a field based on its label.

Kind: instance method of SimulateUser
Throws:

  • Error

| Param | Type | Default | | --- | --- | --- | | label | string | | | [findOptions] | object | {} |

simulateUser.fieldSet(legend) ⇒ SimulateUser | null

Get a fieldset based on its legend.

Kind: instance method of SimulateUser
Throws:

  • Error

| Param | Type | | --- | --- | | legend | string |

simulateUser.dispatchEvent(event)

Proxy for dispatchEvent.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | event | Event |

simulateUser.click(search)

Click this node.

Kind: instance method of SimulateUser

| Param | Type | Default | | --- | --- | --- | | search | SearchProperties | |

simulateUser.attach(files)

Attach files to this input element.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | files | Array.<Files> |

simulateUser.check(checked)

Check this checkbox.

Kind: instance method of SimulateUser

| Param | Type | Default | | --- | --- | --- | | checked | boolean | true |

simulateUser.focus()

Focus this element.

Kind: instance method of SimulateUser

simulateUser.blur()

Blur this element.

Kind: instance method of SimulateUser

simulateUser.typeKey(key)

Type a single key on this element.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | key | string |

simulateUser.type(text)

Type a string on this element.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | text | string |

simulateUser.typeValue(text)

Type into a fields value. Only simulates the final key press then triggers a single change event.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | text | string | number |

simulateUser.fillIn(label, value) ⇒ SimulateUser

Find a field by its label then fill it in.

Kind: instance method of SimulateUser
Returns: SimulateUser - - The field wrapper.

| Param | Type | | --- | --- | | label | string | | value | ValueSelector |

simulateUser.fill(value)

Fill in this node as a field.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | value | ValueSelector |

simulateUser.select(value)

Change a value by the option text.

Kind: instance method of SimulateUser

| Param | Type | | --- | --- | | value | ValueSelector |

simulateUser.sendChangeEvent()

Send a change event.

Kind: instance method of SimulateUser

getDebugUser(Klass) ⇒ object

Get a debug user extending a user class.user.

Kind: global function

| Param | Type | | --- | --- | | Klass | SimulateUser |

get(target, prop) ⇒ any

Get the needed property.

Kind: global function

| Param | Type | | --- | --- | | target | object | | prop | any |

SearchProperties : object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | text | string | Text to search on. | | query | string | Optional query to filter on. | | caseSensitive | boolean | Whether text is case sensitive. | | exact | boolean | Whether text match should be exact (not including trimmed white space). | | predicate | function | Predicate function wrappers must match. | | visible | boolean | If element must be visible or not. | | direct | boolean | If text should be a direct child or not. |

ValueSelector : SearchProperties | string | number

A generic value selector. For a textarea or input it should always be a string or number, for a select it can be a string or a SearchProperties.

Kind: global typedef