WebdriverIO 5 tutorial

Note: This is for WebdriverIO 5. There are different tutorials for WebdriverIO 4 and WebdriverIO 6.

Getting Started with Applitools

Want to learn more about the Applitools platform and how it works? First get started with one of the following:

Running Tests with Applitools

Prerequisites
  1. A free Applitools account and Applitools API KEY

Tip: Unsure how to set up your API key?

Learn how to get started at Setting Up

  1. Node.js https://nodejs.org​

  2. Git https://git-scm.com​

Note: Installing `git` is optional

Installing git is used to clone the demo project from the Github repository. Instead of installing git, you can simply download the Zip file from the repository. Further, if you are Mac, you already have git.

  1. Selenium Standalone Server https://www.seleniumhq.org/download/

Note that this is a jar file

You should also have Java installed on your machine.

  1. Google Chrome Browser https://www.google.com/chrome/

  2. ChromeDriver https://chromedriver.chromium.org/getting-started

ChromeDriver must be installed and in your `PATH`

Below are some resources from the internet that'll help you

On Mac, place the chromedriver executable in /usr/local/bin folder so Eclipse and IntelliJ can find it.

Option 1 - Run With The Ultrafast Grid

Running the Example Project

  1. Clone or download the repository and navigate to that folder
git clone https://github.com/applitools/tutorial-webdriverio5-ultrafastgrid
cd tutorial-webdriverio5-ultrafastgrid
1
2

Note: you can alternatively download the project as a Zip file and extract it

  1. Run the standalone server jar file
java -jar selenium-server-standalone-3.141.59.jar
1

TIP

Replace the jar file name with your jar file name

  1. Install the dependencies
npm install
1
  1. Run the example test
APPLITOOLS_API_KEY="[Your API Key]" npm test
1

This will first set your APPLITOOLS_API_KEY into the node process then run npm test.

Adding Applitools Eyes to an Existing Node.js WebdriverIO Project

Install Applitools Eyes dependencies:

npm install @applitools/eyes-webdriverio webdriverio@5 --save-dev
1

Sample test

"use strict";

const chromedriver = require('chromedriver');
const {remote} = require('webdriverio');
const {
  By,
  Eyes,
  Target,
  VisualGridRunner
} = require('@applitools/eyes-webdriverio');
const {
  BrowserType,
  Configuration,
  DeviceName,
  ScreenOrientation
} = require('@applitools/eyes-selenium');

(async () => {
  chromedriver.start();

  // Open a Chrome browser.
  const chrome = {
    capabilities: {
      browserName: 'chrome'
    }
  };
  let driver = await remote(chrome);

  // Initialize the eyes SDK with 3 concurrent runners
  const eyes = new Eyes(new VisualGridRunner(3));

  try {
    const configuration = new Configuration();
    configuration.setAppName('Demo app');
    configuration.setTestName('WebdriverIO Visual Grid test!');

    //Add Chrome browser with two different viewports
    configuration.addBrowser(800, 600, BrowserType.CHROME);
    configuration.addBrowser(700, 500, BrowserType.CHROME);

    //Add Firefox browser with two different viewports
    configuration.addBrowser(1200, 800, BrowserType.FIREFOX);
    configuration.addBrowser(1600, 1200, BrowserType.FIREFOX);

    //Add iPhone 4 with Portrait mode
    configuration.addDeviceEmulation(DeviceName.iPhone_4, ScreenOrientation.PORTRAIT);

    // Set your private API key here or in the "APPLITOOLS_API_KEY" environment variable
    configuration.setApiKey(process.env.APPLITOOLS_API_KEY);
    eyes.setConfiguration(configuration);

    driver = await eyes.open(driver);

    // Navigate the browser to the "hello world!" web-site.
    await driver.url("https://demo.applitools.com");

    //⭐️To see visual bugs, change the above URL to:
    //  https://demo.applitools.com/index_v2.html and run the test again

    // Visual checkpoint #1.
    await eyes.check("Login Page", Target.window());

    // Click the "Log in" button.
    const el = await driver.findElement(By.id('log-in'));
    await el.click();

    // Visual checkpoint #2.
    await eyes.check("App page", Target.window());

    console.log(
      `Please wait, we are now..
      1. Uploading the app's resources (html, css, images)
      2. Rendering them in different browsers, emulators
      3. Analyzing them using our A.I.

      ...you should see the result within 15 - 60 seconds depending on your internet speed, # combinations and how heavy your app is.
    `
    );


    await eyes.closeAsync();
    // End the test.
    // const results = await eyes.close(); // will return only first TestResults, but as we have two browsers, we need more results
    const results = await eyes.getRunner().getAllTestResults(false);
    console.log(results);
    console.log(results.getAllResults());
  } finally {
    // Close the browser.
    await driver.deleteSession();

    // If the test was aborted before eyes.close was called ends the test as aborted.
    await eyes.abortIfNotClosed();

    chromedriver.stop();
  }
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Option 2 - Run Locally

Running the Example Project

  1. Clone or download the repository and navigate to that folder
git clone https://github.com/applitools/tutorial-webdriverio5-basic
cd tutorial-webdriverio5-basic
1
2

Note: you can alternatively download the project as a Zip file and extract it

  1. Run the standalone server jar file
java -jar selenium-server-standalone-3.141.59.jar
1

TIP

Replace the jar file name with your jar file name

  1. Install the dependencies
npm install
1
  1. Run the example test
APPLITOOLS_API_KEY="[Your API Key]" npm test
1

This will first set your APPLITOOLS_API_KEY into the node process then run npm test.

Adding Applitools Eyes to an Existing Node.js WebdriverIO Project

Install Applitools Eyes dependencies:

npm install @applitools/eyes-webdriverio webdriverio@5 --save-dev
1

Sample test

'use strict';

const chromedriver = require('chromedriver');
const {remote} = require('webdriverio');
const {
  ClassicRunner,
  Eyes,
  Target,
  Configuration
} = require('@applitools/eyes-webdriverio');

let browser;
let eyes;

describe('wdio5', function () {

  before(async function () {
    chromedriver.start();
  });

  beforeEach(async () => {
    const chrome = {
      capabilities: {
        browserName: 'chrome'
      }
    };
    browser = await remote(chrome);
  });

  afterEach(async () => {
    await browser.deleteSession();
    await eyes.abortIfNotClosed();

    const results = await eyes.getRunner().getAllTestResults(false);
    console.log(results);
    console.log(results.getAllResults());
  });

  after(async function () {
    chromedriver.stop();
  });

  it('Classic Runner Test', async () => {
    await browser.url('https://demo.applitools.com');

    const runner = new ClassicRunner();

    eyes = new Eyes(runner);

    const configuration = new Configuration();
    configuration.setAppName('Demo App');
    configuration.setTestName('Smoke Test');

    eyes.setConfiguration(configuration);
    await eyes.open(browser);

    await browser.url('https://demo.applitools.com');

    // Visual checkpoint #1.
    await eyes.check('Login Window', Target.window());

    // Click the "Log in" button.
    // await driver.click(By.id('log-in'));
    const loginButton = await browser.$('#log-in');
    await loginButton.click();

    // Visual checkpoint #2.
    await eyes.check('App Window', Target.window());

    await eyes.closeAsync();
  });

});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

Resources




Terms & Conditions Privacy Policy GDPR© 2021 Applitools. All rights reserved.

Last Updated: 6/24/2021, 10:09:59 AM