All Projects → nuxt-contrib → Tib

nuxt-contrib / Tib

Easy e2e browser testing in Node

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tib

Marionette
Selenium alternative for Crystal. Browser manipulation without the Java overhead.
Stars: ✭ 119 (+85.94%)
Mutual labels:  selenium, webdriver, browser, puppeteer
Protractor
E2E test framework for Angular apps
Stars: ✭ 8,792 (+13637.5%)
Mutual labels:  selenium, test, webdriver, end-to-end
Singlefile
Web Extension for Firefox/Chrome/MS Edge and CLI tool to save a faithful copy of an entire web page in a single HTML file
Stars: ✭ 4,417 (+6801.56%)
Mutual labels:  selenium, browser, puppeteer
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+14237.5%)
Mutual labels:  test, e2e, browser
Query Selector Shadow Dom
querySelector that can pierce Shadow DOM roots without knowing the path through nested shadow roots. Useful for automated testing of Web Components. Production use is not advised, this is for test environments/tools such as Web Driver, Playwright, Puppeteer
Stars: ✭ 115 (+79.69%)
Mutual labels:  selenium, webdriver, puppeteer
Python Scripts
Collection of Various Python Script's.💻
Stars: ✭ 195 (+204.69%)
Mutual labels:  selenium, webdriver, browser
Nightwatch Cucumber
[DEPRECATED] Cucumber.js plugin for Nightwatch.js.
Stars: ✭ 243 (+279.69%)
Mutual labels:  selenium, test, browser
phoenix.webui.framework
基于WebDriver的WebUI自动化测试框架
Stars: ✭ 118 (+84.38%)
Mutual labels:  webdriver, test, selenium
page-modeller
⚙️ Browser DevTools extension for modelling web pages for automation.
Stars: ✭ 66 (+3.13%)
Mutual labels:  webdriver, selenium, puppeteer
Undetected Chromedriver
Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
Stars: ✭ 365 (+470.31%)
Mutual labels:  selenium, webdriver, browser
Webdriverio
Next-gen browser and mobile automation test framework for Node.js
Stars: ✭ 7,214 (+11171.88%)
Mutual labels:  test, webdriver
Java.appium
Mobile test automation using Appium in Java
Stars: ✭ 59 (-7.81%)
Mutual labels:  selenium, webdriver
Foxr
🦊 Node.js API to control Firefox
Stars: ✭ 783 (+1123.44%)
Mutual labels:  selenium, puppeteer
Socialmanagertools Igbot
🤖 📷 Instagram Bot made with love and nodejs
Stars: ✭ 699 (+992.19%)
Mutual labels:  selenium, puppeteer
Karma Event Driver Ext
use webdriverio like api in browser with karma lol
Stars: ✭ 17 (-73.44%)
Mutual labels:  webdriver, browser
Selendroid
"Selenium for Android" (Test automate native or hybrid Android apps and the mobile web with Selendroid.) Join us on IRC #selendroid on freenode. Also confirm you have signed the CLA http://goo.gl/pAvxEI when making a Pull Request.
Stars: ✭ 828 (+1193.75%)
Mutual labels:  selenium, webdriver
E2e Experiment
A demo project with Spring Boot / Angular application and e2e tests
Stars: ✭ 9 (-85.94%)
Mutual labels:  selenium, webdriver
Wdio Workshop
WebdriverIO Workshop
Stars: ✭ 20 (-68.75%)
Mutual labels:  selenium, webdriver
Marionette client
Mozilla's Gecko Marionette client in golang
Stars: ✭ 21 (-67.19%)
Mutual labels:  selenium, webdriver
Selenium Python
Selenium Python Bindings Documentation
Stars: ✭ 640 (+900%)
Mutual labels:  selenium, webdriver

test in browser (tib)

Build Status Coverage Status npm npm (scoped with tag)

Helper classes for e2e browser testing in Node with a uniform interface.

Introduction

tib aims to provide a uniform interface for testing with both jsdom, Puppeteer and Selenium while using either local browsers or a 3rd party provider. This way you can write a single e2e test and simply switch the browser environment by changing the BrowserString

The term helper classes stems from that this package wont enforce test functionality on you (which would require another learning curve). tib allows you to use the test suite you are already familair with. Use tib to retrieve and assert whether the html you expect to be loaded is really loaded, both on page load as after interacting with it through javascript.

Supported browsers/drivers/providers:

  • Puppeteer
    • -core
  • Selenium
    • Firefox
    • Chrome
    • Safari
    • IE (untested)
    • Edge (untested)
  • jsdom
  • BrowserStack

All browser/provider specific dependencies are peer dependencies and are dynamically loaded. You only need to install the peer-dependencies you plan to use

