android - 如何运行 Android UI 测试并将参数传递给 App/Activity
问题描述
我想使用一些预定义的数据为 Android 应用程序运行 UI 测试,这些数据会因测试用例而异。在 iOS 中,可以像这样将参数传递给被测试的应用程序:
app = XCUIApplication()
app.reset()
app.launchArguments += ["--myArgument"]
app.launch()
这些参数稍后在应用程序进程中可用。
Android UI测试有类似的东西吗?最好的方法是通过意图的附加功能访问这些参数。
getIntent().getExtras().getString(key)
感谢帮助!
解决方案
好吧,事实证明用Intents
. 在 Android UI 测试中,使用时ActivityTestRule
可以使用特定的Intent
.
@Rule
public ActivityTestRule<MainActivity> activityRule
= new ActivityTestRule<>(MainActivity.class, false, false);
Intent i = new Intent();
i.putExtra("specificArgument", argumentValue);
activityRule.launchActivity(i);
推荐阅读
- java - 如何保持已经通过电话登录的用户登录
- matlab - 创建一个大致等距点的球
- ios - SwiftUI NavigationView 在子视图中显示 ActionSheet、Popover 或 Sheet 会关闭子视图
- java - 红绿灯计划。爪哇。循环
- php - 在 S3 存储桶中上传图像:“s3”服务需要“区域”配置值
- python - 按 id 上的排名旋转 pandas 数据帧
- jenkins - 如何在 Prometheus 中获取 Jenkins 版本指标信息?
- r - R:按变量分组然后按另一个的出现计数/过滤
- chatbot - 将 bot 的卡片分享给 ms 团队中的另一个人
- python - 聚类标签绘图