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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@actionlogementservices/wdio-test-context

v1.1.3

Published

A framework to add test context to webdriverio end to end tests.

Readme

wdio-test-context

A framework to add test context to webdriverio end to end tests.

  • It uses JSON files (named dataset) and optional javascript function to add dynamic content to your dataset.
  • It consumes a disposable mail service (YOPmail, maildrop or Guerilla Mail) in order to check for new message.
  • It provides pdf generation to enable document uploads.
  • It provides an Azure DevOps webdriverio reporter.
  • It generates a screenshot when the test fails.

Installation

  • In your webdriverio test project:

    npm install @actionlogementservices/wdio-test-context
  • Create a data folder

  • Create JSON files in the data folder: this will be your datasets.

  • Create a data/test-context.d.ts: this will add intellisense when you use your test context data within the spec files.

  • Create a data/test-context.js file with the following code:

    // import your own function to generate dynamic data
    import { generateRandomData } from './generate-random-data.js';
    import { TestContext } from '@actionlogementservices/wdio-test-context';
    
    // to enable intellisense with your own data
    /** @typedef {import('./test-context.d.ts').TestContextModel} TestContextModel */
    
    /** @type {TestContextModel & TestContext} */
    export const testContext = /** @type {TestContextModel & TestContext} */ (
      new TestContext()
        .setDataGenerator(generateRandomData) // optional : add your own dynamic data
        .setDefaultDataset('test') // default dataset name when DATASET env var is not specified
        .setEnvironment('local', {
          //define parameters for your environment
          frontUrl: 'https://test.lvh.me',
          backOfficeUrl: 'https://test-backoffice.lvh.me:4432',
          sso: true
        })
        .setEnvironment('staging', {
          frontUrl: 'https://staging.domain.com',
          backOfficeUrl: 'https://staging-backoffice.domain.com'
        })
        .initialize()
    );
  • Create optionnally data/generate-random-data.js to add dynamic data, file with the following code:

    import { faker } from '@faker-js/faker/locale/fr';
    import moment from 'moment';
    
    /** @typedef {import('@actionlogementservices/wdio-test-context/types').DataGenerator} DataGenerator */
    
    /** @type {DataGenerator} */
    function generateRandomData(_context) {
      // dates random
      const customDate = faker.date.between({ from: '1995-01-01', to: '2001-01-01' });
      return {
        customDate
      };
    }
    
    export { generateRandomData };
  • Configure optionnaly a RabbitMQ client if you plan to send some RabbitMQ message within your tests:

    NOTE

    • If you have secrets in your connection string, you need to

      • create a .env.{your_environment_name}.local file (for instance .env.staging.local) with your secret configuration parameters.

      • add the following entries to your .gitignore:

        .env.local.env.*.local

    export const testContext = /** @type {TestContextModel & TestContext} */ (
      new TestContext()
        .setEnvironment(
          'local',
          {
            frontUrl: 'https://test.lvh.me',
          },
          {
            amqp: String.raw`amqps://${process.env.RMQ_USER}:${process.env.RMQ_PWD}@your-host:5671/your-vhost`,
          }
        )
  • Configure webdriverio: in your wdio.conf.js:

    import { AdoReporter, TestContextWorkerService } from '@actionlogementservices/wdio-test-context';
    import { testContext } from './data/test-context.js';
    
    export const config = {
      ...
      reporters: [[AdoReporter, {}]],
      services: [[TestContextWorkerService, { testContext, logLevel: 'debug' }]],
      ...
    }

Notes on secrets

If you have secrets in your parameter values, you need to

  • create a .env.{your_environment_name}.local file (for instance .env.staging.local) with your secret configuration parameters:

    DB_PWD="MySyperStrongPassword"
    CLIENT_SECRET="MySuperSafeSecret"
  • references the secret in the environment.js like this:

    .setEnvironment('staging', {
      sql: 'Server=YourServer;Password=${process.env.DB_PWD};...'
  • to add the following entries to your .gitignore to prevent storing secret values in your repository:

    .env.local
    .env.*.local

Use the test context in the spec file

To access the mail service

  • Access the mailService property:

    import { testContext } from '../../environments.js';
    
    describe(`[Inbox] - ${testContext.user.email} - I`, () => {
    let confirmationLink;
      it('receive a mail with confirmation code within 10s', async () => {
        await browser.open(testContext.getParameter('frontUrl')); // to retrieve parameters
        const from = '[email protected]';
        const subject = `Confirmation code`;
        // to wait for email and to access test context data
        const content = await testContext.mailService.waitForMessage(testContext.user.email, from, subject);
        confirmationCode = getConfirmationCode(content);
        expect(confirmationCode).toContain('123456');
      });
    }

To execute SQL queries

  • You need to define a parameter in your environment.js that contains the sql connection string. In the following exemple it is named sqlBO.

    export const testContext = /** @type {TestContextModel & TestContext} */ (
      new TestContext()
        .setEnvironment(
          'local',
          {
            frontUrl: 'https://test.lvh.me',
            sqlBO: String.raw`Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\MSSQLLocalDB;Database=YourDatabase;Trusted_Connection=yes;`,
          }
        )

    NOTES on SQL connection string

    • If you plan to use (localdb) or Windows authentication this requires an ODBC driver with a specific connection string syntax : Driver={...}. You also need to check which Microsoft SQL Server ODBC driver is installed on your system with the ODBC Data Sources control panel.
    • For Microsoft Sql Server instance without Windows Authentication, there is no need to use an ODBC driver. In such case remove the Driver={...} portion of the connection string.
    • You can not mix both syntax in the same environment.
    • In the previous example, (localdb) is used with the ODBC Driver 17 for SQL Server which is installed.
  • Somewhere in you spec files

    import { testContext } from '../../environments.js';
    
    describe(`Before starting the test, we`, () => {
    
    it('check the sql version', async () => {
      const result = await testContext.executeSql('sqlBO', (sql) => sql.query('SELECT @@Version'));
      ...
    });

To publish AMQP message

  • You need to define a parameter in your environment.js that contains the amqp connection string. In the following exemple it is named amqpBO.

    export const testContext = /** @type {TestContextModel & TestContext} */ (
      new TestContext()
        .setEnvironment(
          'local',
          {
            frontUrl: 'https://test.lvh.me',
            amqpBO: String.raw`Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\MSSQLLocalDB;Database=YourDatabase;Trusted_Connection=yes;`,
          }
        )
  • Somewhere in you spec files

    import { testContext } from '../../environments.js';
    
    describe(`Before starting the test, we`, () => {
    
    it('send an amqp message', async () => {
      const result = await testContext.publishMessage('amqpBO',
        'exchange',             // your exchange name
        'routingKey',           // your routing key
        'type',                 // your message type
        { test: true },         // your message payload
        testContext.user.email  // something to correlate/track you message
      );
      expect(result).toBe(true);
    });

To run a VTOM job

  • You need to define a parameter in your environment.js that contains the VTOM configuration. In the following exemple it is named vtomBO.

    export const testContext = /** @type {TestContextModel & TestContext} */ (
      new TestContext()
        .setEnvironment(
          'local',
          {
            frontUrl: 'https://test.lvh.me',
            vtomBO: {
              url: 'https://...',
              apiKey: 'abcdef',
              environement: 'DEV'
            },
          }
        )
  • Somewhere in you spec files

    import { testContext } from '../../environments.js';
    
    describe(`Before starting the test, we`, () => {
    
    it('run a vtom job', async () => {
      const result = await testContext.runVtomJob('vtomBO', 'app', 'job');
      expect(result).toBe(true);
    });

Run your test

  • Specify the dataset with the DATASET env var and the environment with the TARGET_ENV env var

    TARGET_ENV=staging DATASET=full-scenario npx wdio
    or
    TARGET_ENV=staging DATASET=full-scenario npm test

Code documentation