我正在使用 Selenium 和 Java 在 android 上运行脚本(通过 Appium 服务器)。我看到使用 selenium 来定位吐司是不可能的
driver.findElement(By.LinkText("User not logged in")
Run Code Online (Sandbox Code Playgroud)
在 Appium
但是可以在 Selendroid 中用于捕获 toast 消息。
有没有办法在同一个脚本中同时使用 Selendroid 和 Appium?
我进行了浓缩咖啡测试,希望应用程序在测试完成后保持准确的活动。我需要继续与应用程序交互。
@SmallTest
public void testOpenNavigationDrawer()
{
Espresso.onView(ViewMatchers.withId(com.eleks.espresso.example.app.R.id.content_frame)).perform(ViewActions.swipeRight());
ListView lvDrawerMenu = (ListView) getActivity().findViewById(com.eleks.espresso.example.app.R.id.lvDrawerMenu);
Preconditions.checkNotNull(lvDrawerMenu, "lvDrawerMenu is null");
final int count = lvDrawerMenu.getAdapter().getCount();
Preconditions.checkPositionIndex(2, count, "No 1 index " + count + " size");
Object obj = lvDrawerMenu.getItemAtPosition(2);
Espresso.onView(Matchers.allOf(ViewMatchers.withId(com.eleks.espresso.example.app.R.id.tvItem), ViewMatchers.hasSibling(ViewMatchers.withText(obj.toString())))).perform(ViewActions.click());
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢你!
我正在尝试使用 Espresso 创建简单的 UI 测试来为新创建的项目设置日期。
项目正在使用https://github.com/wdullaer/MaterialDateTimePicker,但它显示了具有复杂 UI 的对话框片段,没有什么可坚持的。
我想创建自定义 ViewAction 来设置类似于来自 Espresso 的 PickerActions 的日期或时间。
任何建议如何做到这一点?
我想在模型类中记录信息 - 不一定用于单元测试目的,而是用于我尝试调试的现实生活场景。
但是,如果我尝试使用android.util.Log方法,在运行 JUnit 测试时会出现以下错误:
java.lang.RuntimeException: Method d in android.util.Log not mocked. See http://g.co/androidstudio/not-mocked for details.
Run Code Online (Sandbox Code Playgroud)
我明白为什么会发生这种情况,我不应该在设计为独立于框架的模型类中使用 Android 框架代码!我并不是真的反对这个错误,而是我试图找到一种方法来解决这个问题。
我有一个想法,这有意义吗?
CustomLog沿着这些线创建一个类:
public class CustomLog {
private static ILogger mLogger;
public static void setLogger(ILogger logger) {
mLogger = logger;
}
public static void e(String tag, String message) {
mLogger.e(tag, message);
}
}
Run Code Online (Sandbox Code Playgroud)
ILogger具有执行日志功能所需方法的接口在哪里(e、d 等方法...)
我可以创建一个ILoggerImpl使用这些android.util.Log方法的MockLogger类,以及一个简单地打印出来System.out.println和/或什么都不做(或其他任何事情!)的类。
我认为这完全符合我的需求(我需要CustomLog在生命周期的早期设置我的类,但这不是什么大问题)。
但是,如果我需要将第三方库/外部代码添加到我的模型类中,如果新库/代码使用android.util.Log方法,这可能会以相同的方式再次中断。
那么,是否有我可以使用的“一网打尽”类型的行为?你怎么认为?
我正在使用 Android Espresso,当它找不到匹配项时,它会在打印视图层次结构时引发异常。当您运行 Android 测试或 Espresso 时,有没有办法动态获取这种视图层次结构
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+-->ViewStub{id=16909225, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=480, height=764, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, …Run Code Online (Sandbox Code Playgroud) 我的 AAR 清单中有一个占位符。当我使用 assembleRelease/assembleDebug 时,AAR 构建没有问题,但是当我运行我的 Android 检测测试时,gradle 无法构建检测 APK 并抛出一个错误,看起来像这样
Attribute <blah-blah>@<xyz> at manifestMerger....xml requires a placeholder substitution but no value for <my-place-holder> is provided.
Run Code Online (Sandbox Code Playgroud)
仅出于测试目的(并确认我是否可以为特定构建类型设置占位符的值),我在调试构建类型中设置了占位符值:
android { ... buildTypes { debug { manifestPlaceholders = [my-place-holder:"my-value"]
Run Code Online (Sandbox Code Playgroud)
它起作用了(发布版本保留了占位符,而在调试版本中替换了占位符)。但是,我不想(实际上也不应该)这样做,因为这意味着我的调试版本将覆盖 AAR 清单中的占位符,但我必须将占位符保留在清单中,以便我的 AAR 用户可以覆盖它.
有人知道如何仅将 manifestPlaceholders 分配给检测 APK?
我正在使用Android Test Orchestrator来运行我的 UI 测试,并且需要在所有测试完成后生成结果报告。我需要在编排器开始运行测试以及完成运行所有测试时进行回调,以便我可以生成并保存报告。
鉴于为每个测试创建了一个新实例AndroidJUnitRunner,我无法利用onStart()并finish()做到这一点。
我正在寻找一种方法来提供自定义编排器,以便我可以使用内部方法。
android android-testing android-espresso android-junit androidjunitrunner
我目前正在我的 Android 应用上测试 Google Play 的应用内订阅计费库。我已经创建了订阅并将我的应用程序发布到内部测试轨道。但是,当我尝试完成结算流程时,我的应用程序因未知原因崩溃。发生这种情况时我正在发送崩溃报告,但是当我在 ANR 和崩溃报告中查看我的 android 生命体征时,我的崩溃报告数据无处可寻。相反,谷歌控制台说我“没有发现所选标准的错误”。
为什么我的崩溃数据没有注册?我在这里做错了什么?我只想找出我的错误在哪里。我必须将我的应用程序作为一个版本进行测试,否则 google billing api 将无法工作。例如,当尝试在我的模拟器上进行测试时,我收到错误响应代码 5,它表示我的应用程序未设置为应用程序内计费。在内部测试轨道上进行测试时,我通过了此检查并开始了我的计费流程,但随后它就崩溃了。
请帮忙!
android android-testing android-billing android-developer-api google-play-developer-api
我编写了一些片段场景测试,这些测试将截取屏幕截图和一些点击事件。由于未显示图像视图,很少有测试失败。
测试库( https://developer.android.com/training/basics/fragments/testing )中的测试活动似乎使用 FragmentActivity,它不是 AppCompatActivity 的子类。结果,这些图像视图不可见。我可以添加属性android:src以使其在测试中可见,但这将是一个丑陋的修复。还有其他解决办法吗?
感谢对此的任何评论或建议。
view_item.xml
<ImageView
android:id="@+id/ivRemove"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="@dimen/spacing_16dp"
android:layout_marginTop="@dimen/spacing_16dp"
android:layout_marginBottom="@dimen/spacing_16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_remove" />
Run Code Online (Sandbox Code Playgroud)
构建.gradle.kts
defaultConfig {
this.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
this.vectorDrawables.useSupportLibrary = true
}
Run Code Online (Sandbox Code Playgroud) android android-testing android-vectordrawable android-fragmentscenario
我添加coreLibraryDesugaringEnabled到我们的应用程序中,它对于正常的应用程序运行来说工作得很好。
compileOptions {
coreLibraryDesugaringEnabled true
}
Run Code Online (Sandbox Code Playgroud)
和
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
Run Code Online (Sandbox Code Playgroud)
但是,当我运行连接测试时,它会崩溃,并且类上没有此类方法错误Stream:
16:03:56.426 11998 12041 E AndroidRuntime: FATAL EXCEPTION: com....
16:03:56.426 11998 12041 E AndroidRuntime: Process: ...
16:03:56.426 11998 12041 E AndroidRuntime: java.lang.NoSuchMethodError: No static method e([Ljava/lang/Object;)Lj$/util/stream/Stream; in class Lj$/util/n; or its super classes (declaration of 'j$.util.n' appears in /data/app/com....-qU6nwXthxze4O_9rcf1hGg==/base.apk!classes2.dex)
16:03:56.426 11998 12041 E AndroidRuntime: at j$.util.stream.Stream$-CC.of(:1000)
16:03:56.426 11998 12041 E AndroidRuntime: at ...
Run Code Online (Sandbox Code Playgroud)
我发现一些模糊的参考,这可能是因为在调用Multidex.install?之前引用了该类。我首先将该类引用为静态初始化程序,因此可以很早就访问它。不确定这是否是转移注意力,但我想我会提一下。
如果有帮助,则使用AndroidJUnit4ClassRunner.
编辑:我发现了一个模糊的参考,只有一篇文章指出仪器测试不支持这一点:
请注意,在 Android Studio 4.0 中,不支持在仪器测试中使用这些库脱糖类型。
https://medium.com/androiddevelopers/support-for-newer-java-language-apis-bca79fc8ef65
但即使是谷歌关于该功能的嵌入式视频也没有提及这一点。也不确定 …