2.2.0 • Published 2 years ago

@dscribers/autosurf v2.2.0

Weekly downloads
118
License
MIT
Repository
github
Last release
2 years ago

autosurf

Installation

Include on page to test

<script src="https://cdn.jsdelivr.net/npm/@dscribers/autosurf/dist/autosurf.min.js"></script>

Use nodejs

yarn add @dscribers/autosurf

Usage

<script>
  const $surf = new AutoSurf()
  $surf
    .on('*', handleAllEvents)
    // This function directly passed to the init method of the adapter
    .ready(() => {
      $surf.schedules(schedulesArray).start()
    })
</script>

Config

const $surf = new AutoSurf({
  autoAdvance: false, // Indicates whether to automatically advance to the next step or not. Defaults to TRUE,
  defaultFailMessage: 'Something went wrong', // The default message for failed actions. It may be overridden by a more specific message, if available.
  typingSpeed: 500, // The speed for the typing action in milliseconds. Defaults to 100
})

All possible lists of dos and checks are properly documented in the BaseAdapter.

Methods

MethodParamsDescription
on(string) event, (function) callbackAdds an event listener
schedules(array) schedulesAn array of schedules to execute (See below)
pause-Pauses the execution
getBackupData-Fetches data that needs to be backed up
quit-Cleans up AutoSurf
ready(function) callbackSets the function to call when AutoSurf is ready to use
reconfigure(object) configUpdates the configuration on the fly
restart-Restarts the execution from the beginning
resume-Resumes a paused execution
start(object) configStarts the execution

Schedules

A schedules array consists of schedule objects which have the following structure:

// a schedule object

{
  "do": [
    {
      "action": "type",
      "params": ["John Doe"],
      "selector": "#inputName"
    }
  ],
  "check": [
    {
      "action": "valueIs",
      "selector": "#name",
      "params": ["John Doe"]
    }
  ]
}

Events

Events are triggered at different points of the execution. These can be used to monitor the execution.

The following is the list of events:

EventDescription
actionFailedTriggered when an action (do | check) fails
actionStartTriggered when starting to execute an action (do | check)
actionSuccessTriggered when an action executes successfully
doneTriggered when all the schedules have been executed
pausedTriggered when execution is paused
resumedTriggered when execution is resumed
scheduleFinishTriggered when all dos and checks in a schedule have been executed
scheduleInitTriggered when a schedule has been processed which is almost immediately after method schedules is called.
scheduleStartTriggered when starting to execute a schedule

Adapters

AutoSurf works with adapters to surf different devices and platforms. This is required.

Below is a list of available adapters:

How to build

Adapters are classes which must extend the BaseAdapter class.

import BaseAdapter from '@dscribers/autosurf/dist/base-adapter'

export default class MobileAdapter extends BaseAdapter {
  static init($autosurf, callback) {
    // initialize the adapter
  }

  static quit($autosurf) {
    // clean up the process
  }

  static doType(selector, str, speed = 500) {
    // select the element
    // type the str into the element at the given speed
    // throw new Error if something goes wrong
  }

  static checkValueIs(selector, value) {
    // select the element
    // check that the value of the element is the same as the given value
    // throw new Error if not the same
  }

  // ...
}

Usage

import AutoSurf from '@dscribers/autosurf'
import MobileSurf from 'mobile-surf-adapter'

$autosurf = new AutoSurf(new MobileSurf())

Methods

All methods in the BaseAdapter should be overridden as they are designed to fail by default.

MethodParamsDescription
init(AutoSurf) $autosurf, (function) callbackCalled to initialize the adapter
quite(AutoSurf) $autosurfCalled when AutoSurf finishes all executions
checkAttrContains(string) selector, (string) attribute, (string) textCalled to check if an element's attributes contains the given text
checkAttrIs(string) selector, (string) attribute, (string) textCalled to check if an element's attribute is the same as the given text
checkExists(string) selectorCalled to check if an element exists on the page
checkIsOn(string) urlCalled to check if the page is on the given url
checkElementIs(string) selector, (string) displayCalled to check if an element is either visible or hidden
checkTextContains(string) selector, (string) textCalled to check if the element's text contains the given text
checkTextIs(string) selector, (string) textCalled to check if element's text is matches the given text
checkValueContains(string) selector, (string) textCalled to check if the element's value contains the given text
checkValueIs(string) selector, (string) textCalled to check if the element's value matches the given text
doClick(string) selectorCalled to click on an element
doGoBack-Called to go back to a previous page
doWait(integer) millisecondsCalled to make pause the execution for the given milliseconds
doWaitTillPageLoads-Called to make the next execution wait until after the page finishes loading
doGoto(string) urlCalled to go to a url
doRefresh-Called to refresh the page
doSubmitForm(string) selectorCalled to submit the form with the given selector
doType(string) selector, (string) str, (integer) speedCalled to type the given string in the given element at the given speed.
2.2.0

2 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago