Skip to content

TypeError: Cannot read property 'token' of undefined issue  #142

Closed
@msaelices

Description

@msaelices

Which platform(s) does your issue occur on?

  • Android (not tested on iOS)
  • 8.0
  • emulator

Please, provide the following version numbers that your issue occurs with:

  • CLI: 4.1.1
  • Cross-platform modules: 4.1.1
  • Runtime(s): 3.4.1

Please, tell us how to recreate the issue in as much detail as possible.

Please reproduce the code below.

Is there any code involved?

Sample code:

    const appiumCaps = require('./appium.capabilities.json')[argv.runType];
    let args = {
      isSauceLab: argv.sauceLab || false,
      runType: argv.runType,
      appPath: argv.appPath, //'nativescriptvueuitests-debug.apk',
      appiumCaps: appiumCaps,
      verbose: argv.verbose || false,
    }

    AppiumDriver.createAppiumDriver(4723, args)
        .then(driver => run(driver))
        .then(() => console.log('Buh-Bye...'))
        .catch((err) => console.log(err));

Sample capabilities appium.capabilities.json file:

{
  "android23": {
    "automationName": "UiAutomator2",
    "platformName": "Android",
    "platformVersion": "6.0",
    "deviceName": "Android Emulator",
    "noReset": false,
    "avd": "Nexus_5X_API_27",
    "appPackage": "org.nativescript.nativescriptvueuitests",
    "appActivity": "com.tns.NativeScriptActivity"
  }
}

The error is caused because the createAppiumDriver() function calls to AppiumDriver.applyAdditionalSettings(args) which expects having an args.device argument, which is not present and it raises the Cannot read property 'token' of undefined.

But after that, the createAppliumDriver() function defines the args.device, so the sequence is:

    public static async createAppiumDriver(port: number, args: INsCapabilities) {
        ...
        if (!args.attachToDebug && !args.sessionId) {
            await AppiumDriver.applyAdditionalSettings(args);  // --> raises the error
        }
        ...
                        prepareApp(args);
                        if (!args.device) {
                            if (args.isAndroid) {
                                // --> but here we set the device (why later?) 
                                args.device = DeviceManager.getDefaultDevice(...);
                            } else {
                                args.device = DeviceManager.getDefaultDevice(args);
                            }
                        }

    }

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions