Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
314 lines (229 sloc) 7.65 KB
id title
plugins
Plugins

allure

Allure reporter

Enables Allure reporter.

Usage

To start please install allure-commandline package (which requires Java 8)

npm install -g allure-commandline --save-dev

Add this plugin to config file:

"plugins": {
    "allure": {}
}

Run tests with allure plugin enabled:

codeceptjs run --plugins allure

By default, allure reports are saved to output directory. Launch Allure server and see the report like on a screenshot above:

allure serve output
Configuration
  • outputDir - a directory where allure reports should be stored. Standard output directory is set by default.

Parameters

  • config

autoDelay

Sometimes it takes some time for a page to respond to user's actions. Depending on app's perfromance this can be either slow or fast.

For instance, if you click a button and nothing happens - probably JS event is not attached to this button yet Also, if you fill field and input validation doesn't accept your input - maybe because you typed value too fast.

This plugin allows to slow down tests execution when a test running too fast. It puts a tiny delay for before and after action commands.

Commands affected (by default):

  • click
  • fillField
  • checkOption
  • pressKey
  • doubleClick
  • rightClick
Configuration
"plugins": {
   "autoDelay": {
     "enabled": true
   }
}

Possible config options:

  • methods: list of affected commands. Can be overridden
  • delayBefore: put a delay before a command. 100ms by default
  • delayAfter: put a delay after a command. 200ms by default

Parameters

  • config

autoLogin

Logs user in for the first test and reuses session for next tests. Works by saving cookies into memory or file. If a session expires automatically logs in again.

For better development experience cookies can be saved into file, so a session can be reused while writing tests.

Usage

  1. Enable this plugin and configure as described below
  2. Define user session names (example: user, editor, admin, etc).
  3. Define how users are logged in and how to check that user is logged in
  4. Use login object inside your tests to log in:
// inside a test file
// use login to inject auto-login function
Before(login => {
   login('user'); // login using user session
});

// Alternatively log in for one scenario
Scenario('log me in', (I, login) => {
   login('admin');
   I.see('I am logged in');
});

Configuration

  • saveToFile (default: false) - save cookies to file. Allows to reuse session between execution.
  • inject (default: login) - name of the login function to use
  • users - an array containing different session names and functions to:
    • login - sign in into the system
    • check - check that user is logged in
    • fetch - to get current cookies (by default I.grabCookie())
    • load - to set cookies (by default I.setCookie(cookie))

Example: Simple login

autoLogin: {
  enabled: true,
  saveToFile: true,
  inject: 'login',
  users: {
    admin: {
      // loginAdmin function is defined in `steps_file.js`
      login: (I) => I.loginAdmin(),
      // if we see `Admin` on page, we assume we are logged in
      check: (I) => I.see('Admin'),
      // we take all cookies from a browser
      fetch: I => I.grabCookie(),
      // we set all available cookies to restore session
      restore: (I, cookie) => I.setCookie(cookie)
    }
  }
}

Example: Multiple users

autoLogin: {
  enabled: true,
  saveToFile: true,
  inject: 'loginAs', // use `loginAs` instead of login
  users: {
    user: {
      login: (I) => {
         I.amOnPage('/login');
         I.fillField('email', 'user@site.com');
         I.fillField('password', '123456');
         I.click('Login');
      }
      check: (I) => I.see('User', '.navbar'),
    },
    admin: {
      login: (I) => {
         I.amOnPage('/login');
         I.fillField('email', 'admin@site.com');
         I.fillField('password', '123456');
         I.click('Login');
      }
      check: (I) => I.see('Admin', '.navbar'),
    },
  }
}

Example: Keep cookies between tests

If you decide to keep cookies between tests you don't need to save/retrieve cookies between tests. But you need to login once work until session expires. For this case, disable fetch and restore methods.

helpers: {
   WebDriver: {
     // config goes here
     keepCookies: true; // keep cookies for all tests
   }
},
plugins: {
   autoLogin: {
    admin: {
      login: (I) => {
         I.amOnPage('/login');
         I.fillField('email', 'admin@site.com');
         I.fillField('password', '123456');
         I.click('Login');
      }
      check: (I) => I.see('Admin', '.navbar'),
      fetch: () => {}, // empty function
      restore: () => {}, // empty funciton
    }
  }
}

Parameters

  • config

retryFailedStep

Retries each failed step in a test.

Add this plugin to config file:

"plugins": {
    "retryFailedStep": {
       "enabled": true
    }
}

Run tests with plugin enabled:

codeceptjs run --plugins retryFailedStep
Configuration:
  • retries - number of retries (by default 5),
  • when - function, when to perform a retry (accepts error as parameter)
  • factor - The exponential factor to use. Default is 2.
  • minTimeout - The number of milliseconds before starting the first retry. Default is 1000.
  • maxTimeout - The maximum number of milliseconds between two retries. Default is Infinity.
  • randomize - Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.

This plugin is very basic so it's recommended to improve it to match your custom needs.

Parameters

  • config

screenshotOnFail

Creates screenshot on failure. Screenshot is saved into output directory.

Initially this functionality was part of corresponding helper but has been moved into plugin since 1.4

This plugin is enabled by default.

Configuration

Configuration can either be taken from a corresponding helper (deprecated) or a from plugin config (recommended).

"plugins": {
   "screenshotOnFail": {
     "enabled": true
   }
}

Possible config options:

  • uniqueScreenshotNames: use unique names for screenshot. Default: false.
  • fullPageScreenshots: make full page screenshots. Default: false.

Parameters

  • config

stepByStepReport

step-by-step-report

Generates step by step report for a test. After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow. By default, reports are generated only for failed tests.

Run tests with plugin enabled:

codeceptjs run --plugins stepByStepReport
Configuration
"plugins": {
   "stepByStepReport": {
     "enabled": true
   }
}

Possible config options:

  • deleteSuccessful: do not save screenshots for successfully executed tests. Default: true.
  • animateSlides: should animation for slides to be used. Default: true.
  • ignoreSteps: steps to ignore in report. Array of RegExps is expected. Recommended to skip grab* and wait* steps.
  • fullPageScreenshots: should full page screenshots be used. Default: false.
  • output: a directory where reports should be stored. Default: output.
Allure Reports

If Allure plugin is enabled this plugin attaches each saved screenshot to allure report.

Parameters

  • config any