"linkablecontainer not found" when using testcontainers - java

I want to use testcontainers (https://www.testcontainers.org/usage.html)
So I imported the corresponding Maven dependencies:
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-xe</artifactId>
<version>1.10.1</version>
<scope>test</scope>
</dependency>
Then I right clicked the docker icon on taskbar -> Settings -> General
and checked the item:
Expose daemon on tcp://localhost:2375 without TLS
Set the environment variables as described on testcontainers site:
DOCKER_CERT_PATH=C:\Users\username\.docker
DOCKER_HOST=https://localhost:2375
DOCKER_TLS_VERIFY=1
And created a JUnit-test with the code:
#Test
public void test() {
OracleContainer oracleXE = new OracleContainer();
...
However I got the error:
Error:(82, 27) java: cannot access org.testcontainers.containers.traits.LinkableContainer
class file for org.testcontainers.containers.traits.LinkableContainer not found
I've googled for "linkablecontainer not found" and for
"org.testcontainers.containers.traits.LinkableContainer not found" but with no results.
Any ideas what went wrong?

Different case than yours but I got the same error and it seems that it's not that common.
In my case I got the same error when the dependency for the database was not in scope test but the dependency for the testcontainers it was.
For example on pom.xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId>
</dependency>
I forgot to remove <scope>test</scope> from the testcontainers and after that the error was gone.
I guess there isn't a global solution to this error but the cause could be some misconfiguration on pom.xml.

Related

Why do I receive fails when I try to run my framework? [duplicate]

Im having issues running a feature in Cucumber, the feature is very basic as it's from a tutorial.
It is not defined and is as follows:
Feature: Proof that my concept works
Scenario: My first test
Given this is my first step
When this is my second step
Then this is my final step
My Cucumber runner class is as follows:
package cucumber;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#Cucumber.Options(
format = {"pretty", "json:target/"},
features = {"src/cucumber/"}
)
public class CucumberRunner {
}
Also the external .jar files that I have in the project are as follows:
The exception that I'm getting is:
Exception in thread "main" cucumber.runtime.CucumberException: Failed
to instantiate public
cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader)
with [cucumber.runtime.io.MultiLoader#75d837b6]
I've tried to look around online for the solution to this problem but have not had any luck.
I've also discussed with the OP of the tutorial and I'm still awaiting feedback but it has been a while.
I ran into a similar issue and got the same error as you did.
Firstly mention the path to the feature file
features = {"src/cucumber/myfile.feature"}
Anyway, that didn't cause the error.
To just run your Cucumber runner class, all the dependencies you need are
cucmber-junit
cucumber-java and
junit.
I had an additional cucumber-guice which was creating the problem and once I removed it, the error went away and runner was executed successfully.
From the link to the image you have mentioned it looks like you are not using cucumber-guice but still I would recommend you remove other unnecessary cucumber dependencies and try again.
1, I ran into this too few days ago, its simple just remove cucumber-Spring from the dependency.
2 If that doesn't work try updating cucumber-core, cucumber-junit, and cucumber-java all version 1.2.3
I believe the issue is that many of the cucumber add-ins, such as cucumber-testng, cucumber-spring, and (in my case) cucumber-guice, expect the corresponding module they link to be included as well. But apparently the cucumber experts decided not to include this dependency in their pom.xml files, so the problem doesn't manifest itself until runtime.
So (to answer Eugene S's question under LING's answer) if you want to actually use guice with cucumber, you need to also add guice itself as a dependency.
This worked for me, I hope it will work for you as well.
Update your Cucumber dependencies in pom.xml
i.e
cucumber-java (1.2.2)
cucumber-jvm (1.2.2)
cucumber-junit (1.2.2)
And update your Junit dependency as well. (4.11).
The only reason for this error is the version of all the cucumber libraries are not same. It should be like this:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.6</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
First Thing : We would request you to use Cucumber v >=4.0.0 as you are using pretty old dependency(v1.2.5) of Cucumber.
Key Point : We shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome.
Solution: Please remove. cucumber-core, cucumber-java, cucumber-jvm-deps, gherkin and cucumber-html. They're transitive dependencies and will be provided by your direct dependencies.
You can add below set of cucumber minimal dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
After spending a lot of time on this issue, most of the errors I was receiving were due to dependencies and dependencies versions mismatch. Adding these dependencies to pom.xml file worked for me:
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-scala_2.11</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>4.8.1</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.8.1</version>
</dependency>

Unit Tests are getting failed in Java 8 to Java 11 Migration

I'm working on migrating my project from Java 8 to Java 11. So I used, Spring 5.1.0, Java 11, Eclipse 4.16 and Tomcat 9. I'm able to build the source successfully. But when it comes to Tests, they are getting failed.
Here is what I've in pom.xml for tests.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
And my test cases runs absolutely fine with the above dependencies in Java 8. But when I migrate the code to Java 11, I'm getting the below exception.
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing
TestExecutionListener
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener#54e063d] to
prepare test instance [com.test.SomeTest2#4293943]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DefaultTestCDependencyInjectionTestExecutionListenerontext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DefaDefaultTestCDependencyInjectionTestExecutionListenerontextultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
Sample Test Class Structure I've
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {"classpath:test-context.xml"})
public class SomeTestClass {
...
}
Which is getting failed because of the mentioned exception. But, I did some research and found a workaround i.e
to change from:
#ContextConfiguration(locations = {"classpath:test-context.xml"})
to this:
#ContextConfiguration(locations = {"classpath*:/spring/test-context.xml"})
And it works. But the problem is that I'm not allowed to edit the source code. How to achieve it?
If the directory that contains the "spring" directory is what is in your classpath, and not the "spring" directory itself, then this is not a "workaround", but a "fix". If you're not allowed to change anything, then you can't fix anything either.
According to your fix, it seems that test-context.xml is now located at classpath*:/spring/test-context.xml. Therefore, you can try adding the spring folder where test-context.xml is into the class path as well, and then it should work. No code changes needed for this solution. You can read how to do it at How do I add a directory to the eclipse classpath?

cucumber.runtime.cucumberException: Failed to instantiate class CucumberTestDefinition.CucumberStepDefinition

I have gone through all previous StackOverflow issues related to the same. This post will be long so please bear with me. The folders in my cucumber project are ordered as follows:
-src/main/java
-src/main/resources
-src/test/java
-|CucumberRunner (package)
-|CucumberTestRunner.java
-|CucumberTestDefinition (package)
-|CucumberStepDefinition.java
-src/test/resources
-CucumberFeaturesFolder
-|CucumberFeatureFile.feature
Here is a picture of the arrangement of the Project folders if the above order did not make sense to you. Order of project folders inside the project
My pom.xml has the following dependency added (no more dependency):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</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>
My CucumberTestRunner.java file contains the following:
package CucumberRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "CucumberFeaturesFolder/CucumberFeatureFile.feature",
glue = {"src/test.java/CucumberTestDefinition"}
)
public class CucumberTestRunner {}
The error that I get when I try to run CucumberFeatureFile.feature is the following:
cucumber.runtime.CucumberException: Failed to instantiate class CucumberTestDefinition.CucumberStepDefinition
Now, after reading the similar posts mentioned on StackOverflow, I tried changing the version of cucumber-unit & cucumber-java from 1.2.2 to 1.2.0 which also resulted in an error but a different one:
Exception in thread “main” cucumber.runtime.CucumberException: No backends were found
Change
glue = {"src/test.java/CucumberTestDefinition"}
to
glue = {"src/test/java/CucumberTestDefinition"}
Make sure the Java version is compatible with cucumber dependencies and other dependencies added in POM.xml. Earlier I was tried with JDK 7 but after changing to JDK 8, the error/exception was no longer visible at runtime and was able to execute the test successfully.
Restart the Appium Server and run again
Also check the all saved locator. If you create any Mobile/Web element and don't assign any value you can face CucumberException.
#iOSXCUITFindBy(accessibility = "")ERROR REASON
public MobileElement submitButton;
#iOSXCUITFindBy(accessibility = "submit") TRUE
public MobileElement submitButton;

Selenium WebDriver 3.0.1 Actions class missing from selenium-api-3.0.1.jar from Maven repository

I am using Selenium WebDriver 3.0.1 in a Maven based project. This code snippet fails (does not compile):
Actions myActions = new Actions(myWebDriver);
because the org.openqa.selenium.interactions.Actions class is missing from the selenium-api-3.0.1.jar downloaded from maven.
This is the relevant portion of the pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.31.0</version>
</dependency>
I also tested this alternative dependency in pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.0.1</version>
</dependency>
but in both cases the org.openqa.selenium.interactions.Actions class is missing from the downloaded selenium-api artifact.
Searching the class in Maven repository with grepcode.com finds only version 2.47.1 or older.
I downloaded the Selenium Client & WebDriver Language Bindings zip package directly from the http://www.seleniumhq.org/download/ url and the included client-combined-3.0.1-nodeps.jar file does contain the org.openqa.selenium.interactions.Actions class.
It seems that I am missing something ... but I really have no idea how to fix the Maven dependency. Any help will be enthusiastically accepted!
Seems like the org.openqa.selenium.interactions package, including the Actions class, got moved to selenium-remote-driver.
You can either add a dependency to selenium-remote-driver directly, or, even simpler, add a dependency to to selenium-java (that depends on selenium-chrome-driver which in turn depends on selenium-remote-driver). I would try to go with the latter option as this should allow you to get rid of a lot of other explicit dependencies as well.

