Appium Basic Test-参考:未定义

发布于 2025-02-11 05:14:49 字数 1617 浏览 0 评论 0 原文

我正在尝试按照此处所述进行Appium测试, https ://blog.logrocket.com/testing-your-react-native-native-app-with-appium/

但是,我遇到了一个错误 - 如何使我的基本测试工作?

> [email protected] test /Users/user/apps/myracnative/appium
> mocha test/basic


ReferenceError: beforeAll is not defined
    at Object.<anonymous> (/Users/user/apps/myracnative/appium/test/basic/index.js:16:1)

测试:

index.js

const wd = require("wd");
const jasmine = require("jasmine");
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
const PORT = 4723;

const config = {
    platformName: "iOS",
    platformVersion: "14.4",
    deviceName: "iPhone 11",
    app: "../../../apps/myracnative.ipa",
    automationName: "XCUITest", // UiAutomator2, Espresso, or UiAutomator1 for Android
};

const driver = wd.promiseChainRemote("localhost", PORT);

beforeAll(async () => {
    await driver.init(config);
});

test("Test Accessibilty Id", async () => {
    expect(
        await driver.hasElementByAccessibilityId("Create account")
    ).toBe(true);
    expect(await driver.hasElementByAccessibilityId("Log in")).toBe(true);
});

这是我的测试回购的链接:

I am trying to run an appium test as described here, https://blog.logrocket.com/testing-your-react-native-app-with-appium/

However, I get an error - how can I get my basic test to work?

> [email protected] test /Users/user/apps/myracnative/appium
> mocha test/basic


ReferenceError: beforeAll is not defined
    at Object.<anonymous> (/Users/user/apps/myracnative/appium/test/basic/index.js:16:1)

Test:

index.js

const wd = require("wd");
const jasmine = require("jasmine");
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
const PORT = 4723;

const config = {
    platformName: "iOS",
    platformVersion: "14.4",
    deviceName: "iPhone 11",
    app: "../../../apps/myracnative.ipa",
    automationName: "XCUITest", // UiAutomator2, Espresso, or UiAutomator1 for Android
};

const driver = wd.promiseChainRemote("localhost", PORT);

beforeAll(async () => {
    await driver.init(config);
});

test("Test Accessibilty Id", async () => {
    expect(
        await driver.hasElementByAccessibilityId("Create account")
    ).toBe(true);
    expect(await driver.hasElementByAccessibilityId("Log in")).toBe(true);
});

Here is a link to my test repo:

https://bitbucket.org/mharrisRAC/appium-example/src/master/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以往的大感动 2025-02-18 05:14:49

请参阅当前脚本中的以下更改,因为

  1. 将测试文件更新为 test.js 以使其在Local上执行,并
  2. 在以下脚本中进行更改,以使它们在Android设备上使用Android设备执行提供了apk文件,
  3. 添加了 setImpliticwaittimeout(50000)
  4. timeout 50000 jest beforeall()函数,
  5. 添加 timeout 50000 to Mocha test,
const wd = require("wd");
const jasmine = require("jasmine");
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
const PORT = 4723;

const config = {
    platformName: "android",
    // platformVersion: "11",
    // deviceName: "iPhone 11",
    // app: "../../../apps/myracnative.ipa",
    app: "/Users/ubuntu/Documents/tmp/appium-example/apps/app-release.apk",
    automationName: "uiautomator2", // UiAutomator2, Espresso, or UiAutomator1 for Android
};

const driver = wd.promiseChainRemote("localhost", PORT);

beforeAll(async () => {
    await driver.init(config).setImplicitWaitTimeout(50000);
}, 50000);

test("Test Accessibilty Id", async () => {
    expect(
        await driver.hasElementByAccessibilityId("Create a MyRAC account")
    ).toBe(true);
    expect(await driver.hasElementByAccessibilityId("Log in")).toBe(true);
}, 50000);

以下是您成功脚本执行的屏幕截图。

Please refer to the following changes in your current script as,

  1. Updated the test file as test.js to get them executed on local,
  2. Made the changes in the below script to get them executed on android device with the provided apk file,
  3. Added setImplicitWaitTimeout(50000) to the driver config,
  4. Added timeout of 50000 to jest beforeAll() function,
  5. Added timeout of 50000 to mocha test,
const wd = require("wd");
const jasmine = require("jasmine");
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
const PORT = 4723;

const config = {
    platformName: "android",
    // platformVersion: "11",
    // deviceName: "iPhone 11",
    // app: "../../../apps/myracnative.ipa",
    app: "/Users/ubuntu/Documents/tmp/appium-example/apps/app-release.apk",
    automationName: "uiautomator2", // UiAutomator2, Espresso, or UiAutomator1 for Android
};

const driver = wd.promiseChainRemote("localhost", PORT);

beforeAll(async () => {
    await driver.init(config).setImplicitWaitTimeout(50000);
}, 50000);

test("Test Accessibilty Id", async () => {
    expect(
        await driver.hasElementByAccessibilityId("Create a MyRAC account")
    ).toBe(true);
    expect(await driver.hasElementByAccessibilityId("Log in")).toBe(true);
}, 50000);

Following is the screenshot to your success script executions.
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文