Hot questions for Using Cucumber in intellij idea

Top Java Programmings / Cucumber / intellij idea

Question:


Answer:

If you edit IntelliJ's workspace.xml file to set the dynamic.classpath property to true, it will work.

<component name="PropertiesComponent">
    ...
    <property name="dynamic.classpath" value="true" />
</component>

I believe IntelliJ used to do this via a popup for you, but since the "Shorten Command Line" feature in 2017.3 has been added to the normal default Run/Debug configurations, it no longer does it this way. And since Cucumber for Java is a plugin, it must not know what to do in that scenario.

Hopefully the issue is fixed to add the dropdown:

Found some of the answer here: IDEA 10.5 Command line is too long

Question:

My tests run fine with the following in the pom.xml:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
</dependency>

the scenario and steps show fine:

But if I move to newer:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>2.3.1</version>
</dependency>

(or even 2.1.0) the scenario still succeeds but the steps are not displayed anymore:

Runing on IntelliJ Ultimate 2017.1.4

Any thoughts?


Answer:

This is due to the fact that the Event model changed for Cucumber-jvm v2.x (see release notes) and the IntelliJ plugin has not yet been updated to reflect this (for instance, see this issue and the one it links to).

Please vote for these issues at youtrack if you'd like to see this fixed in IntelliJ!

Update: This should work by now.

Question:

Erly I asked this question about cucumber and java. After correct my project, I checked PendingException in cucumber-junit. I have 2 classes: TestClass.java for working with SoapUI, TestSteps.java for implementation cucumber steps with my code and JUnit Run.java class. This is my code: TestClass.java:

    public class FirstTest {
private static String xmlFile;
private static String projectPath;

public FirstTest(String file)
{
    xmlFile = file;
}
//for Then step
public static void run() throws XmlException, IOException, SoapUIException {
    //add test project
    WsdlProject project = new WsdlProject(getProjectPath());
    //add xml file for test into property
    project.setPropertyValue("File", xmlFile);
    //get TestSuite and TestCase by name
    TestSuite testSuite = project.getTestSuiteByName("Test");
    TestCase testCase = testSuite.getTestCaseByName("Test");
    //run test
    testCase.run(new PropertiesMap(), false);

}

public static String getProjectPath()
{
    return projectPath = "path";
}

}

And this is TestSteps.java class:

    public class TestSteps {
private FirstTest testClass;

@Given("^I have a file \"(.*?)\"$")
public void i_have_a_file(String file) throws Throwable {
    testClass = new FirstTest(file);
    throw new PendingException();
}

@Then("^I want to run case$")
public void i_want_to_run_case() throws Throwable {
    testClass.run();
    throw new PendingException();
}

}

Cucumber feature:

    Scenario: Test
Given I have a file "path_to_file"
Then I want to run case

And JUnit Class:

    @RunWith(Cucumber.class)
@CucumberOptions(format = {"junit:target_junit/cucumber.xml"},
glue = {"src/com.teststeps.TestSteps"},
features = {"Feature"},
dryRun = true,
strict = true,
tags = {},
monochrome = true)

public class RunTest {
}

If I try run JUnit Class, I checking PendingException:

cucumber.api.PendingException: TODO: implement me
    at cucumber.runtime.junit.JUnitReporter.addFailure(JUnitReporter.java:134)
    at cucumber.runtime.junit.JUnitReporter.addFailureOrIgnoreStep(JUnitReporter.java:122)
    at cucumber.runtime.junit.JUnitReporter.result(JUnitReporter.java:91)
    at cucumber.runtime.Runtime.runStep(Runtime.java:280)
    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:48)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

But I just implemented this steps in my java files. In what direction to look? Why can I check this exception? UPDATE: Try this code in Eclipse too, it dosen't work. Somebody know reasons? UPD 2: Edit descriptions UPD 3: Recreate project help


Answer:

Remove throw new PendingException(); from your steps.

Question:

I've been trying to get this to work.

I would like set up a test runner class like so

However I get this error:

Error:(3, 26) java: package cucumber.api.junit does not exist Error:(10, 10) java: cannot find symbol symbol: class Cucumber

The class looks like:

package nl.prvgld.sigma.aanvraagtitels.testutil;

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class RunFeature {
}

Pom.xml looks like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.prvgld.sigma.aanvraagtitels</groupId>
  <artifactId>Aanvraagtitels</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Aanvraagtitels</name>
  <url>http://maven.apache.org</url>
  <dependencies>
      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>3.2.0</version>
      </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>1.2.5</version>
    </dependency>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
      <dependency>
          <groupId>info.cukes</groupId>
          <artifactId>cucumber-core</artifactId>
          <version>1.2.5</version>
          <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
      <dependency>
          <groupId>info.cukes</groupId>
          <artifactId>cucumber-junit</artifactId>
          <version>1.2.5</version>
      </dependency>

      <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
      <dependency>
          <groupId>com.microsoft.sqlserver</groupId>
          <artifactId>mssql-jdbc</artifactId>
          <version>6.1.0.jre8</version>
      </dependency>
      <dependency>
          <groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
          <artifactId>testserver-cucumber-core</artifactId>
          <version>1.0.0</version>
          <scope>test</scope>
      </dependency>


  </dependencies>
</project>

All classes are somewhere under the Test folder. I've been lookin at some related questions here and tried the solutions like removing test from Pom, and making sure I have junit, cucumber-junit, cucumber-java8 and cucumber-core in the Pom.

I am using Intellij.

Any help in the right direction is highly appreciated!

Cheers!


Answer:

I don't know if you already resolved your issue but you can quickly fix it by removing the scope tags from your pom.xml file. Do this action for all dependencies that you are facing issues and should work fine.

Cheers, HH

Question:

What I am trying to do:

I am currently migrating my Selenium(Java) framework from a standard Page Object model + cucumber setup to a PageFactory + cucumber setup.

This is what I've done so far to try and make it work:

  • I Initiated my PageFactory.
  • I imported all required packages and dependencies.
  • I checked multiple online tutorials to make sure I have the right syntax.

The issue I run into:

My IDEA (IntelliJ) keeps giving me errors on the @FindBy annotations and failing to compile because of it.

When I mouse-over my @FindBy annotations it tells me "@FindBy not applicable to method"

When I try and run my test it gives me the following error on each occurence of the @FindBy annotation. "annotation type not applicable to this kind of declaration"

The code my question is about:

    package pageObjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class AssociatedAlerts {


    public AssociatedAlerts(WebDriver driver) {
        PageFactory.initElements(driver, this);
    }

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected();
}

I must be missing something simple but I just can't seem to spot it. Any help would be much appreciated.

Thanks in advance.


Answer:

You have an error in your syntax:

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected();

firstAlerchCheckboxSelected is NOT a method. It's a variable.

Change it to:

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected;

Question:

When I run particular features-file (or Scenario or even Scenario Outline) by right-clicking it in IDEA the @txn tag is honored, SpringTransactionHooks#startTransaction gets called and each Scenario is treated as transacional.

When I run them all via runner class the tag is ignored regardless of whether I put it on Feature level or on Scenario Outline.

My Cucumber runner class, not much to see here:

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features")
public class CucumberTest {}

Answer:

Adding cucumber.api.spring to glue seems to be the key, as that is the package where class SpringTransactionHooks resides.

Keep in mind that by defining glue you are overriding its default value, make sure the glue now contains your app's classes.

@RunWith(Cucumber.class)
@CucumberOptions(
    glue = {"cucumber.api.spring", "my.package.app.classes"},
    features = "src/test/resources/features")
public class CucumberTest {}

See the spring-txn eample.

Question:

  • I'm trying to add a .feature file for testing in a java suite for intellij. Howerver I'm unable to open the file in intellij

  • Is cucumber support only available for the ultimate edition?

EDIT: I just did a fresh install and it is now working


Answer:

The main cause of this problem is that you may not be specifying the file type. You can do this in the IDE settings:

Question:

I have changed cucumber-junit and cucumber-java8 version from 4.2.5 to 4.6.0 and now I can't navigate from feature file to step definitions classes.

How to reproduce:

  1. Open feature file.
  2. In feature file auto generate step definition.
  3. You will get step and you are able to navigate to it using ctrl+mouse click.
  4. Intellij idea adds deprecated dependency @cucumber.api.java.en.Given.
  5. Change dependency to @io.cucumber.java.en.Given;
  6. Navigation from point 3 is broken. It is not possible to navigate from feature file to step definitions file now.

Navigation from feature file to step definitions file works with deprecated annotations, so, I think I don't have problems with my project structure (I hope so :)).

Have anybody faced with such problem or it is some bug with Intellij idea?


Answer:

Please upvote this ticket for IDEA's Cucumber plugin to make it compatible with 4.5.0 annotations: https://youtrack.jetbrains.com/issue/IDEA-217391

Question:

Error in Feature file :

Unimplemented Subset definition

