first uiautomator test
This commit is contained in:
parent
f460571e7c
commit
bd08039fd1
|
|
@ -19,7 +19,9 @@ package com.nononsenseapps.filepicker.sample;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Environment;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiScrollable;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
|
@ -27,13 +29,19 @@ import android.support.test.uiautomator.UiDevice;
|
|||
import android.support.test.uiautomator.By;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UITest extends InstrumentationTestCase {
|
||||
|
||||
public static final String PKG_SAMPLE = "com.nononsenseapps.filepicker.sample";
|
||||
private static final long TIMEOUT = 10;
|
||||
private UiDevice mDevice;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
private static final String[] sTestFiles = new String[] {"zz.testfile1.zxvf", "zz.testfile2.zxvf"};
|
||||
|
||||
public void setUp() throws IOException {
|
||||
// Initialize UiDevice instance
|
||||
mDevice = UiDevice.getInstance(getInstrumentation());
|
||||
// Launch sample app
|
||||
|
|
@ -44,6 +52,19 @@ public class UITest extends InstrumentationTestCase {
|
|||
// Clear out any previous instances
|
||||
context.startActivity(intent);
|
||||
mDevice.wait(Until.hasObject(By.pkg(PKG_SAMPLE).depth(0)), TIMEOUT);
|
||||
|
||||
// Create a few files so we know something exists
|
||||
createTestFiles();
|
||||
}
|
||||
|
||||
private void createTestFiles() throws IOException {
|
||||
String folder = Environment.getExternalStorageDirectory().getPath();
|
||||
for (String filename: sTestFiles) {
|
||||
File file = new File(folder + "/" + filename);
|
||||
if (!file.exists()) {
|
||||
assertTrue(file.createNewFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
|
|
@ -54,5 +75,22 @@ public class UITest extends InstrumentationTestCase {
|
|||
assertTrue(sdButton.exists());
|
||||
|
||||
sdButton.click();
|
||||
|
||||
// Scroll to bottom and click on a test file
|
||||
|
||||
UiScrollable list = new UiScrollable(new UiSelector()
|
||||
.className("android.support.v7.widget.RecyclerView"));
|
||||
UiObject testFileItem = list.getChildByText(new UiSelector()
|
||||
.resourceId("com.nononsenseapps.filepicker.sample:id/nnf_item_container"),
|
||||
sTestFiles[0]);
|
||||
testFileItem.click();
|
||||
|
||||
// Press oK
|
||||
UiObject okButton = mDevice.findObject(new UiSelector().resourceId("com.nononsenseapps.filepicker.sample:id/nnf_button_ok"));
|
||||
okButton.click();
|
||||
|
||||
// Make sure result is displayed correctly
|
||||
UiObject resultField = mDevice.findObject(new UiSelector().textContains(sTestFiles[0]));
|
||||
assertTrue(resultField.exists());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue