Appium basic test - ReferenceError: beforeAll is not defined

Viewed 46

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?

> webdriverio-sample-appium-tests@1.0.0 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/

1 Answers

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

Related