Error when Run Testrunner class

cucumber.runtime.CucumberException: Error parsing feature file search.feature

I am using Intellij , Created Maven project and setup below code. I have already checked for subset plugin and it seems installed with latest version into intelliJ.

Already tried different answers from other questions on stackoverflow but still unable to run it.

TestRunner.java

package runner;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;


    @RunWith(Cucumber.class)
    @CucumberOptions(features="src/test/resources/features/",glue={"stepDefinition"})

       public class TestRunner{



    }

SmokeTest.java

package stepDefinition;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

    public class SmokeTest {


        @Given("^I am on the home page$")
        public void iAmOnTheHomePage() throws Throwable {
            System.out.println("1");
        }

        @When("^I select to search for game$")
        public void iSelectToSearchForGame() throws Throwable {
            System.out.println("2");
        }



        @Then("^I get the search results with game names at the top$")
        public void iGetTheSearchResultsWithGameResultsAtTheTop() throws Throwable {
            System.out.println("3");
        }
    }

Feature :

Feature : search

Scenario : Searching as a Global user
   Given I am on the home page
   When I select to search for game
   Then I get the search results with game names at the top

POM.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo.cucumber</groupId>
    <artifactId>com.demo.cucumber</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.2</version>
        <scope>test</scope>
    </dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <version>2.24</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.5.3</version>
        </dependency>

    </dependencies>


</project>


Answer:

The issue is from Substeps IntelliJ Plugin that IntelliJ suggests you install when it locates a .feature file inside your project.

Just ignore this extension when it pops up or uninstall it if you already have it.

Cucumber for Java and Gherkin should be enough. Let me know if it works out.

Question:

I've investigated this issue from different sides, but didn't get anywhere so far. I have a project that runs selenium driver on JUnit using Cucumber for Java. I use Maven. Here's my TestRunner that runs the test:

package com.task.lab;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\features",
        glue = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\steps")
public class TestRunner {
}

Here's feature file:

Feature: Login to Gmail

 Scenario Outline: login compose and delete letter
    Given: User is on SignIn page
    When: User enters <Email> and <Password>
    Then: User sends letter to <Receiver> and alert is displayed letter is sent
Examples:
  |Email                 |Password   |Receiver
  |testaccount@gmail.com |okokokokok |testtest@gmail.com
  |testaccount@gmail.com |okokokokok |testtest@gmail.com

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.task.lab.bddtesting</groupId>
<artifactId>bddtesting</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>3.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.8.1</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
        <type>pom</type>
    </dependency>
</dependencies>

And finally my Steps.Defs class:

package com.task.lab.steps;

import com.task.lab.decorator.bo.businessobjects.GmailMessage;
import com.task.lab.decorator.bo.businessobjects.Login;
import com.task.lab.driver.DriverObject;
import com.task.lab.propertyreader.ReadPropertyFile;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefs {

private Login login = new Login();

@Given("^User is on SignIn page$")
public void openSignInPage(){
    LOG.info("Logging in");
    DriverObject.getDriver();
    DriverObject.getDriver().get(ReadPropertyFile.readGmailURL());
}

@When("^User enters (\\S+) and (\\S+)$")
public void enterCredentials(String email, String password) throws Throwable {
    login = new Login();
    login.login(email, password);
}

@Then("^User sends letter to (\\S+) and alert is displayed letter is sent$")
public void composeLetter(String receiver){
    GmailMessage gmail = new GmailMessage();
    gmail.sendMessage(receiver);
}

@After
public void closeBrowser(){
    DriverObject.releaseThread();
}
}

When I try to run the TestRunner from the window I get the error No tests were found. As I investigated priorly, the reason for this could be that I run Test Unit, not Main class. So I reconfigured Intelij Setting for this project to run from Cucumber for Java and specified the Main class as cucumber.api.cli.Main. However, this gives me another error Test framework quit unexpectedly. I also tried running features file only and in this case tests are green but in fact, no scenarios or steps are passed, as the output in the console shows:

0 Scenarios
0 Steps
0m0,000s

I also reinstalled my Intelij to Ultimate version, but the result is just the same. Could someone please help me see what I am doing wrong?


Answer:

So, as I suspected the issue was minor. In my future file I removed ":" and closed my table with vertical lines "|":

Feature: Login to Gmail

 Scenario Outline: login compose and delete letter
    Given User is on SignIn page
    When User enters <Email> and <Password>
    Then User sends letter to <Receiver> and alert is displayed letter is sent
Examples:
  |Email                 |Password   |Receiver          |
  |testaccount@gmail.com |okokokokok |testtest@gmail.com|
  |testaccount@gmail.com |okokokokok |testtest@gmail.com|

Worked like a charm.

Question:

I've set up cucumber with Java in intelliJ, and I've just glued my feature file to my steps file and tried to run it. It's not really testing anything - it should pass. But I'm getting this warning/error. I'm learning by tutorial and I've followed the steps exactly so can't understand why this is happening? Can anyone help? Error is below:

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by cucumber.deps.com.thoughtworks.xstream.core.util.Fields (file:/C:/Users/Kristian.Senior/.m2/repository/io/cucumber/cucumber-jvm-deps/1.0.6/cucumber-jvm-deps-1.0.6.jar) to field java.util.TreeMap.comparator
    WARNING: Please consider reporting this to the maintainers of cucumber.deps.com.thoughtworks.xstream.core.util.Fields
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release

    Skipped step

    Skipped step

    Skipped step

    Skipped step

    1 Scenarios (1 pending)
    4 Steps (3 skipped, 1 pending)
    0m0.393s

    cucumber.api.PendingException: TODO: implement me
        at Steps.LoginFeature.iNavigateToTheLoginPage(LoginFeature.java:18)
        at ✽.I navigate to the login page(C:/Users/Kristian.Senior/CucumberBasics/src/test/java/Features/login.feature:6)

Answer:

You get the exception

cucumber.api.PendingException: TODO: implement me
        at Steps.LoginFeature.iNavigateToTheLoginPage(LoginFeature.java:18)
        at ✽.I navigate to the login page(C:/Users/Kristian.Senior/CucumberBasics/src/test/java/Features/login.feature:6)

which enforces you to implement the step described in the exception.

Implement step like this:

@When("I navigate to the login")
public void i_navigate_to_the_login() {
    System.out.printf("Navigating to login\n");
}

In order to just skip those steps you can set strict option in CucumberOptions

Strict: if the strict option is set to false then at execution time if cucumber encounters any undefined/pending steps then cucumber does not fail the execution and undefined steps are skipped and BUILD is SUCCESSFUL.

Question:

I am trying to very basically install and set up cucumber in intelliJ with Java but it will not work. I have added/enabled the cucumber for Java plugin, I've added the maven dependency for cucumber, but when I create a .feature file, it does not create a Cucumber file as it should. The little logo next to the file does not change to the Cucumber icon. The feature file kind of half reads the syntax correct, when I type 'feature:' or 'scenario:' it turns orange however it doesn't when I type 'Given', 'When' etc. Can anyone shed some light on why it might be doing this?

See photos of pom and feature file:

Please help I'm at my wits end.


Answer:

You can change filetype in Intellij IDEA

Question:

I have the following declaration before my test suite:

@CucumberOptions(features = "src/test/resources/", plugin = {"pretty",
    "json:target/cucumber.json"})

This works if I run the file from within Idea, however if I run mvn verify from the command line it does not work.

If I change it to

@CucumberOptions(features = "../src/test/resources/", plugin = {"pretty",
    "json:target/cucumber.json"})

...it works with mvn verify but not in Idea. Can I have my cake and eat it?


Answer:

You can have your cukes and eat them too. If you have a single Maven project with a standard layout and all of your Cucumber features are in src/test/resources, running the tests should work in both by omitting features entirely.

If you actually have your Cucumber features in a non-standard location, like in a parent Maven project, you can keep your command-line working with ../src/test/resources, and change the working directory of your Run/Debug configuration to any directory that properly resolves the relative path. You can change it for a specific configuration, or the default configuration so it will take effect for any configurations auto-generated by right-clicking.

Alternatively, you should also be able to use src/test/resources and set the working directory of the maven-surefire-plugin, but it's better to make the IDE bend towards the command-line, not vice versa.

Question:

I'm using IntelliJ Idea Ultimate 2018.1 and in my java project, I've some BDD implemented with Cucumber and Gherkin. when I try to right-click on a feature file and run it I see the following error

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:174)
    at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:166)
    at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:223)
    at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:206)
    at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:456)
    at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:160)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:112)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:105)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:97)
    at cucumber.api.cli.Main.run(Main.java:30)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Formatter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

This is happening for some days. In the past was working perfectly. The cucumber for java and gherkin plugins are installed. I've tried to download a new fresh version of IntelliJ but no luck.

The dependencies I've in my project are the following

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

and my feature file is similar to the following

Feature: Blocker Accumulation

Scenario: Blocker Accumulation
    Given I am logged as a user
    And I have an In-progress activity
    And it has been previously blocked for 16 days
    And now is not blocked
    When I block the activity for other more 6 days
    Then the total blocking days is 22

What can I try? What's my fault? Thank you


Answer:

You'll need to update your Cucumber for Java plugin. (This may include uninstall/install to get it to work correctly).

Question:

I've been stuck for hours and I'm a bit confused, as I've tried to follow quite a few tutorials to set up Cucumber (Java version) + Selenium using IntelliJ as an IDE but I always end up getting errors from the very beginning, so I'm guessing there either is something the tutorials don't mention or some misconfiguration on my IDE.

This is something of what I've tried:

First, created a Maven project in IntelliJ IDEA and added dependencies for cucumber, junit and selenium to my pom.xml:

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.8.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

Then I created some structure for my project:

  • a folder named "resources" within src/test.
  • a folder named "features" within src/test/resources.
  • a package named "step_definitions" within src/test/java.
  • a file called MyTest.feature in the src/test/resources/features folder

In my MyTest.feature I added a simple test like this:

Feature: Check addition in Google calculator

  Scenario: Addition
    Given I open google
    When I enter "2+2" in search textbox
    Then I should get the result as "4"

Then from my feature file I auto-generated step definitions by using the IDE functionality (alt+enter > create step definitions), and I got a new file: MyStepDefs.java which I placed in src/test/java/step_definitions (leaving it in just src/test/java makes no difference), with the following contents:

package step_definitions;
import cucumber.api.PendingException;

public class MyStepdefs {
    public MyStepdefs() {
        Given("^I open google$", () -> {
            // Write code here that turns the phrase above into concrete actions
            throw new PendingException();
        });}
}

The thing is, this is already showing errors. The "Given" keyword is not recognized: Cannot resolve method 'Given(java.lang.String)'

And on "new PendingException()" I get: Incompatible types. Required: java.lang.Throwable. Found: cucumber.api.PendingException

This sounds fishy, as it's auto-generated code so I assume it should be error-free (but it's not).

So I tried replacing this auto-generated code with something I got from this tutorial but then I get a "not applicable to method" error on @Before, @After, @Given, @When, @Then keywords.

package step_definitions;

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class googleCalcStepDefinition {

    protected WebDriver driver;

    @Before
    public void setup() {
        driver = new FirefoxDriver();
    }

    @Given("^I open google$")
    public void I_open_google() {
        //Set implicit wait of 10 seconds and launch google
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.get("https://www.google.co.in");
    }

    @When("^I enter \"([^\"]*)\" in search textbox$")
    public void I_enter_in_search_textbox(String additionTerms) {
        //Write term in google textbox
        WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
        googleTextBox.sendKeys(additionTerms);

        //Click on searchButton
        WebElement searchButton = driver.findElement(By.id("gbqfb"));
        searchButton.click();
    }

    @Then("^I should get result as \"([^\"]*)\"$")
    public void I_should_get_correct_result(String expectedResult) {
        //Get result from calculator
        WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
        String result = calculatorTextBox.getText();

        //Verify that result of 2+2 is 4
        Assert.assertEquals(result, expectedResult);

        driver.close();
    }

    @After
    public void closeBrowser() {
        driver.quit();
    }
}

What am I missing? Is there any way I can set up a fresh new project that uses Cucumber (Java) + Selenium on the IntelliJ IDE? Or is it just not possible at all?

Thanks!


Answer:

Apparently, the Java JDK 9 that I had recently downloaded was the culprit. I went back to square 1 and started the project with JDK 8 and everything works as expected now.

Question:

I have a java cucumber project which is set up with all the required dependencies running latest dependencies of cucumber-java, cucumber-junit and gherkin etc. I also have plugins installed for cucumber and gherkin.

IntelliJ isn't allowing me to create a file with the extension '.feature'. I get an error of 'Cannot create class-file'. Oddly, if I create a regular file (i.e. with no .feature extension) in my ./resources/features folder, then associate it as a 'cucumber scenario' file, IntelliJ recognises this and prefixes it with the little green cucumber sign in the file directory. It also recognises all the 'Given When Then' syntax and formats it in the file correctly. But when I run my runner, it reports no features are found. I think this is because it is looking for '.feature' extension?

Has anyone had this issue before? Its baffling me as it appears cucumber and gherkin are set up correctly, given it allows me to create a cucumber scenario file, but just not with the '.feature' extension. For information my runner file looks like the below. Thanks in advance of any help, its driving me mad :)

@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\Users\\joe.bloggs\\Desktop\\dram_automation_suite\\src\\test\\resources\\features")
public class CucumberRunTest {
}

Answer:

Your error sounds indeed strange. My experience of creating a file, any file, in Idea just works. Are you sure you are not trying to create a java file, i.e. a class?

For your other issue, place the feature file in the same package as the test runner lives is. But in the resources directory.

If your runner lives in the package com.company.lucy then store the feature files in src/test/resources/com/company/lucy This will allow Cucumber to find it since Cucumber searches its classpath and uses every file it finds called .feature

This will allow you to speciy your runner as:

@RunWith(Cucumber.class)
public class CucumberRunTest {
}

And your issue with maintaining many feature files will disappear.

As this seems to be a Maven project, anything placed in the resources folder will end up on your classpath. Anything in src/test/resources will end up on your test classpath.

Question:

I'm having an issue with cucumber reports not generating. I'm running the tests with IntelliJ.

Here's my pom:

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.8.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.8.0</version>
            <scope>test</scope>
        </dependency>

I've created a RunCucumberTest.java class, with the following:

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/reports", "json:target/reports/cucumber.json"},
                 glue = {"com.PACKAGE.featureTests"})
public class RunCucumberTest {
}

I've run it successfully with the IntelliJ plugin, with failures and without (I know some issues have been that the report doesn't generate when there are failures). But in neither case will any report be created in my target folder.

Thoughts?


Answer:

I finally solved my problem by upgrading to 5.1.3 and they generate fine there.

Question:

I'm trying to setup an automation framework with Cucumber and Java. I'm using Itellij IDEA as my IDE. I am able to automate the test cases as of now. I read the Xray documentation and realised that I should use the REST API to update the feature files on Xray.

I have worked a bit with Cucumber and C# where I automated my test cases on Visual Studio and updated the features and execution status on TFS using Hooks. As of now, I wish to implement the same with Java over Xray.

I have done a bit of research and realised that either I should create a test case on Xray written in Cucumber and then export it to automate on Intellij or automate the test cases and use Jenkins to update them on Xray.

Is there a work around or a tutorial which I can follow to update my features on Xray using Java and Cucumber on Intellij?


Answer:

For those who're stuck with the same problem as mine, this is the way that I am able to export my cucumber features to Xray. You just have to send the path of your Cucumber feature file and the url like this - https://jira.yourdomain.com/rest/raven/1.0/import/feature The other parameters are quite understandable.

public static void importFeatureFilesToJira(String filePath, String resultTypeUrlValue){
    String jiraUrl = config.getJiraLoginValue();
    log.info(String.format("Starting upload of Cucumber features to XRAY on Jira project: %s\n Using Jira user: %s ", config.getJiraProjectValue(), config.getJiraLoginValue()));
    log.info(String.format("Path to Report: %s", filePath));
    String authentication = config.getJiraLoginValue() + ':' + config.getJiraPassword();
    BASE64Encoder encoder = new BASE64Encoder();
    String encoded = null;
    try {
        encoded = encoder.encode((authentication).getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    Client client = ClientBuilder.newBuilder()
            .register(MultiPartFeature.class).property(HttpHeaders.AUTHORIZATION, encoded).build();

    //Import type is dynamic below
    StringBuffer url = new StringBuffer(resultTypeUrlValue);
    url.append("?projectKey=").append(config.getJiraProjectValue());
    WebTarget webTarget = client.target(url.toString());
    log.info(String.format("URL of the XRAY API: %s", url.toString()));
    MultiPart multiPart = new MultiPart();
    multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
    FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
            new File(filePath),
            MediaType.APPLICATION_OCTET_STREAM_TYPE);
    multiPart.bodyPart(fileDataBodyPart);

    Response response = webTarget.request(
            MediaType.MULTIPART_FORM_DATA)
            .accept(MediaType.APPLICATION_JSON).
                    header(HttpHeaders.AUTHORIZATION, "Basic " + encoded).post(
                    Entity.entity(multiPart, multiPart.getMediaType()));
    log.info(response.getStatus() + " "
            + response.getStatusInfo() + " " + response);
    int responseBody = response.getStatus();
    String responseBodySting = response.toString();
    try{
        if(responseBody==200 && responseBodySting.contains("200")){
            log.info("Cucumber features were uploaded successfully");
        }
    }catch (Exception e){
        log.info("There was an error uploading the Cucumber feature file");
    }
    log.info("End of XRAY file upload publication");
}