Unable to run a simple cucumber feature file in intelliJ - intellij-idea

I've just installed the community edition of IntelliJ and the Cucumber integration. When I try to run a feature, I get the error below. How do I fix this? I have cucumber-core 4.7.2 and gherkin 7.0.4.
Feature: OrangeHRM Login
Scenario: Logo presence on OrangeHRM home page
Given I launch chrome browser
When I open orangeHRM homepage
Then I verify that the logo present on page
And close the browser
Error :
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:24)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:29)
at io.cucumber.core.cli.Main.run(Main.java:29)
at cucumber.api.cli.Main.run(Main.java:28)
at cucumber.api.cli.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: gherkin.IGherkinDialectProvider
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Process finished with exit code 1

As stated by #mpkorstanje, you are using the wrong version of Gherkin with this version of Cucumber.
You don't need to add a Gherkin dependency yourself; this can be managed by your build tool (Maven/Gradle).
As stated in the docs, you only need the cucumber-java or cucumber-java8 dependency. Which one you need, depends on whether you want to write annotated methods or lambdas, respectively:
If you are going to use the lambda expressions API (Java 8) to write the step definitions, add the following dependency to your pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
Otherwise, to write them using annotated methods, add the following dependency to your pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>

Related

karate-config.js failed after update of karate-core

I'm trying to update my karate project with the newest version of karate-junit5 library.
In the documentation for Maven it's mentioned that only one dependency is required to run karate.
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
Previously I was using karate-jersey and karate-junit4 and everything was working flawless.
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-jersey</artifactId>
<version>0.9.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-junit5 -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.9.6</version>
<scope>test</scope>
</dependency>
I managed to update karate-junit4 to karate-junit5 but I see that karate-core is still using 0.9.6
When I want to replace jersey with karate-core 1.3.0 and run my tests I have an error with loading my karate-config.js
karate-config.js failed
js failed:
org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:82:0 Expected ) but found function
This is strange because I didn't change anything besides the dependencies.
Do I still have to use karate-jersey in my project? The documentation doesn't mention this.
I tried to update the dependency to the newest version. Now I got a failing karate-config.js
There's no such thing as karate-jersey. Get rid of that dependency, the HTTP client is now built-in.
Since you are upgrading from such an old version, you need to read all the release notes. For example this one: https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#java-projects
But let's hope you get by with just this one change. Else be prepared to scan all the release notes. The JS engine has changed, but all those who kept tracking the project and tried RC versions (we spend a lot of time on this) have been having a smooth experience.
I guess this is what folks call "technical debt" ;)

JUnit on IntelliJ not working

I tried setting up JUnit 5 on my INtelliJ IDEA Community Edition 2018.2. The jar was downloaded but I am getting Cannot resolve symbol Assertions on importing
import static org.junit.jupiter.api.Assertions.*;
Error
Are you trying to use the JUnit assertions in a regular app class rather than a test class?
Delete <scope>test</scope>
When a Maven dependency carries a scope element with a value of test, that means you cannot use that library outside of your test-specific source package/folder.
If you are trying to call JUnit from code in your example project’s src/main/java/… folder hierarchy, you will see that error. If you call JUnit from src/test/java…, you will see success.
To enable JUnit in the src/main/java/… folder hierarchy, delete the scope element in your POM dependency. So this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
<scope>test</scope>
</dependency>
…becomes this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
</dependency>
By the way, note that as of 5.4.0 of JUnit, we can specify the new and very convenient single Maven artifact of junit-jupiter which in turn will supply 8 libraries to your project.

How to install a plugin in Jira?

I wanted to create a sample servlet as a Jira-plugin according to a tutorial.
I have built the code as it is and I used the following pom.xml to build the code.
When I run the servlet URL I'm getting the following issue about class cast.
[INFO] [talledLocalContainer] ERROR - 13:41:52,368 - com.atlassian.plugin.servlet.DefaultServletModuleManager - [http-bio-5990-exec-4] - Unable to create new reference LazyLoadedServletReference{d
escriptor=com.atlassian.plugins.tutorial.refapp.adminUI:test (null), servletContext=org.apache.catalina.core.ApplicationContextFacade#2829d93e}
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.ClassCastException: com.atlassian.plugins.tutorial.refapp.MyPluginServlet cannot be cast to javax.servlet.http.HttpServlet
[INFO] [talledLocalContainer] at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)
This is possibly a dependency issue in your pom.xml. Check to make sure you are not bundling resources into your plugin that already exist in the environment that is hosting your plugin.
In your case, you might want to check for this:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
With the key part here being <scope>provided</scope> indicating this resource is needed for compilation but does not need to be bundled with the plugin as it is already provided by the runtime environment. If this line doesn't exist or the scope is anything other than provided, then try adding/changing it.
See this page for more info: Dependency Issues during Plugin Initialisation

IntelliJ with flexunit4

I have a maven project where I am using flexmojos and flexunit and the tests execute fine when building through maven.
However when I try to execute a single test using IntelliJ (right click the on test - run), it creates the _flexunit.swf file and tries to execute it, however there is an exception when it runs:
VerifyError: Error #1014: Class mx.core::Application could not be found.
My knowledge of flexmojos is not great, but I believe it takes care of loading the flex sdk dependencies, however I have tried adding flex sdk dependencies directly in my pom but after that I can't even build in maven, which doesn't happen if I leave those dependencies out:
Unable to locate specified base class 'spark.components.supportClasses.ItemRenderer'
So my question is, what tells IntelliJ to configure the _flexunit.swf not to link the flex sdk? Are there some settings where I have to set these specifically?
Seems like my pom is correctly set up to run the tests (so the TestRunner.swf is fine) but the _flexunit.swf compiled by IntelliJ is missing something...
Sounds to me that you need to do something like this:
<dependency>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-unittest-flexunit4</artifactId>
<version>4.1-beta</version>
<type>swc</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
</exclusion>
<exclusion>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>airframework</artifactId>
</exclusion>
</exclusions>
</dependency>
Notice the Exclusions Tag.

How to make IntelliJ understand annotations

I have recently switched from using Eclipse to IntelliJ, and am preferring the experience.
However, the IDE is not understanding any of the Annotations. I am using Spring #Autowired annotation as well as some of the Spring-WS annotations and the IDE is telling me that they are unresolved.
When the project is built using Maven, it builds fine, and the Annotations are recognised in Eclipse.
Im sure this is a simple setup thing, but cannot find any information on how to set it up.
As Peter said, when correctly importing the Maven project the dependencies should be correctly recognized. The IntelliJ manual has a section on how to import a Maven project.
For the record, in our project pom, we have the following dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
The former two have been present already before implementing a web service, so they may not be required strictly for web services.