Testing React-Native Apps with Appium - The Ultimate Guide


(Skcript Bot) #1

Facebook’s Snapshot is great for ReactJS but for testing ReactNative applications it isn’t too effective as ReactNative renders native UI components. Appium is built on testing native apps and native components and is more effective than snapshot jest test. With Appium can be used to test both iOS and Android applications.

Minimum requirements

For iOS: It requires Mac OSX and with latest Xcode & command line tools

For Android: It requires Mac OSX or Windows or Linux OS with Android SDK >= 16

Getting started with Appium

For get started on testing with Appium it requires Appium in your machine with Appium standalone server and Appium java client.

Before you start running test for iOS applications, you need to Enable UI automation in your Developer settings (only for iOS)

You can now run test for your application.

Start tesing

Run Appium application to get started with testing and you can launch Appium server and inspect with this. You can start testing by selecting the targeted platform. You can config targeted platform by clicking on icon on targeted platform. It requires App path, bundle ID, UDID and targeted device for configuring targeted platform.

You can start testing by clicking launch button on Appium application. You can inspect individual UI components and whole UI container with Appium Inspector. Clicking on UI components on inspector you get details of component where you use this information for interaction while testing the app.

Start creating simple Java application with your IDE. You can grab the dependencies which are manually downloaded before. Make sure you import all dependencies before you run testing and add following code snippets for setting up app launch through Appium,

import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.Android.AndroidDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.net.MalformedURlException;
public class MyFirstTest {
  IOSDriver driver;
  @Before
  public void setup throws MalformedURlException() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapabilities("deviceName", "whatever");
    driver = new IOSDriver(new URL("APPIUM_SERVER_URL"), capabilities);    
  }
  @After
  public void tearDown() {
    driver.quit();
  }
}

Before action is used to start Appium connection with server and after action is used to quit Appuim connection. APPIUM_SERVER_URL is the Appium server end point.

Simple test action

You can test button’s click action creating a test method. Make sure you add test annotation before the method. First you need to find element. You need to find element by strategy like ID, path, name etc which is provided in the information Appium inspector window.

@Test
public void buttonClick() {
  driver.findElement(By.name("new button")).click();
}

You should run test after closing Appium inspector and restarting the server. You can now perform click action and result will be shown in the console 🙂

Try it out and tell us how it goes!


This is a companion discussion topic for the original entry at https://www.skcript.com/svr/testing-react-native-apps-with-appium-the-ultimate-guide/