Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Jaimin180296/940eca5da18abae1cba6bb3f835e311e to your computer and use it in GitHub Desktop.
Save Jaimin180296/940eca5da18abae1cba6bb3f835e311e to your computer and use it in GitHub Desktop.
sample gist UI automator.
package com.mobilesla.testapp;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import java.io.IOException;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
protected UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
@Before
public void setup() throws IOException {
mDevice.executeShellCommand("am force-stop com.amazonaws.devicefarm.android.referenceapp");
}
@Test
public void useAppContext() throws IOException, UiObjectNotFoundException, InterruptedException {
mDevice.executeShellCommand("am start -n com.amazonaws.devicefarm.android.referenceapp/com.amazonaws.devicefarm.android.referenceapp.Activities.MainActivity");
Thread.sleep(5000);
mDevice.findObject(new UiSelector().className("android.widget.ImageButton")).click();
mDevice.findObject(new UiSelector().text("Web")).click();
mDevice.findObject(new UiSelector().text("http://www.amazon.com")).setText("https://www.google.com/");
mDevice.pressEnter();
UiObject settingsValidation = mDevice.findObject(new UiSelector().text("Sign in"));
Assert.assertTrue(settingsValidation.waitForExists(5000));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment