2017-05-02 10 views
1

現在、スクリーンショットを取るエスプレッソテストを実行しようとしています。私のコーディング経験は非常に基本的なものです。 私はこのテストを実行しようとすると、Imは、以下のスタックトレースを取得:Looper.prepare()を呼び出していないスレッド内でハンドラを作成できませんnew

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()); 

    } 



} 
+0

助けてください!あなたができる場合 – fivestargamer

+0

誰か????????? – fivestargamer

+0

助けてください!誰でもできることをしてください – fivestargamer

答えて

0

あなたは、あなたのテストクラスSCREENCAP活動を拡張して行うべきではありません。

アクティビティのコンストラクタで、Looper.prepare()を呼び出さなかったスレッド内でハンドラを作成しようとします。

関連する問題