Error: Cannot find module 'selenium-webdriver/package.json' at import of @applitools/eyes-selenium
Error: Cannot find module 'selenium-webdriver/package.json' at import of @applitools/eyes-selenium
我正在 运行 我的 webdriverio 5 测试中使用 aplitools,我得到这个错误:
[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
这是我的 applitools.ts
文件(第 10 行是 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();
这是 package.json
文件:
{
"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"
}
}
不知道是什么问题,之前是可以的。
谁能帮忙。
我是使用 Applitools 的 Sophie。
我看到你有 @applitools/eyes-webdriverio 这是我们用于 WDIO 5 的 SDK 和 @applitools/eyes-selenium 这是用于 Selenium JS 的。
如果您想使用 wdio SDK,您可以从包 JSON 中删除 @applitools/eyes-selenium 并在测试脚本中从 @applitools/eyes-webdriverio 包中获取配置对象。
我正在 运行 我的 webdriverio 5 测试中使用 aplitools,我得到这个错误:
[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
这是我的 applitools.ts
文件(第 10 行是 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();
这是 package.json
文件:
{
"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"
}
}
不知道是什么问题,之前是可以的。
谁能帮忙。
我是使用 Applitools 的 Sophie。
我看到你有 @applitools/eyes-webdriverio 这是我们用于 WDIO 5 的 SDK 和 @applitools/eyes-selenium 这是用于 Selenium JS 的。
如果您想使用 wdio SDK,您可以从包 JSON 中删除 @applitools/eyes-selenium 并在测试脚本中从 @applitools/eyes-webdriverio 包中获取配置对象。