Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android上运行第二次浓缩咖啡测试之前,先停止所有活动_Android_Automated Tests_Android Espresso - Fatal编程技术网

在Android上运行第二次浓缩咖啡测试之前,先停止所有活动

在Android上运行第二次浓缩咖啡测试之前,先停止所有活动,android,automated-tests,android-espresso,Android,Automated Tests,Android Espresso,我用的是黄瓜和浓缩咖啡。我有以下功能文件: Feature: From Main to Profile Background: Given User is registered And User is logged in @ios @android Scenario: User can navigate from the home screen to the profile screen Given User is on the home screen

我用的是黄瓜和浓缩咖啡。我有以下功能文件:

Feature: From Main to Profile 

  Background:
    Given User is registered
    And User is logged in

  @ios @android   Scenario: User can navigate from the home screen to the profile screen
    Given User is on the home screen
    When User taps Profile
    Then User is navigated to the profile screen

  @ios @android   Scenario: User can navigate from the profile screen back to the home screen
    Given User is on the Profile screen
    When User taps back
    Then User is navigated back to the home screen
在定义
的步骤中,用户被导航到配置文件屏幕
我必须添加一个
pressBack
,否则第二次测试的
main活动
启动不起作用(超时),我可以在模拟器上看到
ProfileActivity
仍然显示

这是
步骤
类:

public class MainActivitySteps extends BaseActivitySteps {

    public static final int PROFILE_BUTTON_ID = R.id.tvProfile;

    @Rule
    public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class);
    @Rule
    public GrantPermissionRule permissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);

    @Before
    public void setup() {
        activityTestRule.launchActivity(new Intent());
        activity = activityTestRule.getActivity();
        Intents.init();
    }

    @After
    public void tearDown() {
        activityTestRule.finishActivity();
        Intents.release();
    }

    @Given("^User is on the home screen")
    public void userIsAtMainScreen() {
        assertTrue(activity.findViewById(R.id.btnRecordTrip).getVisibility() == View.VISIBLE);
    }

    @When("^User taps Profile")
    public void userTapsProfile() {
        // wait for view to become visible
        userTaps(PROFILE_BUTTON_ID);
    }

    @Given("^User is on the Profile screen")
    public void userIsAtProfileScreen() {
        userTaps(PROFILE_BUTTON_ID);

    }

    @Then("^User is navigated to the profile screen")
    public void userIsNavigatedToTheProfileScreen() {
        intended(hasComponent(ProfileActivity.class.getName()));
        pressBack();
    }

    @When("^User taps back")
    public void userTapsBack() {
        pressBack();
    }

    @Then("^User is navigated back to the home screen$")
    public void userIsNavigatedBackToTheHomeScreen() {
        userIsAtMainScreen();
    }

}
public类MainActivitySteps扩展了BaseActivitySteps{
公共静态最终int PROFILE_按钮_ID=R.ID.tvProfile;
@统治
public ActivityTestRule ActivityTestRule=新ActivityTestRule(MainActivity.class);
@统治
public GrantPermissionRule permissionRule=GrantPermissionRule.grant(android.Manifest.permission.ACCESS\u FINE\u LOCATION);
@以前
公共作废设置(){
activityTestRule.launchActivity(new Intent());
activity=activityTestRule.getActivity();
Intents.init();
}
@之后
公共无效拆卸(){
activityTestRule.finishActivity();
意图。释放();
}
@给定(“^User在主屏幕上”)
公共无效用户isatMainScreen(){
assertTrue(activity.findViewById(R.id.btnRecordTrip).getVisibility()==View.VISIBLE);
}
@当(“^User taps Profile”)
public void userTapsProfile(){
//等待视图变为可见
用户点击(配置文件按钮ID);
}
@给定(“^User在配置文件屏幕上”)
public void userIsAtProfileScreen(){
用户点击(配置文件按钮ID);
}
@然后(“^User被导航到配置文件屏幕”)
public void用户被导航到EProfileScreen(){
预期(hasComponent(ProfileActivity.class.getName());
按Back();
}
@当(“^User点击后退”)
public void userTapsBack(){
按Back();
}
@然后(“^User被导航回主屏幕$”)
public void用户被导航回主屏幕(){
userIsAtMainScreen();
}
}
我发现这可能很有用,但我感到惊讶的是,我需要自己做这件事:在我看来,这是一个如此基本的功能。
在第一次测试之后,是否有更好的方法杀死
ProfileActivity

这就是我使用的:

dependencies {
    implementation "an androidx library:1.0.0"
    ...
}

android {
    defaultConfig {
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }

    testOptions {
        animationsDisabled true
        execution 'ANDROIDX_TEST_ORCHESTRATOR'

        unitTests {
            includeAndroidResources true
        }
    }
}
所以请注意,我对依赖项和编排器都使用了AndroidX

由于您没有使用AndroidX,因此需要使用执行“ANDROID\u测试\u ORCHESTRATOR”


如果您只是想终止这些活动,那么测试工具RunneArguments clearPackageData:“true”不是绝对必要的。

您有办法做到这一点吗?现在我被困在这件事上了。每次启动新应用程序之前,我都要重置我的应用程序test@Emjey您可以使用orchestrator。只需谷歌搜索或检查。是的,但当我这样做时,它会立即告诉我找不到任何测试,并且当我删除测试开始运行时。为什么当它说没有发现测试时,可能是配置有问题。您是否检查了导入的版本是否正确?例如,AndroidX
androidTestImplementation'com.android有不同的版本。支持:支持注释:28.0.0'
//用于检测测试
androidTestImplementation'com.android.support.test:runner:1.0.2'
//用于检测测试
testInstrumentationRunner“android.support.test.runner.AndroidJUnitRunner”
以及此,我将作为orchestrator.Is
实现“androidx.legacy:legacy-support-v4:1.0.0输入测试选项“
needed?我正在使用
implementation'com.android.support:appcompat-v7:28.0.0'
以及您提到的依赖项中遗留的所有其他内容。我仍然得到test not found这是启动的命令
adb shell CLASSPATH=$(pm path android.support.test.services)app_process/android.support.test.services.shellexecutor.ShellMain am instrument-r-w-e targetInstrumentation com.xyz.android.test/android.support.test.runner.AndroidJUnitRunner-e debug false-e class'com.xyz.android.Profile'-e clearPackageData trueandroid.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator
正在等待进程联机…`已开始运行测试测试运行失败:无测试结果如果不想使用AndroidX,则不需要它。在这种情况下,您需要使用ANDROID_TEST_ORCHESTRATOR而不是ANDROIDX_TEST_Orchestratories。我这样做了,但当我这样做并同步时,它说找不到任何测试。我还提供了关于它正在执行的命令的附加注释。我也有@Test注释。我不知道为什么它不被认可