Skip to content

[🐛 Bug]: getContext is not defined on SauceLabs iOS simulator #14044

@github-lucas-nou

Description

@github-lucas-nou

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.5.1

Node.js Version

20.18.1

Mode

WDIO Testrunner

Which capabilities are you using?

Here is the full browser options

{
  options: {
    rootDir: '...',
    specs: [ '...' ],
    suites: {},
    exclude: [],
    outputDir: undefined,
    logLevel: 'trace',
    logLevels: {},
    groupLogsByTestSpec: false,
    excludeDriverLogs: [],
    bail: 1,
    waitforInterval: 250,
    waitforTimeout: 5001,
    framework: 'mocha',
    reporters: [ 'spec', [Array] ],
    services: [ [Array] ],
    maxInstances: 12,
    maxInstancesPerCapability: 100,
    injectGlobals: true,
    filesToWatch: [],
    connectionRetryTimeout: 180000,
    connectionRetryCount: 4,
    execArgv: [],
    runnerEnv: {},
    runner: 'local',
    shard: { current: 1, total: 1 },
    specFileRetries: 0,
    specFileRetriesDelay: 0,
    specFileRetriesDeferred: false,
    reporterSyncInterval: 100,
    reporterSyncTimeout: 5000,
    cucumberFeaturesWithLineNumbers: [],
    mochaOpts: {
      timeout: 180000,
      ui: 'bdd',
      retries: 2,
      bail: true,
      allowUncaught: false,
      checkLeaks: true
    },
    jasmineOpts: { defaultTimeoutInterval: 10000 },
    cucumberOpts: { timeout: 10000 },
    onPrepare: [],
    onWorkerStart: [],
    onWorkerEnd: [ [Function: bound onWorkerEnd] ],
    before: [],
    beforeSession: [ [Function: bound beforeSession] ],
    beforeSuite: [],
    beforeHook: [],
    beforeTest: [ [Function: bound beforeTest] AsyncFunction ],
    beforeCommand: [],
    afterCommand: [],
    afterTest: [],
    afterHook: [],
    afterSuite: [],
    afterSession: [],
    after: [ [Function: bound after] AsyncFunction ],
    onComplete: [ [Function: bound onComplete] AsyncFunction ],
    onReload: [],
    beforeAssertion: [],
    afterAssertion: [],
    beforeFeature: [],
    beforeScenario: [],
    beforeStep: [],
    afterStep: [],
    afterScenario: [],
    afterFeature: [],
    _: [ 'run', 'run' ],
    '$0': './node_modules/.bin/wdio',
    'config-path': 'wdio.conf.ts',
    ignoredWorkerServices: [],
    user: '...',
    key: '...',
    region: '...',
    baseUrl: '',
    _automationProtocol: undefined,
    automationProtocol: './protocol-stub.js',
    capabilities: {
      platformName: 'iOS',
      browserName: 'safari',
      'appium:deviceName': 'iPhone Instant Simulator',
      'appium:platformVersion': 'latest',
      'appium:automationName': 'XCUITest',
      'sauce:options': [Object]
    }
  },
  capabilities: {
    platformName: 'iOS',
    browserName: 'safari',
    deviceName: 'iPhone Instant Simulator',
    platformVersion: 'latest',
    automationName: 'XCUITest',
    'sauce:options': {
      appiumVersion: '2.0.0',
      build: '...',
      tunnelIdentifier: '...'
    }
  },
  requestedCapabilities: {
    platformName: 'iOS',
    browserName: 'safari',
    deviceName: 'iPhone Instant Simulator',
    platformVersion: 'latest',
    automationName: 'XCUITest',
    'sauce:options': {
      appiumVersion: '2.0.0',
      build: '...',
      tunnelIdentifier: '...'
    }
  },
  customCommands: [],
  overwrittenCommands: [],
  commandList: [],
  getWindowHandle: [Function: NOOP2],
  on: [Function: NOOP2],
  off: [Function: NOOP2],
  addCommand: [Function (anonymous)],
  overwriteCommand: [Function (anonymous)],
  isChrome: false,
  isFirefox: false,
  isMobile: true,
  isIOS: true,
  isAndroid: false,
  isSauce: false,
  isBidi: false,
  isChromium: false,
  addLocatorStrategy: [Function (anonymous)]
}

What happened?

In ContextManager#initialize there is a call to this.#browser.getContext that have been safe-guarded against errors in these changes, but apparently there are cases where the getContext doesn't exists and having this.#browser.getContext?.() instead solved my issue and test could be ran.

However on android simulator / chrome windows I have 0 workers spawned, but tests are still running 🤔

What is your expected behavior?

Running tests on safari + correct count of workers

How to reproduce the bug.

Use SauceLabs iOS simulator with these capabilities (browser.isMobile is set to true):

{
   platformName: 'iOS',
   browserName: 'safari',
   deviceName: 'iPhone Instant Simulator',
   platformVersion: 'latest',
   automationName: 'XCUITest',
   'sauce:options': {
     ...
         }
}

Relevant log output

Execution of 0 workers started at 2025-01-02T12:19:49.990Z
...
[0-0] TypeError: this[#browser].getContext is not a function
[0-0]     at ContextManager.initialize (/Users/lucas.nouguier/Projects/service-web-formats/node_modules/webdriverio/build/index.js:3121:43)
[0-0]     at remote (/Users/lucas.nouguier/Projects/service-web-formats/node_modules/webdriverio/build/index.js:8075:33)
[0-0] 2025-01-02T12:20:03.839Z ERROR @wdio/runner: TypeError: this[#browser].getContext is not a function
[0-0]     at ContextManager.initialize (/Users/lucas.nouguier/Projects/service-web-formats/node_modules/webdriverio/build/index.js:3121:43)
[0-0]     at remote (/Users/lucas.nouguier/Projects/service-web-formats/node_modules/webdriverio/build/index.js:8075:33)
...
[0-0] 2025-01-02T12:20:11.458Z ERROR @wdio/runner: Error: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialized.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions