cucumber not installed correctly?

35 Views Asked by At

I have a small dumb question for all you smart QA people! It goes like so...

How do you install cucumber correctly?

I keep getting the error

Error:

2024-03-14T15:23:08.851Z ERROR @wdio/runner: Error: 
You're calling functions (e.g. "When") on an instance of Cucumber that isn't running.
This means you have an invalid installation, mostly likely due to:
- Cucumber being installed globally
- A project structure where your support code is depending on a different instance of Cucumber
Either way, you'll need to address this in order for Cucumber to work.
See https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations

I have enabled the logs and and found cucumber is crashing and not doing it's thing. The appium installation log is connecting to the device and killing the sessions after each test is run, but wdio is showing that cucumber is crashing...

wido log:

2024-03-14T15:22:58.331Z INFO @wdio/local-runner: Run worker command: run
2024-03-14T15:22:58.568Z DEBUG @wdio/runner: init remote session
2024-03-14T15:22:58.571Z DEBUG @wdio/utils:initializeServices: initialize service "appium" as NPM package
2024-03-14T15:22:58.670Z INFO wdio-cucumberjs-json-reporter: The 'reportFilePerRetry' was not set, it has been set to the default 'true'
2024-03-14T15:22:59.112Z DEBUG @wdio/runner: init remote session
2024-03-14T15:22:59.113Z INFO webdriver: Initiate new session using the WebDriver protocol
2024-03-14T15:22:59.113Z INFO @wdio/utils: Connecting to existing driver at http://127.0.0.1:4723/
2024-03-14T15:22:59.122Z INFO webdriver: [POST] http://127.0.0.1:4723/session
2024-03-14T15:22:59.122Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      platformName: 'Android',
      'appium:sessionOverride': false,
      'appium:debugLogSpacing': true,
      'appium:connectionRetryTimeout': 30000,
      'appium:maxInstances': 1,
      'appium:maxInstancesPerCapability': 1,
      'appium:connectionRetryCount': 5,
      'appium:app': 'test.apk',
      'appium:automationName': 'UiAutomator2',
      'appium:nativeInstrumentsLib': true,
      'appium:isolateSimDevice': true,
      'appium:noReset': false,
      'appium:relaxedSecurity': true,
      'appium:get_server_logs': true,
      'appium:autoGrantPermissions': true,
      'appium:autoLaunch': true
    },
    firstMatch: [ {} ]
  },
  desiredCapabilities: {
    platformName: 'Android',
    'appium:sessionOverride': false,
    'appium:debugLogSpacing': true,
    'appium:connectionRetryTimeout': 30000,
    'appium:maxInstances': 1,
    'appium:maxInstancesPerCapability': 1,
    'appium:connectionRetryCount': 5,
    'appium:app': 'test.apk',
    'appium:automationName': 'UiAutomator2',
    'appium:nativeInstrumentsLib': true,
    'appium:isolateSimDevice': true,
    'appium:noReset': false,
    'appium:relaxedSecurity': true,
    'appium:get_server_logs': true,
    'appium:autoGrantPermissions': true,
    'appium:autoLaunch': true
  }
}
2024-03-14T15:23:08.851Z DEBUG @wdio/utils:shim: Finished to run "after" hook in 0ms
2024-03-14T15:23:08.851Z ERROR @wdio/runner: Error: 
          You're calling functions (e.g. "When") on an instance of Cucumber that isn't running.
          This means you have an invalid installation, mostly likely due to:
          - Cucumber being installed globally
          - A project structure where your support code is depending on a different instance of Cucumber
          Either way, you'll need to address this in order for Cucumber to work.
          See https://github.com/cucumber/cucumber-js/blob/main/docs/installation.md#invalid-installations
          
    at checkInstall (C:\workspace\ui-test\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:127:15)
    at C:\workspacei-test\node_modules\@cucumber\cucumber\src\support_code_library_builder\index.ts:145:11
    at Object.<anonymous> (C:\workspace\ui-test\test\step-definitions\service-steps.js:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Module.m._compile (C:\workspace\ui-test\node_modules\ts-node\src\index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Object.require.extensions.<computed> [as .js] (C:\workspaceu\ui-test\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
2024-03-14T15:23:08.871Z INFO webdriver: COMMAND deleteSession()
2024-03-14T15:23:08.871Z INFO webdriver: [DELETE] http://127.0.0.1:4723/session/a47d2b52-87f0-435b-96bf-6960c5da4172
2024-03-14T15:23:09.610Z INFO webdriver: RESULT null

Appium is doing it's thing just fine, but it seems that cucumber is giving me grief.

I have tried to remove the some cucumber packages and played with updating and downgrading the version, but I cannot seem to get cucumber to work.

package.json

{
  "name": "ui-test",
  "version": "1.0.0",
  "description": "testing",
  "main": "index.js",
  "scripts": {
    "test": "wdio lan.wdio.conf.js",
    "wdio": "wdio run wdio.conf.js"
  },
  "author": "x",
  "license": "ISC",
  "devDependencies": {
    "@wdio/allure-reporter": "8.29.2",
    "@wdio/appium-service": "8.29.1",
    "@wdio/cli": "8.29.1",
    "@wdio/cucumber-framework": "8.29.1",
    "@wdio/local-runner": "8.29.2",
    "@wdio/selenium-standalone-service": "8.15.0",
    "@wdio/sync": "7.27.0",
    "allure-commandline": "2.26.0",
    "appium": "2.5.1",
    "chai": "4.4.1",
    "chromedriver": "121.0.0",
    "cucumber": "6.0.7",
    "multiple-cucumber-html-reporter": "3.6.1",
    "ts-node": "10.9.2",
    "typescript": "5.3.3",
    "wdio-chromedriver-service": "8.1.1",
    "wdio-cucumberjs-json-reporter": "5.1.8",
    "webdriverio": "8.29.1",
    "appium-uiautomator2-driver": "^2.29.5",
    "@wdio/spec-reporter": "^8.16.3",
    "debug": "^4.3.4"
  },
  "dependencies": {
    "axios": "1.6.7",
    "request-promise-native": "1.0.9",
    "wdio-appium-service": "0.2.3"
  }
}

and according to npm why, (if I am reading this correctly, everything is fine... )

npm why output:

PS C:\Workspace\ui-test> npm why @cucumber/cucumber
npm WARN config optional Use `--omit=optional` to exclude optional dependencies, or
npm WARN config `--include=optional` to include them.
npm WARN config
npm WARN config     Default value does install optional deps unless otherwise omitted.
npm WARN config optional Use `--omit=optional` to exclude optional dependencies, or
npm WARN config `--include=optional` to include them.
npm WARN config
npm WARN config     Default value does install optional deps unless otherwise omitted.
@cucumber/[email protected] dev
node_modules/@cucumber/cucumber
  @cucumber/cucumber@"9.5.1" from @wdio/[email protected]
  node_modules/@wdio/cucumber-framework
    dev @wdio/cucumber-framework@"8.29.1" from the root project
PS C:\Workspace\ui-test>

Is there an easy was to fix this cucumber error?

Ta,

X

1

There are 1 best solutions below

0
Mr. E On

I managed to sort this out.

  1. use npm why @cucumber/cucumber to find all the installed cucumber installations, and remove all thw the extra ones from your package.json
npm why @cucumber/cucumber

@cucumber/[email protected] dev
node_modules/@cucumber/cucumber
  @cucumber/cucumber@"9.5.1" from @wdio/[email protected]
  node_modules/@wdio/cucumber-framework
    dev @wdio/cucumber-framework@"8.29.1" from the root project

if a good config, if you have multiple root entries, you will have to remove them.

so if you are using the wdio/cucumber-framework, you don't need to add @cucumber/cucumber into the package json as it will be already loaded...

  1. next use npm list --all to show the packages that are loaded with npm ....
+package1
+package2
+package3
+package4
+package5
-package6
-package7

if you have any packages with a '-' sign at the start, remove it. and at the bottom, npm will also alert you to the missing dependancies for you to add.

  1. The last bit is to just validate your wdio config.

IF you are running them in jenkins the wdio browsers should have a headless option set. Otherwise it will fail.