Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get context in uiautomator test case?

I have my uiautomator test case:

public class clickTest extends UiAutomatorTestCase {   

   public void myTest() throws UiObjectNotFoundException {   
       ...
       //Is it possible to get Context or Activity here?  

   }
}

I am wondering, is it possible to get Context or Activity instance in UiAutomatorTestCase ?

Or How to get PackageManager in UiAutomatorTestCase ?

like image 342
Mellon Avatar asked Sep 08 '13 17:09

Mellon


1 Answers

In 2021 this is the answer:

To get a Context for the target application being instrumented. See details here: InstrumentationRegistry.getInstrumentation().getTargetContext();

To get the Context of the instrumentation's package. See details here: InstrumentationRegistry.getInstrumentation().getContext();

like image 138
Heitor Paceli Avatar answered Oct 04 '22 22:10

Heitor Paceli