1
我正在嘗試運行帶截圖的esspresso測試。我的編碼體驗是非常基本的,如果任何人有一個簡單的解決方案,將是太棒了。 即時得到下面的堆棧跟蹤,當我試圖運行這個測試:無法在未調用Looper.prepare()的線程內創建處理程序新
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.app.Activity.<init>(Activity.java:794)
at com.lifehealth.irma.test.Screenshotscripts.Screencap.<init>(Screencap.java:70)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
以下是我的代碼:
import android.app.Activity;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import com.lifehealth.MainActivity;
import com.lifehealth.irma.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.doubleClick;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@LargeTest
// Name of the activity + Test
public class Screencap extends Activity {
//Strings to be typed into tests declaration
public static final String STRING_TO_BE_TYPED = "Test1233";
public static final String loginID = "LIFEHEALTH";
public static final String Device = "TestDevice";
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);
//@Test must be there to start a test if this is missing it will not run the test
@Test
public void Screencap1() { /* passes*/
//Enters login
onView(withId(R.id.editOid)) /*editTextUserInput*/
.perform(typeText(loginID), closeSoftKeyboard());
// then click next
onView(withId(R.id.btn_next)).perform(click());
// "Clicks the settings
onView(withId(R.id.btnSettings)).perform(click());
//Clicks Device Settings.
onView(withText("Device Settings")).perform(click());
//Scroll up
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Configure IRMA Base")).perform(swipeUp());
onView(withText("Barcode Reader Timeout")).perform(swipeUp());
onView(withText("Barcode Reader Timeout")).perform(swipeUp());
onView(withText("Barcode Reader Timeout")).perform(swipeUp());
//language
onView(withText("Language")).perform(doubleClick());
HelperClass.takeScreenshot("Whatever you want to call the file", Screencap.this);
//wait 1 min
try {
Thread.sleep(1 * 60 * 1000);
} catch (InterruptedException e) {
}
/* Clicks back button */
onView(withId(R.id.btn_back)).perform(click());
//clicks main menu button
onView(withText("Main Menu")).perform(click());
}
}
請幫忙!如果你可以 – fivestargamer
任何人????????? – fivestargamer
幫助!請任何人都可以 – fivestargamer