Cannot read properties of undefined when attempting to run tests in parallel using Appium

Very new to Codecept JS, big fan so far.

I’ve been tasked with a proof of concept and demo for my test eng team to make the case to use this framework moving forward. A critical part of that proof of concept needs to be parallelization across multiple devices. Explicitly, running the same test across multiple android devices (eventually apple too, but one thing at a time) simultaneously.

Running tests on one device works perfectly. Here is the conf for that:

export const config: CodeceptJS.MainConfig = {
  tests: 'test/spec/*.spec.ts',
  output: './output',
  helpers: {
    Appium: {
      appiumV2: true,
      host: "hub-cloud.browserstack.com",
      port: 4444,
      user: process.env.BROWSERSTACK_USERNAME, 
      key: process.env.BROWSERSTACK_ACCESS_KEY, 
      app: process.env.BROWSERSTACK_UPLOADED_ANDROID_APP_ID,
      browser: '',
      platform: 'Android',
      device: 'Samsung Galaxy S23 Ultra',
      autoGrantPermissions: true,
      desiredCapabilities: {
        'platformName': 'android',
        'platformVersion':'13.0',
        'automationName': 'UIAutomator2',
        'newCommandTimeout': 300000,
        'androidDeviceReadyTimeout': 300000,
        'androidInstallTimeout': 90000,
        'appWaitDuration': 300000,
        'autoGrantPermissions': true,
      },
    },
  },
  include: {
    I: './steps_file'
  },
  name: 'codeceptJS-mobile-app-demo'
}

That runs beautifully. I did some digging on how to set up multiple devices with Appium as the helper and found that they get set up with different profiles. So I modified the conf like so:

    Appium: {
      appiumV2: true,
      host: "hub-cloud.browserstack.com",
      port: 4444,
      user: process.env.BROWSERSTACK_USERNAME, 
      key: process.env.BROWSERSTACK_ACCESS_KEY, 
      app: process.env.BROWSERSTACK_UPLOADED_ANDROID_APP_ID,
      autoGrantPermissions: true,
      browser: '',
      platform: 'Android',
      multiple:{
        profile1:{
          desiredCapabilities: {
            'device': 'Samsung Galaxy S23 Ultra',
            'platformName': 'android',
            'platformVersion':'13.0',
            'automationName': 'UIAutomator2',
            'newCommandTimeout': 300000,
            'androidDeviceReadyTimeout': 300000,
            'androidInstallTimeout': 90000,
            'appWaitDuration': 300000,
            'autoGrantPermissions': true,
          }
        },
        profile2:{
          desiredCapabilities: {
            'device': 'Samsung Galaxy S23',
            'platformName': 'android',
            'platformVersion':'13.0',
            'automationName': 'UIAutomator2',
            'newCommandTimeout': 300000,
            'androidDeviceReadyTimeout': 300000,
            'androidInstallTimeout': 90000,
            'appWaitDuration': 300000,
            'autoGrantPermissions': true,
          }
        },
      },
    },

Those same tests are failing almost instantly now with Cannot read properties of undefined (reading ‘waitUntil’)

That is on the 10th line of the login test I wrote.

To me, that suggests that the call isn’t making it out to browserstack; it is failing syntactically on an undefined value that hasn’t been initialized yet because browserstack hasn’t yet loaded the app.

Is that the case? If so, where do I go from here? Is there a way to force the test to wait until browserstack has finished loading?