Features

  • Retrieve html as ASTElements (using vue-template-compiler)
  • Very easy to write page function to run in the browser
    • just remember to only use language features the loaded page already has polyfills for
    • syntax is automatically transpiled when browser version is specified
      • e.g. arrow functions will be transpiled to normal functions when you specify 'safari 5.1'
  • Supports BrowserStack-Local to easily tests local html files
  • Serve your local html files with a simple webserver
  • Automatically starts Xvfb for non-headless support (on supported platforms)
    • set xvfb: false if you want to specify DISPLAY manually

Documentation

Install

$ yarn add -D tib

Extra steps on Mac OS with Safari

Make sure to Enable WebDriver Support, see here for more information

Usage

import { createBrowser } from 'tib'

const browserString = 'firefox/headless'
const autoStart = false // default true
const config = {
  extendPage(page) {
    return {
      myPageFn() {
        // do something
      }
    }
  }
}

const browser = await createBrowser(browserString, config, autoStart)
if (!autoStart) {
  await browser.start()
}

Browser Strings

Browser strings are broken up into capability pairs (e.g. chrome 71 is a capability pair consisting of browser name and browser version). Those pairs are then matched against a list of known properties (see constants.js for the full list). Browser and provider properties are used to determine the required import (see browsers.js). The remaining properties should be capabilities and are depending on whether the value was recognised applied to the browser instance by calling the corresponding set<CapabilityName> methods.

API

Read the API reference

Example

also check our e2e tests for more information

import { createBrowser, commands: { Xvfb, BrowserStackLocal } } from 'tib'

const browserString = 'windows 10/chrome 71/browserstack/local/1920x1080'
// const browserString = 'puppeteer/core/staticserver'

describe('my e2e test', () => {
  let myBrowser

  beforeAll(async () => {
    myBrowser = await createBrowser(browserString, {
      // if true or undefined then Xvfb is automatically started before
      // the browser and the displayNum=99 added to the process.env
      xvfb: false,
      quiet: false,
      folder: process.cwd(),
      staticServer: {
        host: 'localhost', // or set process.env.HOST
        port: 3000 // or set process.env.PORT
      },
      // only used for BrowserStackLocal browsers
      BrowserStackLocal: {
        start: true, // default, if false then call 'const pid = await BrowserStackLocal.start()'
        stop: true,  // default, if false then call 'await BrowserStackLocal.stop(pid)'
        user: process.env.BROWSERSTACK_USER,
        key: process.env.BROWSERSTACK_KEY
      },
      extendPage(page) {
        return {
          getRouteData() {
            return page.runScript(() => {
              // this function is executed within the page context
              // if you use features like Promises and are testing on
              // older browsers make sure you have a polyfill already
              // loaded
              return myRouter.currentRoute
            })
          },
          async navigate(path) {
            await page.runAsyncScript((path) => {
              return new Promise(resolve => {
                myRouter.on('navigationFinished', resolve)
                window.myRouter.navigate(path)
              })
            }, path)
          }
        }
      }
    })
  })

  afterAll(() => {
    if (myBrowser) {
      await myBrowser.close()
    }
  })

  test('router', async () => {
    const url = myBrowser.getUrl('/')

    const page = await myBrowser.page(url)

    // you should probably expect and not log this
    console.log(await page.getHtml())
    console.log(await page.getElement('div'))
    console.log(await page.getElements('div'))
    console.log(await page.getElementCount('div'))
    console.log(await page.getAttribute('div', 'id'))
    console.log(await page.getAttributes('div', 'id'))
    console.log(await page.getText('h1'))
    console.log(await page.getTexts('h1, h2'))
    console.log(await page.getTitle())

    await page.navigate('/about')
    console.log(await page.getRouteData())

    console.log(await page.getTitle())
  })
})

FAQ

I receive a WebDriverError: invalid argument: can't kill an exited process error

Its a Selenium error and means the browser couldnt be started or exited immeditately after start. Try to run with xvfb: true

Known issues / caveats

  • If Node force exits then local running commands might keep running (eg geckodriver, chromedriver, Xvfb, browserstack-local)
    • workaround: none unfortunately
  • On CircleCI puppeteer sometimes triggers Protocol error (Runtime.callFunctionOn): Target closed error on page.evaluate. This could be related to a version mismatch between the browser and puppeteer.
    • workaround: use chrome/selenium
  • with Firefox you cannot run two page functions at the same time, also not when they are async
    • workaround: combine the functionality you need in a single page function
  • with Safari you can get ScriptTimeoutError on asynchronous page function execution. Often the timeout seems false as it is in ms and the scripts are still executed
    • workaround: wrap runAsyncScript calls in try/catch to just ignore the timeout :)

Todo's

  • local ie/edge
  • more platforms
    • SauceLabs (key required)
    • others?
  • increase coverage
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].