我正在尝试创建一个应用程序,该应用程序将在后台运行一个能够将触摸屏事件注入任何正在运行的活动的服务.我可以通过调用将事件注入到我的应用程序的一部分Activity中Instrumentation.sendPointerSync(motionEvent);但是如果我尝试在没有运行应用程序的活动的情况下执行此操作,则会收到权限错误,说我没有INJECT_EVENTS权限.我已将此权限添加到我的清单中,但是<uses-permission android:name="android.permission.INJECT_EVENTS"></uses-permission>它仍然会抛出相同的权限异常.经过一些搜索,我得到了答案,为了获得INJECT_EVENTS权限,您的应用必须使用与系统签名相同的签名进行签名.但我不清楚这究竟是什么意思.我将不得不找到一个自定义rom构建它并使用与该应用程序签名相同的签名对其进行签名.然后在我的设备上安装自定义ROM,然后安装我的应用程序,我将能够正确地注入触摸事件?如果是这样的话是我最好与已放在一起,就像一个自定义ROM开始从该页面或者是我要去的地方需要抢Android项目的git的副本,并建立整个事情的情况myslef?无论哪种方式,任何人都知道你可以指向我的地方,这会让我朝着正确的方向努力实现这一目标吗?
我想使用Espresso按下面按钮,但我不确定如何.我应该获得资源ID吗?或者如何设置AlertDialog的ID?
@RunWith(AndroidJUnit4.class)
public class ApplicationTest {
@Rule
public ActivityTestRule<LoadingActivity> mActivityRule =
new ActivityTestRule<>(LoadingActivity.class);
@Test
public void loginClickMarker() {
//Doesn't work:
onView(withText("GA NAAR INSTELLINGEN")).perform(click());
}
}
public class PopupDialog {
public static void showGPSIsDisabled(Context context, String msg, final PopupDialogCallback popupDialogCallback) {
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.location_turned_off))
.setMessage(msg)
.setPositiveButton(context.getString(R.string.go_to_settings), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
popupDialogCallback.hasClicked();
}
}).show();
}
}
Run Code Online (Sandbox Code Playgroud)
android.support.test.espresso.NoMatchingViewException:找不到层次结构中的视图匹配:with text:is"GA NAAR INSTELLINGEN"
我的浓缩咖啡仪器测试无法单击 ImageView:
在视图“id: com.example.test:id/btnNext”上执行“单击”时出错。
原因:android.support.test.espresso.PerformException:在视图“未知”上执行“单击(3 次尝试后)”时出错。
引起原因:android.support.test.espresso.InjectEventSecurityException:java.lang.SecurityException:注入到另一个应用程序需要 INJECT_EVENTS 权限
但奇怪的是,仅仅三行就可以单击另一个看起来与我非常相似的 ImageView。像人类一样使用该应用程序也是可行的。
这是我的最小的非工作示例,您看到错误了吗?
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TestTest {
@Rule
public ActivityTestRule<TestActivity> _activityRule = new ActivityTestRule<TestActivity>(
TestActivity.class);
@Test
public void testClicking() {
onView(withId(R.id.btnPrevious)).perform(click());
onView(withId(R.id.btnNext)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.btnNext)).check(matches(isClickable()));
onView(withId(R.id.btnNext)).perform(click()); // This line throws an exception
}
}
Run Code Online (Sandbox Code Playgroud)
要测试的活动:
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
}
}
Run Code Online (Sandbox Code Playgroud)
和布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:id="@+id/lytFooter">
<ImageView …Run Code Online (Sandbox Code Playgroud) 我无法执行我的 android espresso 单元测试并且它失败了:
// (kotlin syntax)
closeSoftKeyboard()
onView(withId(R.id.et_login_mobile_number)).perform(TypeTextAction(invalidMobileNo))
closeSoftKeyboard()
Run Code Online (Sandbox Code Playgroud)
androidx.test.espresso.InjectEventSecurityException:java.lang.SecurityException:注入另一个应用程序需要 INJECT_EVENTS 权限。
我终于了解到:在进行自动化测试的 UI 上出现的任何意外动画都可能会中断该过程。
所以我怀疑这是由于谷歌密码管理器提示保存的密码列表不断弹出,这可能是导致中断的原因。
我现在正在寻找的是:从建议保存的密码中关闭谷歌密码管理器的方式
我一直发现的是
并且无法关闭/禁用它
在我从 Google 密码管理器中删除所有保存的密码之后,现在它出现了建议自动填充文本(请比较两个屏幕截图)
我已经包含了如下属性,它仍然不会阻止自动填充到 Android 8 及更高版本的设备。
android:inputType="number|textNoSuggestions|textFilter"
Run Code Online (Sandbox Code Playgroud)
passwords android autocompletetextview android-layout android-espresso
我是一名 Android 开发人员,面临着一个非常严重的问题,但在任何地方都没有提到解决方案。
我正在尝试在我的 oneplus6t 上运行 Expresso 自动化测试。但是一年中的每一次我都无法测试。
错误信息是这样的:
"Testing started at 09:46 AM ...
04/20 09:46:21: Launching 'ASyncSettingsTest' on OnePlus ONEPLUS A6010.
Running tests
$ adb shell am instrument -w -r -e debug false -e class 'com.declaree.declaree.ASyncSettingsTest' com.demo.test/androidx.test.runner.AndroidJUnitRunner
Timed out waiting for process (com.demo) to appear on oneplus-oneplus_a6010-21663687."
Run Code Online (Sandbox Code Playgroud)
它适用于模拟器和其他制造设备,如像素、moto、三星。
我在开发人员选项中也没有找到类似的东西。
为了运行测试,我必须自己打开应用程序然后它才能运行。
仅供参考:重启、重置、擦除缓存不起作用。
我在 Android Studio 3.6.2 中工作
有人有任何解决方案吗?提前致谢。
这是我的代码:
onView(withId(R.id.first_name)).perform(
typeText("John"), closeSoftKeyboard());
SystemClock.sleep(5000);
onView(withId(R.id.last_name)).perform(typeText("Smith"));
Run Code Online (Sandbox Code Playgroud)
我从这里尝试了答案 Android:java.lang.SecurityException:注入到另一个应用程序需要INJECT_EVENTS权限 ,但没有帮助。
这是我使用的Expresso版本:
// Android Test Support Libraries
espressoRunnerVersion = "0.5"
espressoRulesVersion = "0.5"
espressoVersion = "2.2.2"
Run Code Online (Sandbox Code Playgroud)
这是完整的堆栈跟踪:
android.support.test.espresso.PerformException: Error performing 'type text(Smith)' on view 'with id: church.life.app:id/last_name'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:167)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:110)
at church.life.app.ui.profile.ProfileSignupTest.InvalidSignupTest(ProfileSignupTest.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
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) …Run Code Online (Sandbox Code Playgroud)