[英]Espresso Instrumentation Tests - how to uninstall or delete the app after the test
I setup Espresso instrumentation framework to run my Android Functional Automation tests. 我设置了Espresso工具框架来运行我的Android Functional Automation测试。 For every test, I want to login to the app and delete the app after I finish the test.
对于每个测试,我都想登录到该应用程序并在完成测试后删除该应用程序。
So, I setup something like below: 因此,我设置如下所示:
public class FirstSampleTest extends BaseTest { 公共类FirstSampleTest扩展了BaseTest {
private final BaseTest baseTest;
// private final ElementUtils elementUtils; //私有最终ElementUtils elementUtils;
public FirstSampleTest() throws InterruptedException {
this.baseTest = new BaseTest();
}
@Before
public void initiate() throws InterruptedException {
//I have setup login method here to login to the app after it installs
}
@Rule
public ActivityTestRule<SplashScreenActivity> splashScreenActivityActivityTestRule = new ActivityTestRule(SplashScreenActivity.class);
@Test
public void testTheHomeScreen() throws InterruptedException {
//Some tests go here.
}
@After
public void teardown() throws InterruptedException {
//I want to uninstall the app or delete it from the emulator once the test is run
}
}
Uninstalling the app from the Instrumentation tests is not possible. 无法从Instrumentation测试中卸载该应用。 However, once all the tests are run, the app is uninstalled automatically.
但是,一旦运行了所有测试,该应用程序将自动卸载。
Note: The app is not uninstalled only when a single test is run. 注意:仅当运行单个测试时,才会卸载应用程序。 Please run the whole build using the command ./gradlew connectedAndroidTest
请使用命令./gradlew connectedAndroidTest运行整个构建
You can add a gradle task in the Android Studio Before launch
section in Run -> Edit Configurations
. 您可以在
Run -> Edit Configurations
中的Android Studio Before launch
部分中添加gradle任务 。
Click +
-> Add a gradle-aware Make -> :app:uninstallAll
单击
+
->添加可识别gradle的Make-> :app:uninstallAll
note: "app" in :app:uninstallAll
depends on your main module name. 注意::
:app:uninstallAll
“ app”取决于您的主模块名称。 So it can be :my_module:uninstallAll
, or :company:uninstallAll
因此可以是
:my_module:uninstallAll
或:company:uninstallAll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.