Negligible Psychological Misery
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

bowow

0.8.2 • Public • Published

Bowow

A micro-library for browser automation.

Features

  • Tiny API (1 function + some helpers)
  • jQuery is always available
  • Synchronous API
  • Built directly on the w3c-webdriver spec.
  • Supports taking Screnshots
  • Supports mobile device emulation

Example Usage

Thie example searches Google and returns the list of urls returned on the first page.

const bowow = require('.')
 
bowow($ => {
  // Navigate to google
  $('https://www.google.com')
 
  // Type in "example"
  $('input[name=q]')
    .val('example')
    .blur()
 
  // Click on the Search button
  $(`input[type='button'][value='Google Search']`).click()
 
  // collect all links in search results
  return $('#res #search h3 > a').map((index, e) => $(e).attr('href'))
}).then(console.log) // outputs an array of urls

API

bowow($ => {...}, opts = { headless: false, device: null }) : Promise

Accepts a function that will receive a jQueryProxy. Supporting some configuration through the opts parameter.

$(fn : Function)

This is the core of the library. It performs the passed function in the browser context and returns the value the function returns.

$(selector, timeout = 30) : jQueryProxy

This is a helper that makes working with jQuery a trivial undertaking. When provided with a jQuery selector, $ acts like jQuery would, except it throws an exception if the selector fails to match any elements within the specifies timeout (in seconds). If you want to disable that check, pass in -1 as the timeout value.

$(selector).type('text')

Sends keystrokes to the targetted elements. Can be used to upload a file, like so: $('input[type=file]).type('/tmp/image.png').

$.screenshot() : path

Takes a screenshot and saves it to a temporary file, returing the full path to the file.

$(ms: number)

Waits synchronously for the number of milliseconds given.

$.downloads(wait = false) : string[]

Returns an array of all files in the download directory. If wait is true it'll wait until a new file appears in the directory.

install

npm i bowow

Downloadsweekly downloads

3

version

0.8.2

license

ISC

repository

githubgithub

last publish

collaborators

  • avatar