sebaslogen / CleanGUITestArchitecture

Sample project of Android GUI test automation using Espresso, Cucumber and the Page Object Pattern
MIT License
137 stars 31 forks source link

Getting error: cucumber.runtime.CucumberException: No CucumberOptions annotation #3

Closed aashreys closed 8 years ago

aashreys commented 8 years ago

Hey, I've created a sample project based on your example here and now I'm getting the above mentioned exception every time I try to run my test (HelloWorldSteps.java). I would greatly appreciate it if you could tell me what I'm doing wrong. I've attached the relevant classes below. Alternatively, I can also upload my project if you need more information. Let me know. :)

Instrumentation class

public class CucumberTestRunner extends android.support.test.runner.AndroidJUnitRunner {

    public static final String TAG = CucumberTestRunner.class.getSimpleName();

    private final CucumberInstrumentationCore instrumentationCore
            = new CucumberInstrumentationCore(this);

    @Override
    public void onCreate(final Bundle bundle) {
        super.onCreate(bundle);
        instrumentationCore.create(bundle);
    }

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

@CucumberOptions marker class

@CucumberOptions(
    features = "features", // Test scenarios
    glue = {"com.aashreys.cucumberplayground"}, // Steps definitions
    tags= {"@hello-world"}
)
public class CucumberTestCase {
}

Step Definition Class

public class HelloWorldSteps extends ActivityInstrumentationTestCase2<MainActivity> {

    private String helloWorld;

    public HelloWorldSteps(Class<MainActivity> activityClass) {
        super(activityClass);
    }

    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void tearDown() throws Exception {
        getActivity().finish();
        super.tearDown();
    }

    @Given("^the text is \"(.+)\"$")
    public void given_the_text_is(String text) {
        helloWorld = text;
    }

    @Then("^the text is \"(.+)\"$")
    public void then_the_text_is(String text) {
        Assert.assertEquals(text, helloWorld);
    }
}

.feature file placed in /src/androidTest/assets/features

Feature: Hello World

  @hello-world
  Scenario: A test to check Hello World!
      Given the text is "Hello World!"
       Then the text should be "Hello World!"
sebaslogen commented 8 years ago

The Cucumber error message is not very helpful but looking at your code there is one thing that is not allowed in Cucumber and maybe it's the root of your problem:

Step definitions annotated with @Given/@When/@Then/@And can not be duplicated and the keywords at the beginning of the sentences are equivalent and interchangeable, so you can annotate a method with @Given("some exact text") and then use it in the feature files as 'Given some exact text' or 'And some exact text' and both will work.

Now with this cucumber rule for the @Given/@When/@Then/@And keywords, you can see in the sample code that the @Given("^the text is \"(.+)\"$") and @Then("^the text is \"(.+)\"$") annotations are exactly the same for Cucumber and therefore invalid.

aashreys commented 8 years ago

Oh alright. I've modified my feature file above and in my project to have different texts. My problem however is that Cucumber can't find the @CucumberOptions annotations and hence is unable to locate my scenario entirely. Here's the logcat if you need more info

01-26 12:46:37.004 11545-11545/? E/MonitoringInstrumentation: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
                                                              java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com.aashreys.cucumberplayground.test/com.aashreys.cucumberplayground.CucumberTestRunner}: cucumber.runtime.CucumberException: No CucumberOptions annotation
                                                                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4547)
                                                                  at android.app.ActivityThread.access$1500(ActivityThread.java:151)
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                  at android.os.Looper.loop(Looper.java:135)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                               Caused by: cucumber.runtime.CucumberException: No CucumberOptions annotation
                                                                  at cucumber.runtime.android.CucumberExecutor.createRuntimeOptions(CucumberExecutor.java:156)
                                                                  at cucumber.runtime.android.CucumberExecutor.<init>(CucumberExecutor.java:88)
                                                                  at cucumber.api.android.CucumberInstrumentationCore.create(CucumberInstrumentationCore.java:70)
                                                                  at com.aashreys.cucumberplayground.CucumberTestRunner.onCreate(CucumberTestRunner.java:20)
                                                                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4544)
                                                                  at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                  at android.os.Looper.loop(Looper.java:135) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                  at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
01-26 12:46:37.006 11545-11545/? E/THREAD_STATE:   Thread[Instr: com.aashreys.cucumberplayground.CucumberTestRunner,5,main]
                                                     java.lang.Object.wait(Native Method)
                                                     android.app.Instrumentation$Idler.waitForIdle(Instrumentation.java:1939)
                                                     android.app.Instrumentation.waitForIdleSync(Instrumentation.java:338)
                                                     com.aashreys.cucumberplayground.CucumberTestRunner.onStart(CucumberTestRunner.java:25)
                                                     android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
01-26 12:46:37.006 11545-11545/? E/MonitoringInstrumentation: Dying now...
sebaslogen commented 8 years ago

That is a different problem, maybe CucumberTestCase.java is not part of your test package. If you put the rest of the code online maybe I can see the source of the problem.

aashreys commented 8 years ago

Sure, let me upload it to a repo and send you the link.

aashreys commented 8 years ago

Here: https://github.com/aashrey99/CucumberPlayground

sebaslogen commented 8 years ago

There are a few Cucumber problems in your example project but I made it run:

1.- Location of Cucumber runner and options classes

2.- The Activity tested in step definitions

Let me know if you made it work with these fixes.

aashreys commented 8 years ago

Thanks, these solved my issues. I'm successfully able to run the tests now.

moenterazi commented 8 years ago

He @sebaslogen, Have setup the same way you have on your project but keep getting the No CucumberOptions annotation

moenterazi commented 8 years ago

java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com..mobile.android.test/com..mobile.***.cucumber.runner.CucumberTestRunner}: cucumber.runtime.CucumberException: No CucumberOptions annotation at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6310) at android.app.ActivityThread.access$1800(ActivityThread.java:221) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230

sebaslogen commented 7 years ago

Hi @moenterazi, The usual reason for this problem is that the java file with CucumberOptions is not in the right path/package. See this comment: https://github.com/sebaslogen/CleanGUITestArchitecture/issues/3#issuecomment-177162185

If you still can't figure it out, share your code online and I can take a look at it.

moenterazi commented 7 years ago

@sebaslogen thanks sebas. The issue is resolved now. is there a way to contact you faster... through email?

sebaslogen commented 7 years ago

@moenterazi I got this message quite fast but I was away on holidays. I'm glad it works now :)

moenterazi commented 7 years ago

@sebaslogen... getting the following: No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

In my stepdefinition class i have a call to some other already written tests with @test annotations in espresso.

sebaslogen commented 7 years ago

@moenterazi if you look at the examples in StepDefinitions you don't have to tag anything with @test, you need to create methods with the @Given("") annotation to define steps and use these steps in your feature file.

The error you get seems like there is no feature file in the assets folder or the test case in the feature file doesn't have any tag from the ones you select in the CucumberOptions

moenterazi commented 7 years ago

@sebaslogen looks like i'm not defining the location for the feature file and steps file properly.

sebaslogen commented 7 years ago

@moenterazi if you still have problems you can share your implementation of the step definitions, feature file and cucumber options like the original reporter of the problem and maybe I can help you more.

moenterazi commented 7 years ago

@sebaslogen looks like my testrunner is not being detected. because when it's commented it's not making any different and still cannot find tests.

So what i'm doing is that i'm integrating cucumber with a current android app and unable share the code online. What i've done with directory structure is this: in android Studio.

VIEW: app->java->com.x.x.androidTest->original-espresso-test ->cucumber->conf->CucumberTestCase.java (contains@options - ->cucumber->runner->CucumberTestRunner.java ->cucumber->steps->StepDefinitions.java

and added what you had for build.gradle of the app I added what you added.

Here are the content of the files: CucumberTestCase.java

package com._.mobile._.cucumber.conf;

import cucumber.api.CucumberOptions;

/**

CucumberTestRunner.java

package com._.mobile._.cucumber.runner;

import android.os.Bundle;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions; import cucumber.api.android.CucumberInstrumentationCore; //import cucumber.api..AbstractTestNGCucumberTests;

/**

public class CucumberTestRunner extends android.support.test.runner.AndroidJUnitRunner {

public static final String TAG = CucumberTestRunner.class.getSimpleName();
/**
 * This is the item Cucumber uses to identify the tags parameter, see method
 * cucumber-android-1.2.2.jar\cucumber\runtime\android\Arguments.class @ getCucumberOptionsString()
 */
private static final String CUCUMBER_TAGS_KEY = "tags";
private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);

@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);
    final String tags = "";
    if (!tags.isEmpty()) {
        bundle.putString(CUCUMBER_TAGS_KEY, tags.replaceAll(",", "--").replaceAll("\\s",""));
    }
    instrumentationCore.create(bundle);
}

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

}

CucumberTestRunner.java

package com._.mobile._.cucumber.runner;

import android.os.Bundle;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions; import cucumber.api.android.CucumberInstrumentationCore; //import cucumber.api..AbstractTestNGCucumberTests;

/**

public class CucumberTestRunner extends android.support.test.runner.AndroidJUnitRunner {

public static final String TAG = CucumberTestRunner.class.getSimpleName();
/**
 * This is the item Cucumber uses to identify the tags parameter, see method
 * cucumber-android-1.2.2.jar\cucumber\runtime\android\Arguments.class @ getCucumberOptionsString()
 */
private static final String CUCUMBER_TAGS_KEY = "tags";
private final CucumberInstrumentationCore instrumentationCore = new CucumberInstrumentationCore(this);

@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);
    final String tags = "";
    if (!tags.isEmpty()) {
        bundle.putString(CUCUMBER_TAGS_KEY, tags.replaceAll(",", "--").replaceAll("\\s",""));
    }
    instrumentationCore.create(bundle);
}

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

}

sebaslogen commented 7 years ago

@moenterazi did you modify your app/build.gradle to point to the cucumber test runner that you posted? testInstrumentationRunner "com..mobile..cucumber.runner.CucumberTestRunner"

Also in @CucumberOptions(features = "src/androidTest/assets/features", you should point only to features folder because the folder src/androidTest doesn't exist at runtime and the folder assets is where the Cucumber is going to start looking for features by default.

moenterazi commented 7 years ago

@sebaslogen yes to the 1st question.

second: changed it to src/main/assets/features

moenterazi commented 7 years ago

still getting no test error

moenterazi commented 7 years ago

@sebaslogen can i have the two of these runners together? // testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "com.rbc.mobile.bud.cucumber.runner.CucumberTestRunner"

moenterazi commented 7 years ago

@sebaslogen

here is my gradle changes

//Espresso

androidTestCompile('com.android.support.test:runner:0.5') {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}

androidTestCompile 'com.android.support:design:23.3.0'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
    exclude module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'recyclerview-v7'
}
// Cucumber
androidTestCompile('info.cukes:cucumber-android:1.2.4') {
    exclude module: 'cucumber-jvm-deps'
}
androidTestCompile('info.cukes:cucumber-picocontainer:1.2.4') {
    exclude module: 'cucumber-jvm-deps'
}
androidTestCompile 'info.cukes:cucumber-jvm-deps:1.0.3'

// androidTestCompile 'info.cukes:cucumber-testng:1.2.4'

sebaslogen commented 7 years ago

@moenterazi second: changed it to src/main/assets/features I meant exactly the opposite, to change your CucumberTestCase.java file to @CucumberOptions(features = "features", exactly like the example in this project

moenterazi commented 7 years ago

@sebaslogen ing tests

$ adb shell am instrument -w -r -e tags @managePayees -e debug false com._.mobile.android.test/com._.mobile.***.cucumber.runner.CucumberTestRunner Client not ready yet.. Started running tests Test running failed: Instrumentation run failed due to 'cucumber.runtime.CucumberException' Empty test suite.

moenterazi commented 7 years ago

@sebaslogen :app:connectedAutoSignInDebugAndroidTest Tests on SM-G900W8 - 6.0.1 failed: Instrumentation run failed due to 'cucumber.runtime.CucumberException'

com.android.builder.testing.ConnectedDevice > No tests found.[SM-G900W8 - 6.0.1] FAILED No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations). :app:connectedAutoSignInDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

BUILD FAILED

Total time: 56.152 secs

sebaslogen commented 7 years ago

@moenterazi check that you have a feature file in /app/src/androidTest/assets/features/ with:

Feature: Some text description

  @managePayees
  Scenario: Some text description
Given Text for step

And on the Step definitions java file inside package com.**.mobile.android.cucumber.steps you have: @Given("Text for step") public void my_step_name() {}

If this is the case, try with one single feature, 1 scenario and 1 very simple step, then make sure the syntaxis is correct. I remember having a weird fail once because the feature text was very bad formatted (e.g. having a step without any text for the step, so a line with only "Given").

moenterazi commented 7 years ago

@sebaslogen still the same

moenterazi commented 7 years ago

@sebaslogen if I try to run the feature file this is what I get:

Testing started at 7:02 PM ...

1 Scenarios (1 undefined) 1 Steps (1 undefined) 0m0.000s

Undefined step: Given Text for step

You can implement missing steps with the snippets below:

@Given("^Text for step$") public void text_for_step() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }

sebaslogen commented 7 years ago

@moenterazi Perfect, that means it's running because it recognized the feature and scenario, you are simply getting back the exception that you throw new PendingException(), now implement the code inside public void text_for_step() and you can have a successful test scenario executed.

moenterazi commented 7 years ago

But i don't think it's reading the steps that i provided. It seems to be suggesting a sample step that need to be created like.

sebaslogen commented 7 years ago

@moenterazi it's reading text_for_step(), so if it's reading that step but not the other ones you created it means there is a problem (my guess it's a syntax problem) in the other steps. My suggestion is to take the feature and step that works @Given("^Text for step$") and start modifying it in small steps until it looks like the one you created before, I imagine at some point during the modification process you're gonna see the fail happening and you'll know exactly where you're feature file or step definition is broken.

Alternative you can paste upload your feature file and step definitions file and maybe I can stop the syntax error.

moenterazi commented 7 years ago

other ones were commented out.

Feature: Some text description

@managePayees Scenario: Some text description Given Text for step

@Given("^Text for step$") public void my_step_name() {}
moenterazi commented 7 years ago

@sebaslogen can we share things privately?

sebaslogen commented 7 years ago

@moenterazi, yes, you can write me at gmail, my user is the same as in github.

Auronake commented 7 years ago

Hello @sebaslogen, i try to execute tests in the same way of this discussion and i fail in the same step

Have you resolved the problem with @moenterazi ? If yes, can you write it here ? Thanks!

sebaslogen commented 7 years ago

@Auronake no, without the full code I wasn't able to figure out what was the difference between his project and this repository. I would recommend to start by executing the code in this repo in your computer and then copy/migrate to your project until you have one single feature with one scenario and one step running.

Good luck.

Auronake commented 7 years ago

@sebaslogen ok thanks for the reply :) i'll try

maravij commented 7 years ago

@sebaslogen when i am playing around with your project https://github.com/sebaslogen/CleanGUITestArchitecture.git I added an entry to gradle file for web view testing androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2') { exclude group: 'com.android.support' }

following error displayed in the project :app:transformClassesWithDexForDebugAndroidTest

Running dex as a separate process.

To run dex in process, the Gradle daemon needs a larger heap. It currently has 1024 MB. For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB. To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties. For more information see https://docs.gradle.org/current/userguide/build_environment.html

warning: Ignoring InnerClasses attribute for an anonymous inner class (org.ccil.cowan.tagsoup.Parser$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class. Dex: Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/thirdparty/publicsuffix/PublicSuffixPatterns; UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/thirdparty/publicsuffix/PublicSuffixPatterns; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:591) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:546) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:528) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106)

:app:transformClassesWithDexForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

BUILD FAILED

please provide me some direction to fix the issue for web view testing

thanks Vijay

sebaslogen commented 7 years ago

@maravij a quick Google search points to a problem of duplicated dependencies that you include with the espresso-web: http://stackoverflow.com/questions/22468700/unexpected-top-level-exception-com-android-dex-dexexception-multiple-dex-files#26940654

maravij commented 7 years ago

@sebaslogen thanks for spontaneous reply, I tried everything to my knowledge. if you can update your repository (https://github.com/sebaslogen/CleanGUITestArchitecture.git) with
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2' it would be great

thanks

Vijay

maravij commented 7 years ago

@sebaslogenI managed the resolved the issue by adding following info to build.gradle androidTestCompile('info.cukes:cucumber-android:1.2.4') { exclude group: 'com.google.guava' exclude module: 'cucumber-jvm-deps' }

sebaslogen commented 7 years ago

@maravij 💯 👌! Well done for finding the duplicated dependency between those two libraries.

This demo project doesn't use espresso-web so if I add the dependency to build.gradle, some people may think it's mandatory to use it for any kind Espresso tests. Imho, the best you can do is write a question and answer in StackOverflow about the problem of combining com.android.support.test.espresso:espresso-web with info.cukes:cucumber-android, it will be very useful.

aranip commented 4 years ago

I am getting this error: can anyone please help me here is my error stack trace cucumber.api.PendingException: TODO: implement me at cucumber.runtime.junit.JUnitReporter.addFailure(JUnitReporter.java:150) at cucumber.runtime.junit.JUnitReporter.addFailureOrIgnoreStep(JUnitReporter.java:138) at cucumber.runtime.junit.JUnitReporter.result(JUnitReporter.java:98) at cucumber.runtime.Runtime.runStep(Runtime.java:282) at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44) at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.runtime.junit.ExamplesRunner.run(ExamplesRunner.java:59) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.runtime.junit.ScenarioOutlineRunner.run(ScenarioOutlineRunner.java:53) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.api.junit.Cucumber.run(Cucumber.java:100) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Here is my runner file:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class) @CucumberOptions( features = "/Users/amruthapenigalapati/eclipse-workspace/corejava/src/Basic_java/CucumberWithJunit/src/test/java/features/Login.feature", //the path of the feature files glue={"stepDefinitions.LoginStep"}, //the path of the step definition files plugin = {"pretty","html:test-outout", "json:json_output/cucumber.json", "junit:junit_xml/cucumber.xml"}, //to generate different types of reporting monochrome = true, //display the console output in a proper readable format strict = true //it will check if any step is not defined in step definition file //dryRun = false //to check the mapping is proper between feature file and step def file ) public class TestRunner {

}

Here is my step definition: import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;

import core.ApexBaseTest; import core.EcommerceConstants; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When;

public class LoginStep extends ApexBaseTest implements EcommerceConstants{ static WebDriver driver; @Given("^ecomm user enters the url$") public static void ecomm_user_enters_the_url() throws Throwable { ApexBaseTest.setup(); Assert.assertEquals("Welcome to Ez Shop Online" , TITLE); driver.findElement(By.linkText("ACCOUNT")).click();

}
@When("^ecomm user enters the login details \"([^\"]*)\" and \"([^\"]*)\"$")
public static void ecomm_user_enters_the_login_details(String UserName, String Password) throws Throwable {
    driver.findElement(By.name(EMAIL_NAME_LOCATOR)).sendKeys(UserName);
    driver.findElement(By.name(PWD_NAME_LOCATOR)).sendKeys(Password);  
    driver.findElement(By.xpath("/html/body/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[4]/td[2]/form/table/tbody/tr[5]/td/a/div")).click();
}
@Then("^user logs in successfully$")
public void user_logs_in_successfully() throws Throwable {
    Assert.assertEquals("You have Logged In successfully.",TITLE2);

}

}

Feature file:

Feature: Ecommerce Application Test

Scenario Outline: Validate Ecommerce Login Page Test

Given ecomm user enters the url When ecomm user enters the login details "" and "" Then user logs in successfully

Examples: | UserName | Password | | harikaqa.601@gmail.com | Welcome@123 | |chitraaaaaaa@gmail.com | chitra121 |

sebaslogen commented 4 years ago

@aranip see my answer to your questions in https://github.com/sebaslogen/CleanGUITestArchitecture/issues/27