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

noflo-automaton

v0.1.6

Published

Automate navigation on the web based on Casper.js

Downloads

17

Readme

noflo-automaton

Build Status

Automate navigation on the web. This component library is built for NoFlo using Casper.js.

Given a URL and a rule object (structure described below), noflo-automaton would go through the rule object and try to reach the end, at which point the automaton would forward the accumulated output to its OUT port with the status number of 'true'.

If at any point it fails, the automaton would still forward the accumulated output but with the status number being the rule number in the provided rule object.

The Rule Object

To automate web navigation simply requires a list of rules to tell automaton what to look for, what to do if it is found, and which rule to execute next. The object is a simple JavaScript object containing an array of rules. It works virtually the same way as an assembly language does.

Rule Object API

For each rule, the automaton expects:

  • selector: The CSS3 selector to operate on
  • actions: An array of actions to perform (see below)
  • conditions: An array of conditions to test for success before moving on (see below)
  • name: optional An identifier so other rules can refer to this rule
  • on-success: optional The next rule to execute upon success. It refers to the rule by its name. Automaton scans forward for the name and does not go back in history. In other words, automaton will execute the first instance of the rules matching the name. If it's false, quit the program successfully. If it's true, the immediately next rule is executed. Default to true
  • on-failure: optional The next rule to execute upon failure. The same properties of determining the next rule to execute as for on-success apply.
  • test-timeout: optional Number of milliseconds to timeout before applying 'conditions'. Default to 0 miliseconds (i.e. immediately calling setTimeout() with 0 milliseconds)
  • retry-timeout: optional Number of milliseconds to timeout before retrying upon failure. Default to 0 milliseconds
  • retry-count: optional How many times to retry before giving up? Default to no retry (i.e. quit the program with a failure status number)

For each action in the actions array:

  • action: One of mouse and form events without the 'on' prefix. It also accepts 'value' which would change the value of an input and trigger the 'change' event.
  • selector: optional The element to perform the action on. Default to the element specified by the rule selector.

For each condition in the conditions array:

  • condition: The value to match on the element. This is a RegExp string. For instance, when class="page row item" and property is class, the condition is not going to match with ^row$. However, it would match with row.
  • name: optional An identifier for other conditions to refer to this
  • property: optional The attribute name (e.g. 'class') to test. Default to the content of the HTML element
  • selector: optional The selector to test the condition on. Default to the element specified by the rule selector.
  • on-success: optional The next condition by its name to test on success. If it's false, stop testing and assume success. If it's true, move on to the next condition. Default to true
  • on-failure: optional The next condition by its name to test on failure. If it's false, stop testing and assume failure. If it's true, move on to the next condition. Default to false

Examples

Click on all the row items and test that all item has the content 'Item' except the one marked with 'you' as ID.

[
  {
    "selector": "body #page .row",
    "actions": [
      { "action": "click" },
      { "action": "click", "selector": "body #page .row .item" }
    ],
    "conditions": [
      { "condition": "Item" },
      { "condition": "You", "selector": "body #page .row .item#you" }
    ]
  }
]

Data Structure

The automaton is essentially a looper that ends when there is a failure in satisfying the provided conditions or when it completes successfully (i.e. no more rules to apply). Along with the expectation that after each test and rule, there is a timeout to allow DOM events to fire, the flow must be completely stateless.

Therefore, each component in the automaton, including the graph automaton/automaton itself, expects the same inbound object, which follows the protocol of:

  • page: The DOM element of the page against which all selectors are executed.
  • rules: This is the rule obejct.
  • status: internal This is the current rule's offset in the rule object. This is used internally as a counter to refer to the the current rule to be applied as well as forwarded to OUT upon completion.
  • counts: internal This is a hash of counters used by some components in order to track when to quit upon repeated failures.

On OUT port from the graph automaton/automaton it outputs an object following this protocol:

  • status: true if it's successful. false if the provided page or rule object is not valid. The position of the rule in the rule object otherwise.
  • error: optional An error object or a string indicating the error message if any
  • page: The DOM element passed to the graph in the beginning
  • rules: The rule object passed to the graph in the beginning