CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Using CodeceptJS and Browserstack with localIdentifier does not work correctly.

Open satoshi-kawasaki opened this issue 3 years ago • 3 comments

What are you trying to achieve?

Hello,

I'm trying to run E2E tests using a combination of CodeceptJS + WebDriverIO and Browserstack.

Since the test needs to be run locally on a separate connection from the CI/CD Pipeline, the localIdentifier value is specified as follows:

codecept.config.js

desiredCapabilities: {
  project: "target",
  "browserstack.local": "true",
  "browserstack.debug": "true",
  "browserstack.networkLogs": "true",
  "browserstack.console": "errors",
  "browserstack.user": "dummyuser",
  "browserstack.key": "dummykey",
  "browserstack.networkLogs": "true",
  "browserstack.localIdentifier": uuidv4(),
},

startBrowserStackLocal.js

const bs_local = new browserstack.Local();
const bs_local_args = {
  key: "dummykey",
  forceLocal: true,
  localIdentifier:
    config.helpers.WebDriver.desiredCapabilities[
      "browserstack.localIdentifier"
    ],
};

bs_local.start(bs_local_args, function () {
  console.log(">>>> BrowserStack-local START.");
});

However, when you run the E2E test, you get the following error:

Please make sure Selenium Server is running and accessible
(node:31501) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sessionId' of undefined
    at Object._getSessionId (/Users/kawasakis91/workspace/develop/git/git_gs-cancellation-site/frontend/app/e2e/node_modules/codeceptjs-bshelper/index.js:100:47)
    at EventEmitter.<anonymous> (/Users/kawasakis91/workspace/develop/git/git_gs-cancellation-site/frontend/app/e2e/node_modules/codeceptjs-bshelper/index.js:94:28)
    at EventEmitter.emit (events.js:326:22)
    at EventEmitter.emit (domain.js:483:12)
    at Object.emit (/Users/kawasakis91/workspace/develop/git/git_gs-cancellation-site/frontend/app/e2e/node_modules/codeceptjs/lib/event.js:145:28)
    at /Users/kawasakis91/workspace/develop/git/git_gs-cancellation-site/frontend/app/e2e/node_modules/codeceptjs/lib/scenario.js:64:17
    at /Users/kawasakis91/workspace/develop/git/git_gs-cancellation-site/frontend/app/e2e/node_modules/codeceptjs/lib/recorder.js:233:9
(node:31501) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 70)
Error: Can't connect to WebDriver.
Error: Failed to create session.
[browserstack.local] is set to true but local testing through BrowserStack is not connected.

I am getting an error trying to access the value of a property that does not exist in the config file. Is this a bug?

Details

  • CodeceptJS version: 3.0.6
  • NodeJS Version: 12
  • Operating System: macOS
  • webdriverio:
  • Configuration file:
require("ts-node/register");

const { setHeadlessWhen } = require("@codeceptjs/configure");
const { v4: uuidv4 } = require("uuid");
const { mockServer } = require("./MockServer");

setHeadlessWhen(process.env.HEADLESS);

exports.config = {
  tests: "./spec/browserstack/*.spec.ts",
  output: `../../../testReport/frontend/codeceptjs-${process.env.STAGE}/output`,
  helpers: {
    WebDriver: {
      host: "hub-cloud.browserstack.com",
      path: "/wd/hub",
      url: "http://bs-local.com:8081",
      browser: "dummy",
      user: "dummyuser",
      key: "Dummykey",
      desiredCapabilities: {
        project: "projectname",
        "browserstack.local": "true",
        "browserstack.debug": "true",
        "browserstack.networkLogs": "true",
        "browserstack.console": "errors",
        "browserstack.user": "dummyuser",
        "browserstack.key": "Dummykey",
        "browserstack.networkLogs": "true",
        "browserstack.localIdentifier": uuidv4(),
      },
    },
    Mochawesome: {},
  },
  include: {
    ...
  },
  mocha: {
    reporterOptions: {
      reportDir: `../../../testReport/frontend/codeceptjs-${process.env.STAGE}`,
    },
  },
  name: "e2e",
  translation: "ja-JP",
  plugins: {
    pauseOnFail: {},
    autoDelay: {
      enabled: true,
    },
    retryFailedStep: {
      enabled: true,
    },
    tryTo: {
      enabled: true,
    },
    screenshotOnFail: {
      enabled: true,
    },
    stepByStepReport: {
      enabled: true,
      output: `../../../testReport/frontend/codeceptjs-${process.env.STAGE}/stepByStepReport`,
      fullPageScreenshots: true,
    },
    BrowserstackHelper: {
      require: "codeceptjs-bshelper",
      user: "dummyuser",
      key: "Dummykey",
      shortUrl: false,
      enabled: true,
    },
  },
  bootstrap: async () => {
    await mockServer.start();
  },
  teardown: async () => {
    await mockServer.stop();
  },
};

satoshi-kawasaki avatar Apr 14 '22 02:04 satoshi-kawasaki

https://codecept.discourse.group/t/local-testing-for-browser-stack/58

Or something changed 🤔

kobenguyent avatar Apr 15 '22 13:04 kobenguyent

@PeterNgTr Thank you for your reply to e's Browser.

I corrected it referring to the URL of the link you told me, but it doesn't work.

If I use a Browserstack Selenium server for E2E testing, do I need to set onlyAutomate in config?

satoshi-kawasaki avatar Apr 19 '22 08:04 satoshi-kawasaki

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Dec 14 '23 02:12 github-actions[bot]