tamarin

1.0.28 • Public • Published

Tamarin

npm version Travis bitHound Code bitHound Overall Score Coverage Known Vulnerabilities bitHound Dependencies bitHound Dev Dependencies

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 (selenium_selector) ..returns a promise resolving to a web element
  • whenExists (selenium_selector) ..returns a promise resolving to a web element
  • whenEnabled (selenium_selector) ..returns a promise resolving to a web element
  • whenDisabled (selenium_selector) ..returns a promise resolving to a web element
  • whenVisible (selenium_selector) ..returns a promise resolving to a web element
  • whenHidden (selenium_selector) ..returns a promise resolving to a web element
  • whenMatches (selenium_selector, val) ..returns a promise resolving to a web element
  • whenContains (selenium_selector, val) ..returns a promise resolving to a web element
  • sendKeys (selenium_selector, value) ..returns a promise resolving to a web element
  • hover (selenium_selector, delay) ..returns a promise resolving to a web element
  • click (selenium_selector) ..returns a promise resolving to a web element
  • getText (selenium_selector) ..returns a promise resolving to the text within the web element
  • getVal (selenium_selector) ..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!

Package Sidebar

Install

npm i tamarin

Weekly Downloads

11

Version

1.0.28

License

ISC

Last publish

Collaborators

  • bsurgison