Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webdriverio-mocha-helper

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webdriverio-mocha-helper

Helper library for better webdriverio integration in mocha and additional helper method like feature detection and server versioning.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

webdriverio-mocha-helper

Helper library for a better webdriverio integration in mocha. The main purpose of webdriverio-mocha-helper is to provide you with helper methods.

Install

npm install webdriverio-mocha-helper --save

Migration

The Helper class needs the parameter options on creation. The options have to be taken from the local environment file env. Create a JavaScript file (e.g. WebdriverHelper) in the common directory::

import WebdriverHelper from 'webdriverio-mocha-helper';
const Env = require('./env');

const options = {
    desiredCapabilities: {
        browserName: Env.getBrowser(),
    },
    waitforTimeout: Env.getDefaultTimeout(),
    port: Env.getSeleniumPort(),
    host: Env.getSeleniumHost(),
    baseUrl: Env.getBaseUrl(),
    logLevel: 'silent',
    coloredLogs: true,
    screenshotPath: Env.getErrorScreenshotDir()
};

module.exports = (describe, it) => {
    const Webdriver = new WebdriverHelper(
        describe, it,
        options
    );
    return Webdriver;
};

Library Content

  • Helper.js
  • Features.js
  • commands.js
  • Webdriver.js
  • logger.js

Helper's guiTest & runTest

Helpers.js is the place where guiTest and runTest functions are called. To use the helper functions from the package use this statement at the beginning of the tests/spec files::

const Webdriver = require('../../common/WebdriverHelper')(describe, it);

Once imported and the const is declared you are ready use it in your tests.

withVersion Example test:

Webdriver.guiTest('Version check',
    function CheckoutTest() {
        Webdriver.guiTest('Version to high').withVersion('100.12.0', function VersionTest() {
            Webdriver.runTest('is not run because of version restriction', () => {
                return this.expect(true).to.equal.false;
            });
        });

        Webdriver.guiTest('Version passes').withVersion('4.12.0', function VersionTest() {
            Webdriver.runTest('is run because version restriction is fullfilled', () => {
                return this.client;
            });
        });
    });

Result:

Version check Version to high - is not run because of version restriction Version passes V is run because version restriction is fulfilled

Helper's pageAction

To abstract your test from specific markup selectors or specific commands you should always use page objects. A page object provides helpers for certain views and hold a composition of multiple WebdriverIO commands. The idea behind page objects is to keep your test simple and clear and to push reusability.

Example:

import {pageAction} from 'webdriverio-mocha-helper';
const Logger = require('../node_modules/webdriverio-mocha-helper/lib/logger');
const idLoginForm = '#loginForm';

module.exports = class Registration {
    constructor(client) {
        this.client = client;
    }

    @pageAction
    login(loginData) {
        Logger.info('logging in');
        return this.waitForExist(idLoginForm)
            .fillForm(idLoginForm, loginData, true);
    }
);

commands.js

As seen in the pageAction example the function fillForm is called. This function is added as an webdriverio command within the command.js:

function registerCommands(client) {
    client.addCommand('fillForm', function fillForm(formSelector, data, submit) {
    ...

There are several functions in the library which can be added in your tests.

Features.js

Features.js holds the testWrapperFactory which handles the withVersion and withFeatureEnabled methods. withVersion crosschecks the local environment files settings with the test file as seen in the withVersion example on top. withFeatureEnabled can block tests is the feature flag is set to false in the environment

Environment Example:

    "settings": {
        "versionUrl": "http://t.xxxlutz.at.tlz.local.netconomy.net/back/versioninfo"
},
    "features": {
        "checkout": true
    },
    ...

Keywords

FAQs

Package last updated on 25 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc