what package should be imported when using #Before #After cucumber Hooks - maven

I'm using Cucumber and Junit for my Maven Project. When I tried to create Cucumber Hooks with #After or #Before annotation and imported cucumber.api.java.Before; package, it didnt work. It says this is deprecated. Can someone tell me what annotation I can use for running the steps before every scenario or if I should import any other package for cucumber hooks? I tried importing io.cucumber.junit.CucumberOptions as well. It didn't work.
I'm using io.cucumber dependencies version 4.8.1. With this version, it shows #After #Before cucumber hooks annotation deprecated but With version 2.0.0,it doesn't show deprecated.
Could someone help on this.

Adapt your imports' packages. There is:
cucumber.api.java.After which is deprecated
io.cucumber.java.After which is not
The same applies to Before.

You need to add below dependency in POM.xml file
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
Import below packages:
import io.cucumber.java.After;
import io.cucumber.java.Before;

Related

Eclipse - No tests found with test runner 'JUNIT 4'

I have generated a spring boot project from start.spring.io and imported it into STS. The tutorial I'm watching wants to run a JUNIT test before continuing. But when I try to run Junit test I get the following error "No tests found with test runner 'JUNIT 4'.
Also tested with following dependency
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
Any suggestion on how to fix this?
I suspect class DevopsApplicationTests. If I add class DevopsApplicationTests extends TestCase then unit test works but fails. Not sure what should be the correct code.
When testing "import org.junit.Test" I see the following errors.
When trying "import junit.framework.Test;" Also I get "No tests found with test runner 'JUNIT 4' like before but also there is a error near "#Test".
You're using the wrong import.
org.junit.jupiter.api.Test is the annotation for JUnit 5.
For JUnit 4, you need to import junit.framework.Test.
By the way, the latest version of STS is 3.8.0, released in 2017, based on Eclipse Neon from 2016.
STS is deprecated, and is replaced by 'Spring Tools 4 for Eclipse': https://spring.io/tools
Making the class Public fixed the issue.
package com.example.devops;
// import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
#SpringBootTest
public class DevopsApplicationTests {
#Test
public void contextLoads() {
}
}

how to import a Maven dependency using SBT

I am trying to get embedded-cassandra in my scala/play project which uses sbt instead of maven. (https://github.com/nosan/embedded-cassandra/wiki)
I translated the following maven dependency into sbt.
<!-- Core API -->
<dependency>
<groupId>com.github.nosan</groupId>
<artifactId>embedded-cassandra</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Test Extensions (Spring, JUnit, etc.) -->
<dependency>
<groupId>com.github.nosan</groupId>
<artifactId>embedded-cassandra-test</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
SBT conversion
"com.github.nosan"%"embedded-cassandra" % "2.0.1" % "test"
But I am getting compilation error when I try to import embedded-cassandra in my unit test.
import com.github.nosan.embedded.cassandra.Cassandra
error
Error:(7, 12) object github is not a member of package com
import com.github.nosan.embedded.cassandra.Cassandra
What am I doing wrong?
Turns out, the issue was that SBT hadn't downloaded the dependency. I re-imported the project and things worked. I made another change. I removed the % test from the sbt entry though to be honest I don't know if that had any implications.

import of amqp from org.springframework get error

I'm working on existing Scala project which using the spring framework and I need to import org.springframework.amqp but when I tried to build the project I get:
Error:(15, 28) object amqp is not a member of package
org.springframework import org.springframework.amqp
It is really strange since I can see it in the formal website and I can see it in lot of examples in the web.
Any idea what is the problem?
A Maven dependency was missing. This is what I was need to add:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

Exception when running ChromeDriver with WebDriverManager in maven project

I am getting an exception when trying to open the ChromeDriver using WebDriverManager in a Maven project.
The framework I am planning is tended to pull the ChromeDriver from WebDriverManager after adding the dependency in the pom.xml and is intended to use Gauge to perform the tests.
The error occurs at the moment it tries to create a new instance for the ChromeDriver when running the tests.
Here is the exception:
Error Message: java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter;
Stacktrace:
org.openqa.selenium.net.UrlChecker.<init>(UrlChecker.java:64)
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255)
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:167)
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
StepTests.setupTest(StepTests.java:26)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:38)
com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.executeHook(HooksExecutor.java:102)
com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.execute(HooksExecutor.java:88)
com.thoughtworks.gauge.execution.HooksExecutor.execute(HooksExecutor.java:45)
com.thoughtworks.gauge.processor.MethodExecutionMessageProcessor.executeHooks(MethodExecutionMessageProcessor.java:65)
com.thoughtworks.gauge.processor.SpecExecutionStartingProcessor.process(SpecExecutionStartingProcessor.java:32)
com.thoughtworks.gauge.connection.MessageDispatcher.dispatchMessages(MessageDispatcher.java:89)
com.thoughtworks.gauge.GaugeRuntime.dispatchMessages(GaugeRuntime.java:104)
com.thoughtworks.gauge.GaugeRuntime.access$100(GaugeRuntime.java:36)
com.thoughtworks.gauge.GaugeRuntime$2.run(GaugeRuntime.java:85)
java.lang.Thread.run(Unknown Source)
When running this code:
import com.thoughtworks.gauge.*;
import io.github.bonigarcia.wdm.ChromeDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.thoughtworks.gauge.Step;
import static org.junit.Assert.assertEquals;
public class StepTests {
//Holds the WebDriver instance
private WebDriver webDriver;
#BeforeSuite
public static void initializeDriver(){
ChromeDriverManager.getInstance().setup();
}
#BeforeSpec
public void setupTest(){
webDriver = new ChromeDriver();
}
--test code--
#AfterSuite
public void closeDriver(){
if (webDriver != null) {
webDriver.quit();
}
}
}
Please inform me if there is something more you need to know to find a solution.
You have a version conflict in Guava. Selenium WebDriver (not WebDriverManager) depends transitively of a given version of Guava, and it seems you are using another one in your project. I would use the latest versions of both.
Yes, working for me after adding the guava dependency :
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>
1st Possible Solution
2nd Possible Solution
Refer this answer only if the problem is not fixed with the 1st Solution.
I have faced this issue and found no accepted answers on SO. I have figured this out by reading it on a non-SO link and pasting it here for future references.
We need to figure out the exact problem first.
If you are using IntelliJ or Eclipse, you need to go to the Run/Debug Configurations, and add a VM argument,
-ea -verbose:class
Now, re-run your test.
This will start printing out the classes and the jars from which those classes are being imported and used. In your specific case, if you search for SimpleTimeLimiter, you will see the package from which it is imported.
Since, there has been a conflict of package versions, this error has come up. One jar dependency would be referring to an earlier guava version and this jar would be present early in the classpath. This will avoid the intended class-path to be used.
To be more precise, there would be some package which is importing guava earlier than the one which you have written in your pom.xml.
How is that possible?
Let us assume, yours is a project which imports a package dog-2.0.jar and animal-2.0.jar. Now, you might be unaware that dog-2.0.jar internally imports animal-1.0.jar. So, owing to this dependency of imports, JVM will import a class named Animal.class which would be coming from animal-1.0.jar instead of the Animal.class you / your project is expecting from animal-2.0.jar.
And then?
JVM will get the reference of Animal.class even before it reaches your intended import of animal-2.0.jar. Hence, the order in which the jar files are being imported (class-path) will un-intentionally mess with this transitive dependency.
What can I do?
You can right-click on your project in INtelliJ and something similar for Eclipse. Click on
Open Module Settings -> Click on Dependencies
You will get the list of jars being imported here. You can re-arrange the order of the jars. You can push dog-2.0.jar right below your animal-2.0.jar dependency. This will fix the problem.
I resolved this issue by changing the version of guava dependency in pom.xml to 23.0.
If it is still not working for you, try changing the version of gson dependency in pom.xml to 2.8.2 or 2.8.5.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

Spring Framework 4.3.1 mail not resolved

I updated Spring Framework to 4.3.1, now I am getting an error:
The import cannot be resolved
for the following imports:
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
I have the following libraries for springframework 4.3.1;
spring-core-4.3.1.RELEASE.jar,
aop, aspects, beans, context, context-support,expression, instrument,
instrument-tomcat, jdbc, jms, messaging, orm, tx, websocket
I am not using Maven. Others: Java 8, Liferay 4.3.1, Hibernate 5.2. How can I fix it?
The mail library is found in spring-context-support so download spring-context-support-4.3.1.RELEASE.jar and add that in your classpath
Without maven you may know that you must place the jar in classpath. Follow the jar.
Java Mail Jar
Check those steps on link above and you'll get it.
Spring Mail Integration
If work, tell us a feedback.
Regards
If it was Maven you could add the following to your dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>

Resources