npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webdriverio-mocha-helper

v1.0.1

Published

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

Downloads

8

Readme

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
    },
    ...