Last active
August 29, 2015 14:17
-
-
Save YukiMatsumura/ed214becc5b1dd191be5 to your computer and use it in GitHub Desktop.
UIAutomator2.0を使ったAndroid UI Testの準備 ref: http://qiita.com/Yuki_312/items/c4e2138aff9fcaf02afd
This file contains 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
android { | |
defaultConfig { | |
minSdkVersion 18 // Requires Android 4.3 (API level 18) | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
packagingOptions { | |
exclude 'LICENSE.txt' // Duplicate files copied | |
} | |
} | |
dependencies { | |
// Testing-only dependencies | |
androidTestCompile 'com.android.support.test:testing-support-lib:0.1' | |
// UiAutomator Testing | |
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.0.0' | |
} |
This file contains 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
import android.support.test.filters.SdkSuppress; | |
import android.support.test.runner.AndroidJUnit4; | |
@RunWith(AndroidJUnit4.class) | |
@SdkSuppress(minSdkVersion = 18) | |
public class ApplicationTest { | |
} |
This file contains 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
// Copyright 2015, The Android Open Source Project | |
@Before | |
public void startMainActivityFromHomeScreen() { | |
// Initialize UiDevice instance | |
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | |
// Start from the home screen | |
mDevice.pressHome(); | |
// Wait for launcher | |
final String launcherPackage = getLauncherPackageName(); | |
assertThat(launcherPackage, notNullValue()); | |
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); | |
// Launch the blueprint app | |
Context context = InstrumentationRegistry.getContext(); | |
final Intent intent = context.getPackageManager() | |
.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances | |
context.startActivity(intent); | |
// Wait for the app to appear | |
mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment