-1

I wanted to run cucumber tests. I am unable to invoke or to run these tests. 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: Enter login details

  @login-feature
  Scenario Outline: Successful Login
    Given   App is launch and user is not logged in
    When    I Click on Log in with Email button
    And Login screen is launched
    And I input an email, "<Email>"
    And I input a password, "<Password>"
    And I press on Log in button
    Then    I Should get logged in and redirect to home screen

    Examples:
      | Email              | Password   |
      | user@login.com     | mypasword123  |

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

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

private LoginActivity activity;

@Before("@login-feature")
public void setUp() {
activityTestRule.launchActivity(new Intent());
activity = activityTestRule.getActivity();
}

@After("@login-feature")
public void tearDown() {
activityTestRule.getActivity().finish();
}


@Given("^App is launch and user is not logged in$")
public void appIsLaunchAndUserIsNotLoggedIn() throws Throwable {
System.out.println("appIsLaunchAndUserIsNotLoggedIn");
}

// and other functions
}

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);

    String tags = BuildConfig.TEST_TAGS;
    if (!tags.isEmpty()) {
        arguments.putString("tags", tags.replaceAll(",", "--").replaceAll("\\s",""));
    }

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

And under AndroidManifest file. i added this

<application
    <uses-library android:name="android.test.runner" />
</application>
<instrumentation
    android:name="cucumber.api.android.CucumberInstrumentation"
    android:targetPackage="com.my.app.test" />

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”

As a result this is the console output. I have also checked it by using break points, where the debugger never stops.

Testing started at 6:24 PM ...
02/12 18:24:35: Launching CucumberTests
$ adb push /home/sajid/Git/app-android/app/build/outputs/apk/debug/app-debug.apk /data/local/tmp/com.my.app
$ adb shell pm install -t -r "/data/local/tmp/com.my.app"
    pkg: /data/local/tmp/com.my.app
Success
APK installed in 2 s 118 ms
$ adb push /home/sajid/Git/app-android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk /data/local/tmp/com.my.app.test
$ adb shell pm install -t -r "/data/local/tmp/com.my.app.test"
    pkg: /data/local/tmp/com.my.app.test
Success
APK installed in 738 ms
Running tests

$ adb shell am instrument -w -r   -e debug false com.my.app.test/com.my.app.test.CucumberInstrumentation
Client not ready yet..
Started running tests
Tests ran to completion.
Test running failed: Unable to find instrumentation info for: ComponentInfo{com.my.app.test/cucumber.api.android.CucumberInstrumentation}

Empty test suite.

Please guide me where I am going wrong and what I need to make this work.

Sajid Zeb
  • 1,806
  • 18
  • 32

2 Answers2

0

EDIT: Your Manifest should be something like this

<application
    android:allowBackup="true"
    android:label="@string/app_name">

    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

Obs: Don't need to put instrumentation here if you put in the Gradle.

OLD:

Check on your file "CucumberInstrumentation" the "package" path Something like com.my.app.test Copy this path and past it on your app/build.gradle. Changing the com.my.app.test for your real path, like com.sajid.app.test

Canato
  • 3,598
  • 5
  • 33
  • 57
  • Thanks for your time @Canato. But i already have the package name synced everywhere. no issue with it. Actually the package name is something else i dont want to reveal. so i put com.my.app as an example. This package name is already added in app/build.gradle. Have a look at the question again. thanks – Sajid Zeb Feb 13 '19 at 10:20
  • @SajidZeb your activity is in your Manifest? – Canato Feb 13 '19 at 10:40
  • no. Actually when i added this I got this error: Test running failed: Unable to find instrumentation info for: ComponentInfo{com.my.app.test/cucumber.api.android.CucumberInstrumentation} Along with Empty test suite. error – Sajid Zeb Feb 13 '19 at 10:53
  • What to edit? i have added those lines and getting this error upon test run : Test running failed: Unable to find instrumentation info for: ComponentInfo{com.my.app.test/cucumber.api.android.CucumberInstrumentation} – Sajid Zeb Feb 14 '19 at 12:23
  • Canato i have updated Android Manifest in post. Please view – Sajid Zeb Feb 14 '19 at 12:51
  • no it doesnot work. i also added the error added in console due to this. : Test running failed: Unable to find instrumentation info for: ComponentInfo{com.my.app.test/cucumber.api.android.CucumberInstrumentation} – Sajid Zeb Feb 14 '19 at 13:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188418/discussion-between-canato-and-sajid-zeb). – Canato Feb 14 '19 at 13:09
0

I don't know what is the reason. But in my feature file

When I changed "Scenario Outline:" to "Scenario:"

its start working

Sajid Zeb
  • 1,806
  • 18
  • 32