Created
December 11, 2015 07:16
-
-
Save codeskyblue/c53c8fd4b3ebacfa4eee to your computer and use it in GitHub Desktop.
uiautomator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.hzsunshx.helloworld; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.support.test.InstrumentationRegistry; | |
import android.support.test.uiautomator.By; | |
import android.support.test.uiautomator.UiDevice; | |
import android.support.test.uiautomator.UiObject; | |
import android.support.test.uiautomator.UiObject2; | |
import android.support.test.uiautomator.Until; | |
import android.test.InstrumentationTestCase; | |
import android.util.Log; | |
import java.io.IOException; | |
/** | |
* Created by hzsunshx on 2015/12/11. | |
*/ | |
public class MainActivityTester extends InstrumentationTestCase{ | |
private UiDevice device; | |
private static final String TARGET_PACKAGE = | |
InstrumentationRegistry.getTargetContext().getPackageName(); | |
private static final int LAUNCH_TIMEOUT = 5000; | |
@Override | |
public void setUp() throws Exception { | |
super.setUp(); | |
device = UiDevice.getInstance(getInstrumentation()); | |
} | |
public void testRun() throws Exception { | |
Log.i("HW", "test started"); | |
device.wakeUp(); | |
assertTrue("HW Should wakeUp", device.isScreenOn()); | |
device.pressHome(); | |
device.swipe(50, 1000, 800, 1000, 10); | |
// device.pressDPadRight(); | |
Log.i("HW", "product name: " + device.getProductName()); | |
Context context = InstrumentationRegistry.getContext(); | |
final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); | |
context.startActivity(intent); | |
device.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), LAUNCH_TIMEOUT); | |
Log.i("HW", "current package name: "+ device.getCurrentPackageName()); | |
Log.i("HW", "Launcher package name: " + TARGET_PACKAGE); | |
device.wait(Until.hasObject(By.text("ClickMe")), 3000); | |
UiObject2 clickMe = device.findObject(By.text("ClickMe")); | |
clickMe.click(); | |
device.wait(Until.hasObject(By.text("Hi 1")), 3000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment