typescriptwebdriver-ioapplitools

Error: Cannot find module 'selenium-webdriver/package.json' at import of @applitools/eyes-selenium


I am running my webdriverio 5 test with aplitools and I get this error:

[0-0] RUNNING in chrome - C:\MyProject\src\features\login.feature
[0-0] 2020-06-26T16:21:11.313Z ERROR @wdio/runner: Error: Cannot find module 'selenium-webdriver/package.json'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._resolveFilename (C:\MyProject\node_modules\tsconfig-paths\lib\register.js:75:40)
    at Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.hookedLoader [as _load] (C:\MyProject\node_modules\mockery\mockery.js:111:12)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (C:\MyProject\node_modules\@applitools\eyes-selenium\index.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.hookedLoader [as _load] (C:\MyProject\node_modules\mockery\mockery.js:111:12)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (C:\MyProject\src\config\applitools.ts:10:25)
[0-0] Error: Cannot find module 'selenium-webdriver/package.json'
[0-0] FAILED in chrome - C:\MyProject\src\features\login.feature

Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:10  

This is my applitools.ts file (line 10 is const {Configuration} = require('@applitools/eyes-selenium');):

import { config } from '.';

const {
ClassicRunner,
Eyes,
Target
// tslint:disable-next-line:no-var-requires
} = require('@applitools/eyes-webdriverio');
// tslint:disable-next-line:no-var-requires
const {Configuration} = require('@applitools/eyes-selenium');

class ApplitoolsService {
eyes: any;

async takeScreenshot(name: string) {
    const applitoolsConfig = config.applitools;

    if (applitoolsConfig.enabled === true) {
        let eyes: any;
        try {
            const runner = new ClassicRunner();

            eyes = new Eyes(runner);

            const configuration = new Configuration();
            configuration.setAppName('Sample Project');
            configuration.setTestName(name);

            eyes.setConfiguration(configuration);
            eyes.setApiKey(applitoolsConfig.key);

            await eyes.open(browser);

            const viewportSize = browser.getWindowSize();
            await eyes.check(name, Target.window(), viewportSize);

        } finally {
            await eyes.closeAsync();
        }
    } else {
        // tslint:disable-next-line:no-console
        console.log('Image comparison has been skipped, to activate it configure it in the index.ts file');
    }
  }
}
export default new ApplitoolsService();  

This is package.json file:

{
"name": "webdriverio_v5_typescript",
"version": "1.0.0",
"description": "Boilerplate project using version 5 WebdriverIO & TypeScript.",
"repository": "https://github.com/jpolley/WebdriverIO_v5_TypeScript",
"scripts": {
    "test": "wdio",
    "test:staging": "cross-env TEST_ENV='staging' wdio src/config/env/staging/staging.conf.js --spec src/features/login.feature",
    "test:testing": "cross-env TEST_ENV='testing' wdio src/config/env/testing/testing.conf.js --spec src/features/login.feature",
    "lint": "tslint --fix 'test/**/*.ts' && tslint --fix 'src/**/*.ts'",
    "report": "allure generate ./allure-results --clean && allure open",
    "report-ci": "allure generate allure-results --clean -o allure-report"
},
"author": "Jeremy Polley",
"license": "ISC",
"devDependencies": {
    "@applitools/eyes-selenium": "^4.31.24",
    "@applitools/eyes-webdriverio": "^5.8.4",
    "@types/chai": "^4.2.2",
    "@types/cucumber": "^4.0.5",
    "@types/node": "^10.14.18",
    "@wdio/allure-reporter": "^5.12.1",
    "@wdio/applitools-service": "^5.8.0",
    "@wdio/cli": "^5.13.0",
    "@wdio/cucumber-framework": "^5.16.12",
    "@wdio/local-runner": "^5.16.11",
    "@wdio/selenium-standalone-service": "^5.16.10",
    "@wdio/spec-reporter": "^5.12.1",
    "@wdio/sync": "^5.16.11",
    "allure-commandline": "^2.13.0",
    "chai": "^4.2.0",
    "chromedriver": "^78.0.1",
    "cross-env": "^7.0.2",
    "ts-node": "^7.0.1",
    "tsconfig-paths": "^3.9.0",
    "tslint": "^5.20.0",
    "typescript": "^3.6.3",
    "wdio-chromedriver-service": "^5.0.2",
    "webdriverio": "^5.16.11"
}
}

I don't know what the problem could be, it used to work before.
Can anyone help.


Solution

  • This is Sophie with Applitools.

    I see that you have both @applitools/eyes-webdriverio which is our SDK for WDIO 5 and @applitools/eyes-selenium which is for Selenium JS.

    If you would like to use wdio SDK you can remove @applitools/eyes-selenium from your package JSON and in your tests script take the Configuration object from the @applitools/eyes-webdriverio package.