2017-05-02 23 views
-2

エスプレッソテスト中にスクリーンショットを取ろうとしています ここに私のコードがあり、getActivityメソッドを解決できません。getActivity()メソッドを解決できません

package com.lifehealth.irma.test.Screenshotscripts; 
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; 

//hamcrest 

@RunWith(AndroidJUnit4.class) 
@LargeTest 

// Name of the activity + Test 
public class Screencap { 
    //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 that tells the system which screen to start/boot up on this is telling the device to start from the main menu screen. 
    @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", getActivity()); 


//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

誰か助けてください! –

答えて

0

であり、これはgetActivity()メソッドは、アクティビティのコンテキストを与えます。 YourActivityName.thisを代わりに使用することができます。

getActivity() where it is defined?

が、これはあなたを助けることを願っています。

0

getActivityFragmentに使用されます。この場合は、getApplicationContext()またはYourClassName.thisを使用してください。

+1

ありがとうございました –

+0

これが役に立った場合、これを回答としてマークしてください。ありがとう –

関連する問題