NoClassDefFoundError while running a valid jar (compiled with dependencies) despite having commons-httpclient and httpcomponents dependencies on pom

I'm trying to automate a simple user act by using selenium webdriver from main method (not under test scope)
When running the following code from the complier it works!
But when running the jar on several cases - facing the following issue
(I'm running on Ubuntu, using java 7)
"Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager"
#Log
public class MainProgram {
public WebDriver driver = new FirefoxDriver();
public static void main(String args[]) {
// Injector injector = Guice.createInjector(new WebModule());
System.out.println("Browser will soon be opened");
MainProgram mainProgram = new MainProgram();
mainProgram.run();
}
public void run(){
driver.get("http://www.google.co.il");
WebElement lookFor = driver.findElement(By.name("q"));
if(!lookFor.isDisplayed()){
driver.close();
log.log(Level.WARNING,"Failed!");
};
driver.close();
}
}
WebDriver dependencies on pom:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.42.2</version>
</dependency>
Case A
when removed -commons-httpclient - received: HttpClientConnectionManager as follows:
<!--
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
<!-- <scope>test</scope>-->
</dependency>
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
-------------------------------------------------------------------------------------------------------------------------------------------
Case B
removed both commons-httpclient + httpcomponents received HttpClientConnectionManager:
<!-- <!–
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>–>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
<!– <scope>test</scope>–>
</dependency>-->
liron#liron-Latitude-3330:~$ java -jar automatic-tests-4.0-SNAPSHOT-jar-with-dependencies.jar
Try
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
---------------------------------------------------------------------------------------------------------------------------------------------
Case C
when both were added to pom - same HttpClientConnectionManager
liron#liron-Latitude-3330:~$ java -jar automatic-tests-4.0-SNAPSHOT-jar-with-dependencies.jar
Browser will soon be opened
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
----------------------------------------------------------------------------------------------------------------------------------------------
I ran into this same issue last night with my WebDriver project, and after a bit of debugging, found out that it was missing the following dependency. After adding them I didn't encounter this exception again.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
You should only need selenium-java in your pom dependencies. See the this graphic # Selenium HQ which explains how parts of Selenium are related. Further, Selenium itself has dependencies on httpclient, you should not need to define those explicitly. If you do have a legitimate need for those, things will collide and you will need to clean that up with exclusions.
After you clean up your pom, you can run mvn dependency:tree to see what is going on in your project.
Adding new google guava helps in my case:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
That's because other dependencies can download old one guava 18 version.
And of course like testphreak said: org.apache.httpcomponents

Categories