DEV Community

timeturnback
timeturnback

Posted on

Simplest way to Automatic test your React Native app with Appium

You must hear about automation test . The instruction you found with google do not statisfy you . Ok . Here is the shortest one to help you test with the Appium for React Native . Pls notice , this tutorial is for the short test and fastest ways to test , not provide fully document about all kind of test aspect .

Ok lets go .

First . Download Appium

Come here and get yoursefl a desktop version of Appium .

Then . Open it ( Appium )

Open the appium app , run the server. Note the port , here is 4723
image
Press Start Server.

Write the code .

You will need webdriverio,jest and jasmine install

yarn add -D webdriverio jest jasmine
Enter fullscreen mode Exit fullscreen mode

put this in appium/TestAppium.test.js ( or any directory if you know Jest )

import { remote } from "webdriverio";

// eslint-disable-next-line no-undef
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
let driver;

beforeAll(async () => {
  driver = await remote({
    path: "/wd/hub",
    host: "localhost",
    port: 4723,
    capabilities: {
      platformName: "iOS",
      platformVersion: "14.5", // must correct the stimuator
      deviceName: "iPhone 12 Pro Max", // must correct the stimuator
      appium: { connectHardwareKeyboard: true }
      // automationName: "XCUITest",
      // app: "org.reactjs.native.example.LearnRnE2eTest", // this is for open specify app
      // udid: process.env.IOS_DEVICE_UUID,
      // xcodeOrgId: "xxx",
      // xcodeSigningId: "Apple Development"
    }
    // logLevel: "silent"
  });
});

afterAll(async () => {
  if (driver) {
    await driver.deleteSession();
  }
});
test("Login test", async () => {
  await driver.pause(2000);

  const loginUsernameInput = await driver.$("~LoginInput");
  await loginUsernameInput.clearValue();
  await loginUsernameInput.setValue("TestAccount@test.com");
  await driver.hideKeyboard("pressKey", "next");

  const loginNextButton = await driver.$("~LoginNextButton");
  await loginNextButton.waitForExist();
  loginNextButton.click();
  await driver.pause(3000);

  const loginPasswordInput = await driver.$("~LoginPasswordInput");
  await loginPasswordInput.setValue("Test1234");
  const loginButton = await driver.$("~LoginButton");
  await loginButton.click();
  await driver.pause(3000);
});
Enter fullscreen mode Exit fullscreen mode

Input device setting must correct the emulator
image

To access the id like LoginButton , you must set it up in React Native

<GreenButton
  testID={"LoginNextButton"}
  title={'Login'}
/>
Enter fullscreen mode Exit fullscreen mode

testID with work on iOS

Run code with Jest

Ok . In conclusion , you will need those things to run

  1. Appium started
  2. Your app run on emulator ( through expo , react native metro (dev mode ) , stimulator app run on , ipa install on emulator ... any kind , just run the app , doesn't matter .. )
  3. Jest ready

Then run the test with jest

jest appium
Enter fullscreen mode Exit fullscreen mode

You can run jest only ( without appium , I put appium here beacause I put my test file in appium folder ).

And that is all . If you need more instructions , pls comment below so I can answer or make another tutorial for this .

Top comments (2)

Collapse
 
anabeatrizzz profile image
Ana Beatriz

Can I test using a real device, without the need of an emulator?

Collapse
 
jorgearuv profile image
Jorge Ruvalcaba

Thank you!