- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Android SDK:22(长)UiAutomator 版本:'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
在单击按钮时,我正在尝试使用
从 Android 应用程序访问 InstrumentationBoolean start = false;
start = startInstrumentation(new ComponentName("com.automation.vzw.sanity.test", "android.test.InstrumentationTestRunner"), null, null);
System.out.println("value of start is " +start);
start 的值显示为“true”,表示已启动
问题是:一旦 Instrumentation 启动并调用 setUp(),当执行下面的代码时,会发生崩溃
public class ApplicationTest extends InstrumentationTestCase {
public void setUp() {
UiDevice testDevice = UiDevice.getInstance(getInstrumentation());
}
public void testCase1(){
System.out.println("In testcase1");
}
}
崩溃详情:
/TestRunner(11209): started: testCase1(com.automation.vzw.sanity.ApplicationTest)
I/TestRunner(11209): failed: testCase1(com.automation.vzw.sanity.ApplicationTest)
I/TestRunner(11209): ----- begin exception -----
I/TestRunner(11209):
I/TestRunner(11209): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.UiAutomation.setOnAccessibilityEventListener(android.app.UiAutomation$OnAccessibilityEventListener)' on a null object reference
I/TestRunner(11209): at android.support.test.uiautomator.UiAutomatorBridge.setOnAccessibilityEventListener(UiAutomatorBridge.java:78)
I/TestRunner(11209): at android.support.test.uiautomator.QueryController.<init>(QueryController.java:58)
I/TestRunner(11209): at android.support.test.uiautomator.UiAutomatorBridge.<init>(UiAutomatorBridge.java:66)
I/TestRunner(11209): at android.support.test.uiautomator.InstrumentationUiAutomatorBridge.<init>(InstrumentationUiAutomatorBridge.java:35)
I/TestRunner(11209): at android.support.test.uiautomator.UiDevice.<init>(UiDevice.java:103)
I/TestRunner(11209): at android.support.test.uiautomator.UiDevice.getInstance(UiDevice.java:263)
I/TestRunner(11209): at com.automation.vzw.sanity.ApplicationTest.setUp(ApplicationTest.java:103)
I/TestRunner(11209): at junit.framework.TestCase.runBare(TestCase.java:132)
I/TestRunner(11209): at junit.framework.TestResult$1.protect(TestResult.java:115)
I/TestRunner(11209): at junit.framework.TestResult.runProtected(TestResult.java:133)
I/TestRunner(11209): at junit.framework.TestResult.run(TestResult.java:118)
I/TestRunner(11209): at junit.framework.TestCase.run(TestCase.java:124)
I/TestRunner(11209): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
I/TestRunner(11209): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
I/TestRunner(11209): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
I/TestRunner(11209): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1944)
I/TestRunner(11209): ----- end exception -----
I/TestRunner(11209): finished: testCase1(com.automation.vzw.sanity.ApplicationTest)
I/ActivityManager(30686): Force stopping com.automation.vzw.sanity appid=10175 user=0: finished inst
I/ActivityManager(30686): Killing 11209:com.automation.vzw.sanity/u0a175 (adj 0): stop com.automation.vzw.sanity
I/ServiceManager(31912): Waiting for service SurfaceFlinger...
W/ActivityManager(30686): Spurious death for ProcessRecord{2a8ec647 11209:com.automation.vzw.sanity/u0a175}, curProc for 11209: null
注意:当从命令行执行时没有问题运行良好(am instrument -w com.automation.vzw.sanity.test/android.test.InstrumentationTestRunner)
请帮助克服这个问题
谢谢
最佳答案
这不是您获得仪器的方式。使用
Instrumentation instr = InstrumentationRegistry.getInstrumentation();
访问仪器。
然后就可以获得一个UiDevice对象:
UiDevice device = UiDevice.getInstance(instr);
关于android - 使用 startInstrumentation() 启动 Instrumentation 时 UiDevice.getInstance(getInstrumentation()) 崩溃(作为空对象引用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31474776/
我一直在尝试制作一个扩展 intstrumentationtestcase 的测试用例,每当我调用 getinstrumentation() 时,它都会返回 Instrumentation 的空实例而
我需要从 Android 测试(AndroidJUnit4ClassRunner)中获取资源。推荐的方法是什么,为什么? String some_res_string = androidx.test.
Android SDK:22(长)UiAutomator 版本:'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' 在单击按钮时,
我是一名优秀的程序员,十分优秀!