1

I am getting 2 issues
1- Cucumber Test functions in steps are not getting invoked unless i add @After or @Before before step class functions
2- The sequence of functions in steps are not accordingly. Last function getting called first and like wise. no regularity.

I am checking these by taking prints. Also by debugging.

This is what I have done:

In app/build.gradle

defaultConfig {
testApplicationId "com.my.app.test"
testInstrumentationRunner "com.my.app.test.CucumberInstrumentation"
}

sourceSets {
androidTest { assets.srcDirs = ['src/androidTest/assets'] }
}

buildTypes {
debug {
    testCoverageEnabled true
    buildConfigField "String", "TEST_TAGS", "\"${getTestTags()}\""
}
}

def getTestTags() {
    return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}

dependencies {
    androidTestImplementation 'info.cukes:cucumber-android:1.2.5'
    androidTestImplementation 'info.cukes:cucumber-picocontainer:1.2.5'
}

This is my feature file under the src/androidTest/assets/features directory.

Feature: Login
Perform login on email and password are inputted

@login-scenarios
Scenario: Input email and password in correct format
Given   Login screen is launched
When    I input an email, "[email protected]"
When    I input a password, "abc12345"
When    I press on Log in button
Then    I Should get logged in and redirect to home screen

This is my Login StepDefinitions file under the src/androidTest/java/com/my/app/test directory.

public class LoginStepdefs {
    @Rule
    private ActivityTestRule<LoginActivity> activityTestRule = new ActivityTestRule<>(LoginActivity.class);

    private LoginActivity activity;

    final static String Tag = "CucumberLogin: ";

    @Before("@login-scenarios")
    public void setUp() {
    System.out.println(Tag + "setUp in LoginStepdefs");
    activityTestRule.launchActivity(new Intent());
    activity = activityTestRule.getActivity();
    }

    @After("@login-scenarios")
    @Given("^Login screen is launched$")
    public void testLoginScreenIsLaunched() {
    System.out.println(Tag + "testLoginScreenIsLaunched");
    }

    @When("^I input an email, \"([^\"]*)\"$")
    public void iInputAnEmail(String email) {
    System.out.println(Tag + "iInputAnEmail: " + email);
    }

    @When("^I input a password, \"([^\"]*)\"$")
    public void iInputAPassword(String password) {
    System.out.println(Tag + "iInputAPassword: " + password);
    }

    @After("@login-scenarios")
    @When("^I press on Log in button$")
    public void iPressOnLogInButton() {
    System.out.println(Tag + "iPressOnLogInButton");
    }

    @After("@login-scenarios")
    @Then("^I Should get logged in and redirect to home screen$")
    public void iShouldGetLoggedInAndRedirectToHomeScreen() {
    System.out.println(Tag + "iShouldGetLoggedInAndRedirectToHomeScreen");
    }

    @After("@login-scenarios")
    public void tearDown() {
    System.out.println(Tag + "tearDown in LoginStepdefs");
    activityTestRule.finishActivity();
    }
}

Then this is my Runner file.

@CucumberOptions(
    features = "features",
    glue = "com.my.app.test")
public class CucumberInstrumentation extends MonitoringInstrumentation {

    private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);

    @Override
    public void onCreate(Bundle arguments) {
    super.onCreate(arguments);

    instrumentationCore.create(arguments);
    start();
    }
    @Override
    public void onStart() {
    super.onStart();

    waitForIdleSync();
    instrumentationCore.start();
    }
}

Now I am trying to run the cucumber tests with Android Studio like this:

  • Open “Edit Configuration”
  • Click + on left panel and select “Android Instrumented Tests”
  • Put a name you like to remember with at the Name field on top and select OK.
  • Click “Run”

Now i am getting prints in this sequence. Which is wrong.

CucumberLogin: setUp in LoginStepdefs
CucumberLogin: iPressOnLogInButton
CucumberLogin: iShouldGetLoggedInAndRedirectToHomeScreen
CucumberLogin: tearDown in LoginStepdefs
CucumberLogin: testLoginScreenIsLaunched

These are complete logs

