我的UiAutomator测试之一在我的某个测试设备上失败,因为
_uiDevice.openNotification()
无法打开通知区域。
与documentation of this function相反,我检索true
作为结果。
如果我设置了<item name="android:windowFullscreen">false</item>
(以前,这是true
),则会正确打开通知。
但是这个问题只发生在我的一个设备(Sony Xperia Z3)上,而另一个(三星Galaxy S5)成功打开通知,无论活动是否全屏。
我的(初始)风格:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="colorAccent">@color/ioxp_yellow</item>
</style>
在我的清单中:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:theme="@style/AppTheme" >
我测试的摘录:
@RunWith(AndroidJUnit4.class)
public class MainActivityAutomatorTest {
@Test
public void testNotifications() throws UiObjectNotFoundException, NoSuchMethodException,
NoSuchFieldException, IllegalAccessException,
InvocationTargetException, ClassNotFoundException
{
//...
Assert.assertTrue("Could not open device notifications", _uiDevice.openNotification());
String notificationString = context.getString(R.string.downloadService_title_workspace, serverWsId);
UiObject2 notification = _uiDevice.wait(Until.findObject(By.text(notificationString)),
UI_TIMEOUT);
Assert.assertNotNull(notification); // THIS FAILS
}
@Before
public void startMainActivityFromHomeScreen() {
// Initialize UiDevice instance
_uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
_uiDevice.pressHome();
// Wait for launcher
final String launcherPackage = _uiDevice.getLauncherPackageName();
Assert.assertNotNull(launcherPackage);
_uiDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), UI_TIMEOUT);
// Launch the app
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(BuildConfig.APPLICATION_ID);
Assert.assertNotNull(intent);
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// Wait for the app to appear
_uiDevice.wait(Until.hasObject(By.pkg(BuildConfig.APPLICATION_ID).depth(0)), UI_TIMEOUT);
}
}
这是自动化框架中的错误还是我做错了什么?