【问题标题】:Why is appium throwing error when desired capability is using variable当所需功能使用变量时,为什么appium会抛出错误
【发布时间】:2019-11-28 17:51:55
【问题描述】:

我正在尝试编写测试自动化来记录完成后的测试结果,并且我需要记录设备名称和完成后的结果。

当我将所需的功能设备名称值设置为失败的变量时,一切似乎都可以正常工作。

let desiredCaps = {
        platformName: 'Android',
        platformVersion: '9',
        deviceName: Name,
        app: Apk,
        fullReset: false,
        automationName: "UiAutomator2"
    };

我已经通过将值更改为静态值进行了测试:

let desiredCaps = {
        platformName: 'Android',
        platformVersion: '9',
        deviceName: 'testDevice1',
        app: Apk,
        fullReset: false,
        automationName: 'UiAutomator2'
    };

它工作得很好,没有任何问题。

const Set_Desired_Device_Capabilities = async function Set_Desired_Device_Capabilities(Port, Name, Apk) {
    let driver = await wd.promiseChainRemote({
        host: '127.0.0.1',
        port: Port
    });
    let desiredCaps = {
        platformName: 'Android',
        platformVersion: '9',
        deviceName: Name,
        app: Apk,
        fullReset: false,
        automationName: 'UiAutomator2'
    };

    console.log(desiredCaps);
    await driver.init(desiredCaps);
    await driver.setImplicitWaitTimeout(30000);

};


module.exports = Set_Desired_Device_Capabilities;

使用上面的代码我最终得到了这个错误:

init(
     {
       "platformName":"Android",
       "platformVersion":"9",
       "deviceName":"testDevice1",
       "app":"/Users/username/Downloads/test.apk",
       "fullReset":false,
       "automationName":"UiAutomator2"
     }
  )
] Parse Error

是否有解决方法或更好的方法将设备名称作为变量传递?

【问题讨论】:

  • 只要变量里面存的是字符串应该没有问题。您能否粘贴您为设备名称初始化此变量的部分?

标签: android node.js appium


【解决方案1】:

发现问题:

问题在于我在导出函数中的异步作业。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-26
    • 2019-08-28
    • 2021-12-16
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    相关资源
    最近更新 更多