Sequence

Sequence

Class representing a sequence of tests and actions to perform.

Constructor

new Sequence()

Source:
Examples

An example Sequence class from the README. This Sequence creates a Fragment and sets some basic steps to load the Google homepage and check if the image loads.

import { GOOGLE_FRAGMENT } from '../constants'
import { Sequence } from 'test-automation'
import GoogleFragment from '../fragments/GoogleFragment'

export default class GoogleSequence extends Sequence {
  constructor() {
    super()

    this.setFragment(GOOGLE_FRAGMENT, new GoogleFragment())

    this.setStep(() => this.getUrl('/'))
    this.setStep(this.getFragment(GOOGLE_FRAGMENT).testElements)
  }
}

A slightly more complex example Sequence class from the starter kit. This Sequence creates multiple Fragments and sets many steps to fill out the Google search form, perform a search for `www.google.com`, land on the results page, and go back to the homepage.

import { FORM_SELECTOR, INPUT_SELECTOR, LINK_SELECTOR, GOOGLE_FRAGMENT, RESULT_FRAGMENT } from '../constants'
import { Sequence } from 'test-automation'

import GoogleFragment from '../fragments/GoogleFragment'
import PageFragment from '../fragments/PageFragment'
import ResultFragment from '../fragments/ResultFragment'

export default class GoogleSequence extends Sequence {
  constructor () {
    super()

    const homepage = this.setFragment(GOOGLE_FRAGMENT, new PageFragment([new GoogleFragment()]))
    const resultpage = this.setFragment(RESULT_FRAGMENT, new ResultFragment())

    this.setStep([
      () => this.getUrl('/'),
      () => homepage.testElements(),
      () => homepage.elementSendKeys(INPUT_SELECTOR, 'something'),
      () => homepage.elementClear(INPUT_SELECTOR),
      () => homepage.elementSendKeys(INPUT_SELECTOR, 'www.google.com'),
      () => homepage.elementSubmit(FORM_SELECTOR),
      () => resultpage.testElements(),
      () => resultpage.elementClick(LINK_SELECTOR),
      () => homepage.testElements()
    ])
  }
}

Methods

getFragment(key) → {Fragment}

Gets the Fragment referenced by the key passed.
Source:
Parameters:
Name Type Description
key string | Symbol The unique key associated with the Fragment.
Returns:
Type:
Fragment
The associated fragment.

(async) getUrl(url) → {Promise}

[`async`] Getter method that gets the url specified to load in the browser.
Source:
Parameters:
Name Type Description
url string The relative url path to load.
Returns:
Type:
Promise
The promise representing the browser get call.

(async) runSequence() → {Promise}

[`async`] Method that runs the sequence of test steps previously specified.
Source:
Returns:
Type:
Promise
The promise chain of test steps.

setFragment(key, fragment) → {Fragment}

Sets the Fragment to be referenced by the key passed.
Source:
Parameters:
Name Type Description
key string | Symbol The unique key associated with the Fragment.
fragment Fragment The Fragment to associate with the key.
Returns:
Type:
Fragment
The associated fragment.

setStep(step)

Sets a test step to be run, in order, during the test pass.
Source:
Parameters:
Name Type Description
step function | Array.<function()> The function that wraps a test or action.