node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



High-level abstraction for selenium-webdriver


  • Built with Selenium v3 and W3C WebDriver
  • Supports DOM API to explore page structure (via jsdom)
  • No setup: built in Chrome support (via chromedriver)
  • Flexibility: integrates with any test framework, node script, and selenium cloud provider.


Smoke test for using mocha and chai.

import { expect } from 'chai'
import { Browser } from 'sweb'
describe('smoke-tests', () => {
  let browser
  before(() => { browser = new Browser() })
  after(() => { browser.quit() })
  it('opens', async () => {
    const page = await'')
    expect(page.title).equal('Example Domain')


Requires node >= 6.9 (because of selenium-webdriver)

$ yarn add -D sweb
$ npm i -D sweb


new Browser(opts = {})

Creates new Browser instance.

Available options:

  • screenhostOnError (default: false) - make automatic screenshot when sweb throws a custom error, for example on failed waitFor or click.
  • workDir (default: ${cwd}/.sweb) - specify directory for sweb's logs and screenshots. If folder does not exist, it will be created automatically.
  • driver - custom build of WebDriver, useful for running different browsers or for Browserstack/Saucelabs integration. Check custom drivers section for more details.


Load url in browser and return Page instance.

Page instance has useful properties:

  • url - page url
  • document - similar to window.document, it's a jsdom instance with support of all DOM API methods.
  • title - page title
  • source - page html source
  • driver - WebDriver instance

await browser.quit()

Quit real browser.


Perform click event to selector.

await page.type(selector, text)

Send user type input (combination of keydown, keypress, keyup for each character) to selector with text. To emulate special keys like ENTER or F12 use Key.

import { Browser, Key } from 'sweb'
const browser = new Browser()
const page = await'')
await page.type('[name="q"]', `selenium webdriver npm${Key.ENTER}`)

await page.waitFor(selector, delay = 2000)

Wait for selector appears in html.

await page.screenshot(name)

Make screenshot of the page and store to ${browser.workDir}/${name}.png.

Custom drivers

driver option allows to pass custom selenium-webdriver configuration.

Firefox with geckodriver

import 'geckodriver'
import { Browser, Builder } from 'sweb'
const driver = new Builder().forBrowser('firefox').build()
const browser = new Browser({ driver })
const page = await'')

Integration with Browserstack

import { Browser, Builder } from 'sweb'
const driver = new Builder()
    'browserName': 'chrome',
    'browserstack.user': browserStackUser,
    'browserstack.key': browserStackKey,
    'browserstack.debug': 'true',
    'build': 'First build'
const browser = new Browser({ driver })
const page = await'')  

Integration with Saucelabs

import { Browser, Builder } from 'sweb'
const driver = new Builder()
  .usingServer('http://' + username + ':' + accessKey + '')
    'browserName': 'chrome',
    'platform': 'Windows XP',
    'version': '43.0',
const browser = new Browser({ driver })
const page = await'')