E/libprocessgroup: failed to make and chown /acct/uid_10088: Read-only file system
04-12 12:04:07.246 3481-3481/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
04-12 12:04:07.246 3481-3481/? I/art: Not late-enabling -Xcheck:jni (already on)
04-12 12:04:07.262 3481-3481/com.my.app W/System.err: java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:456)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.openFile(FileOutput.java:67)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.startup(FileOutput.java:49)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Agent.startup(Agent.java:122)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Agent.getInstance(Agent.java:50)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at org.jacoco.agent.rt.internal_8ff85ea.Offline.<clinit>(Offline.java:31)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at com.my.app.di.MyApp.$jacocoInit(MyApp.java)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at com.my.app.di.MyApp.<init>(MyApp.java)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at java.lang.reflect.Constructor.newInstance(Native Method)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at java.lang.Class.newInstance(Class.java:1606)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.Instrumentation.newApplication(Instrumentation.java:995)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.Instrumentation.newApplication(Instrumentation.java:980)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4526)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.ActivityThread.access$1500(ActivityThread.java:151)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.os.Looper.loop(Looper.java:135)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err: Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at libcore.io.Posix.open(Native Method)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:442)
04-12 12:04:07.263 3481-3481/com.my.app W/System.err:   ... 23 more
04-12 12:04:07.264 3481-3481/com.my.app I/MultiDex: VM with version 2.1.0 has multidex support
04-12 12:04:07.264 3481-3481/com.my.app I/MultiDex: Installing application
04-12 12:04:07.264 3481-3481/com.my.app I/MultiDex: VM has multidex support, MultiDex support library is disabled.
04-12 12:04:07.291 3481-3481/com.my.app I/MonitoringInstr: Instrumentation started on process com.my.app
04-12 12:04:07.298 3481-3481/com.my.app I/MonitoringInstr: Setting context classloader to 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.my.app.test-2/base.apk", zip file "/data/app/com.my.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-2/lib/x86, /vendor/lib, /system/lib]]]', Original: 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.my.app.test-2/base.apk", zip file "/data/app/com.my.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-2/lib/x86, /vendor/lib, /system/lib]]]'
04-12 12:04:07.321 3481-3481/com.my.app D/cucumber-android: Found CucumberOptions in class com.my.app.test.CucumberInstrumentation
04-12 12:04:07.454 3481-3512/com.my.app I/MonitoringInstr: Setting context classloader to 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.my.app.test-2/base.apk", zip file "/data/app/com.my.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-2/lib/x86, /vendor/lib, /system/lib]]]', Original: 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.my.app.test-2/base.apk", zip file "/data/app/com.my.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-2/lib/x86, /vendor/lib, /system/lib]]]'
04-12 12:04:07.456 3481-3508/com.my.app W/AnalyticsUserIDStore: initStore should have been called before calling setUserID
04-12 12:04:07.456 3481-3512/com.my.app D/cucumber-android: Feature: Login (features/login.feature)
    Perform login on email and password are inputted
04-12 12:04:07.457 3481-3508/com.my.app W/UserDataStore: initStore should have been called before calling setUserID
04-12 12:04:07.462 3481-3512/com.my.app I/System.out: CucumberLogin: setUp in LoginStepdefs
04-12 12:04:07.468 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: PRE_ON_CREATE
04-12 12:04:07.470 3481-3481/com.my.app W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-12 12:04:07.493 3481-3481/com.my.app I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
04-12 12:04:07.495 3481-3481/com.my.app I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
04-12 12:04:07.497 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: CREATED
04-12 12:04:07.497 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: STARTED
04-12 12:04:07.497 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: RESUMED
04-12 12:04:07.499 3481-3519/com.my.app D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
04-12 12:04:07.500 3481-3481/com.my.app D/Atlas: Validating map...
04-12 12:04:07.527 3481-3519/com.my.app I/OpenGLRenderer: Initialized EGL, version 1.4
04-12 12:04:07.527 3481-3519/com.my.app W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
04-12 12:04:07.532 3481-3519/com.my.app D/EGL_emulation: eglCreateContext: 0xa1805dc0: maj 2 min 0 rcv 2
04-12 12:04:07.536 3481-3519/com.my.app D/EGL_emulation: eglMakeCurrent: 0xa1805dc0: ver 2 0
04-12 12:04:07.537 3481-3519/com.my.app D/OpenGLRenderer: Enabling debug mode 0
04-12 12:04:07.541 3481-3519/com.my.app D/EGL_emulation: eglMakeCurrent: 0xa1805dc0: ver 2 0
04-12 12:04:07.601 3481-3512/com.my.app D/cucumber-android: Scenario: Input email and password in correct format
04-12 12:04:07.602 3481-3512/com.my.app I/System.out: CucumberLogin: iPressOnLogInButton
04-12 12:04:07.603 3481-3512/com.my.app I/System.out: CucumberLogin: iShouldGetLoggedInAndRedirectToHomeScreen
04-12 12:04:07.603 3481-3512/com.my.app I/System.out: CucumberLogin: tearDown in LoginStepdefs
04-12 12:04:07.631 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: PAUSED
04-12 12:04:07.631 3481-3481/com.my.app D/LifecycleMonitor: running callback: [email protected]28631
04-12 12:04:07.631 3481-3481/com.my.app D/LifecycleMonitor: callback completes: [email protected]28631
04-12 12:04:07.639 3481-3512/com.my.app I/System.out: CucumberLogin: testLoginScreenIsLaunched
04-12 12:04:07.640 3481-3512/com.my.app I/MonitoringInstr: Unstopped activity count: 1
04-12 12:04:07.641 3481-3481/com.my.app I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 1
04-12 12:04:07.665 3481-3519/com.my.app D/EGL_emulation: eglMakeCurrent: 0xa1805dc0: ver 2 0
04-12 12:04:07.690 3481-3512/com.my.app I/MonitoringInstr: Unstopped activity count: 1
04-12 12:04:07.719 3481-3481/com.my.app W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
04-12 12:04:07.741 3481-3512/com.my.app I/MonitoringInstr: Unstopped activity count: 1
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: STOPPED
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: running callback: [email protected]28631
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: callback completes: [email protected]28631
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: Lifecycle status change: [email protected] in: DESTROYED
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: running callback: [email protected]28631
04-12 12:04:07.763 3481-3481/com.my.app D/LifecycleMonitor: callback completes: android.suppor[email protected]
04-12 12:04:07.791 3481-3512/com.my.app I/MonitoringInstr: waitForActivitiesToComplete() took: 151ms

Please help me

My setup:
Gradle Version: 5.0
Android Plugin Version: 3.3.0
Cucumber Library Version: 1.2.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.