Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dscribers/autosurf

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dscribers/autosurf

Automactically surf webpages from Gherkin config files

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • WebSurf

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.

FAQs

Package last updated on 04 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc