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

scholar-runner

v0.17.0

Published

NPM command line module for running scholar visual regression tests

Downloads

10

Readme

scholar-runner

NPM command line module for running visual regression tests

Synopsis

This is the client test runner for usage with the Scholar application.

Installation

npm install scholar-runner --save-dev

Usage

scholar-runner --help

Usage: scholar-runner [options]

  Options:
    -h, --help                                      Output usage information
    -V, --version                                   Output the version number
    -b, --browser <option>                          Define test browser (defaults to "phantomjs")
    -r, --runner <option>                           Define the runner for the tests e.g. local, remote (defaults to "local")
    --compareLocally                                Define to run the comparison locally (defaults to false)
    --seleniumVersion <version>                     Optionally use a specific selenium version
    --verbose                                       Define selenium log level
    -s, --suite <suite>                             Define file to run (optional)
    -t, --type <key>                                Define subset of tests to run (optional)
    -c, --config <filePath>                         Define config file location (defaults to "config/scholar.js")
    -d, --directory <testDirectory>                 Define test files directory (defaults to "process.cwd()/test/")
    -o, --output <imageDirectory>                   Define directory to place screenshots (defaults to "process.cwd()/test_images/")
    -r, --testReportDirectory <testReportDirectory> Define directory to place report html (defaults to "process.cwd()/test_images/")
    --baselineDirectory <baselineDirectory>         Define baseline files directory (defaults to "process.cwd()/baselines/")

Setup

Config

The minimum configuration required is:

module.exports = {
  baseUrl: 'http://the-website-you-want-to-test.com',
  scholarUrl: 'http://your-scholar-instance.com'
};

Adding Global Cookies to Config

Add required cookies to your config file,

module.exports = {
  baseUrl: 'http://the-website-you-want-to-test.com',
  scholarUrl: 'http://your-scholar-instance.com',
  cookies: [{
      'name': 'example',
      'value': 'exampleValue',
      'domain': '.example.com'
  }]
};

Remote Sessions

To run your tests against a remote Selenium server (ie BrowserStack / Saucelabs) you will need to:

  • Set the runner flag to remote
  • Set the host (required) and port number (optional) in your config file.
  • Set the user variable in config to your Selenium login (optional).
  • Set the key variable in config to your automation key (optional).

For Example:

module.exports = {
      baseUrl: 'http://the-website-you-want-to-test.com',
      scholarUrl: 'http://your-scholar-instance.com',
      host: 'http://your-Selenium-server.com',
      port: '1337',
      user: process.env.USER || 'user-name',
      key: process.env.SECRET_KEY || 'my-secret-key'
};

Running on BrowserStack:

  • Define the user variable as your BrowserStack user in config.
  • Define the key variable as your BrowserStack automation key in config.
  • If you want to test somewhere not internet accessible (localhost / internal domain etc) you will need to start up the browserstack local tunnel CLI. It's not included with this package, however the following should help get started:
    • wget https://www.browserstack.com/browserstack-local/BrowserStackLocal-YOURENVNAME-x64.zip && unzip BrowserStackLocal-YOURENVNAME-x64.zip
    • ./BrowserStackLocal -v -onlyAutomate -forcelocal $BROWSERSTACK_KEY &
  • If you are required to run BrowserStack with a local/private connection add browserstack.local:true to your config file.

An Example browserstack config:

{
    baseUrl: 'http://the-website-you-want-to-test.com',
    scholarUrl: 'http://your-scholar-instance.com',
    host: 'hub.browserstack.com',
    user: 'browserstack-user-name',
    key: 'browserstack-automation-key',
    browserstack: {
        'browserstack.local' : true,
        ie: {
            browser: 'IE',
            browser_version: '11',
            os: 'Windows',
            os_version: '8.1'
        },
        edge: {
            browser: 'Edge',
            browser_version: '12',
            os: 'Windows',
            os_version: '10'
        },
        safari: {
            browser: 'Safari',
            browser_version: '9.1',
            os: 'OS X',
            os_version: 'El Capitan'
        },
        chrome: {
            browser: 'Chrome',
            browser_version: '47',
            os: 'Windows',
            os_version: '7'
        }
    }
}

Writing Specs

Your first spec file

Within your test directory (defaults to test/) add your spec file. Ensure the ending contains '-spec.js';

let desktopSpecs = [
    {
        name: 'desktop-test-1',
        selector: 'body',
        path: '/'
    },
    {
        name: 'alex-test',
        selector: 'body',
        path: '/'
    }
];

let otherSpecs = [
    {
        name: 'other-test-1',
        selector: 'body',
        path: '/'
    },
    {
        name: 'other-test-2',
        selector: 'body',
        path: '/'
    }
];

module.exports = {
    desktop: desktopSpecs,
    another: otherSpecs,
    all: desktopSpecs.concat(otherSpecs) // default if no --type is provided
};

Advanced Options

There are other possible spec options such as:

  • name: String that will be the unique identifier within Scholar.
    • Example = "TestHeaderDesktop"
  • selector: CSS Selector to target specific elements.
    • Example = ".main.header"
  • url: Optional override of the global baseUrl.
    • Example = "alternative.domain.testing.com"
  • path: URL path to target page.
    • Example = "/myTestPage"
  • labels: An array allowing labelling / tagging of images for use within scholar
    • Example = ['homepage', 'carousel', 'hero']
  • loadTimeout: Milliseconds to allow page to stabilise before taking a screenshot (Defaults to 2000).
    • Example = 5000
  • setup: function that will be passed to the runner to allow events to happen after page loads (click on an accordion heading etc). MUST return the client
    • Example = function(client) { return client.waitForVisible('.n-button', 5000).click('.n-button'); }
  • setupTimeout: Milliseconds to allow page to stabilise after running a setup function (Defaults to 0).
    • Example = 2000
  • waitTimeout: Milliseconds to wait for required element to become visible (Defaults to 3000).
    • Example = 5000
  • viewportSize: JS Object with width and height properties.
    • Example = {width: 1280, height: 720}
  • cookies: Same format as the config options, however will only be included for the specific test.
    • Example = [ { name: 'first', value: 'test' }, { name: 'second', value: 'another' } ]

License

GNU