1.0.28 • Published 9 years ago

tamarin v1.0.28

Weekly downloads
62
License
ISC
Repository
github
Last release
9 years ago

Tamarin allows the tester/developer to concentrate on the functionality that needs to be tested rather than the boiler-plate code around it in order for the test to work.

I have often asked myself As a user would I ever click on an invisible link, type in a disabled field or select an item from a dynamically loaded dropdown that hadn't loaded yet? My answer was of course I wouldn't! so why do we have to write tests to make sure this doesn't happen? What if all that extra code was abstracted away and all you had to do was implement a one-line "click" and everything else was taken care of?

Tamarin can be used with or without cucumber.js.

Note the following files taken from the example project: tamarin-vanilla-example.

index.js

const googleSearch = require('./google_search')
googleSearch.test()
    .then(() => {
      console.log('Google search completed successfully')
      googleSearch.quit()
    })
    .catch((err) => {
      console.error('Google search failed')
      googleSearch.quit()
      throw err
    })

google_search.js

const World = require('./world').World
const world = new World()

const page = {
  'search': { css: '[title="Search"]' },
  'navLink': { xpath: '//*[@role="navigation"]//a[text()="Images"]' },
  'results': { css: 'img[alt="Image result for Tamarin"]' }
}

module.exports = {
  quit: () => world.quit(),
  test: () => world.visit('http://google.com')
    .then(() => world.waitForTitle('Google'))
    .then(() => world.sendKeys(page.search, 'Tamarin' + '\n'))
    .then(() => world.click(page.navLink))
    .then(() => world.waitFor(page.results))
}

world.js

'use strict'

const driver = require('./driver')
const tamarin = require('tamarin')

module.exports = {
  World: class extends tamarin {
    constructor () {
      super(driver())
    }
    quit () {
      return this.getDriver()
        .then((driver) => driver.quit())
    }
  }
}

driver.js

'use strict'

const webDriver = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const service = new chrome.ServiceBuilder(require('chromedriver').path).build()
chrome.setDefaultService(service)

module.exports = function () {
  return new webDriver.Builder()
    .withCapabilities(webDriver.Capabilities.chrome())
    .build()
}

Under the hood, tamarin waits until an element exists, is visible and enabled prior to performing such actions such as clicking a button or keying text into an input field.

API

tamarin contains the following functions within the tamarin world object:

  • setData (key, val)
  • getData (key) .. returns a promise resolving to the val of the key value pair
  • sleep (delay) .. returns a promise
  • visit (url) .. returns a promise
  • waitForTitle (title) ..returns a promise resolving to true if found
  • waitForCookie (cookieName) ..returns a promise resolving to a cookie
  • waitForUrl () ..returns a promise resolving to the current url
  • waitFor (seleniumselector) .._returns a promise resolving to a web element
  • whenExists (seleniumselector) .._returns a promise resolving to a web element
  • whenEnabled (seleniumselector) .._returns a promise resolving to a web element
  • whenDisabled (seleniumselector) .._returns a promise resolving to a web element
  • whenVisible (seleniumselector) .._returns a promise resolving to a web element
  • whenHidden (seleniumselector) .._returns a promise resolving to a web element
  • whenMatches (seleniumselector, val) .._returns a promise resolving to a web element
  • whenContains (seleniumselector, val) .._returns a promise resolving to a web element
  • sendKeys (seleniumselector, value) .._returns a promise resolving to a web element
  • hover (seleniumselector, delay) .._returns a promise resolving to a web element
  • click (seleniumselector) .._returns a promise resolving to a web element
  • getText (seleniumselector) .._returns a promise resolving to the text within the web element
  • getVal (seleniumselector) .._returns a promise resolving to the value of the web element

Install

As a dependency

Tamarin is available as an npm module.

$ npm i tamarin -D

More to come!

1.0.28

9 years ago

1.0.27

9 years ago

1.0.26

9 years ago

1.0.25

9 years ago

1.0.24

9 years ago

1.0.23

9 years ago

1.0.22

9 years ago

1.0.21

9 years ago

1.0.20

9 years ago

1.0.19

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.16

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.0

9 years ago

0.0.37

9 years ago

0.0.36

9 years ago

0.0.35

9 years ago

0.0.34

9 years ago

0.0.33

9 years ago

0.0.32

9 years ago

0.0.31

9 years ago

0.0.30

9 years ago

0.0.29

9 years ago

0.0.28

9 years ago

0.0.27

9 years ago

0.0.26

9 years ago

0.0.25

9 years ago

0.0.24

9 years ago

0.0.23

9 years ago

0.0.22

9 years ago

0.0.21

9 years ago

0.0.20

9 years ago

0.0.19

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago