1

So I am trying to run tests using mvn test -P and it is giving me java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsElement when I run it from the cmd although it is working fine from within eclipse itself.

I have my pages classes src/main/java and my tests in src/test/java, I just can't get why it would work perfectly fine from eclipse but not from the command prompt. I assume it has something to do with the pom.xml but I am not sure

Here is my pom.xml:

<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>selenium</groupId>
<artifactId>taf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>taf</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testNGSuite}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.basedir}/target/classes</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>com.github.javafaker</groupId>
        <artifactId>javafaker</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>5.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.1</version>
    </dependency>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.13.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.4.4</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>4.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.8.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>4.8.0</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.0.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-common</artifactId>
        <version>2.0b1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <id>regression</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>environment</name>
                <value>regression</value>
            </property>
        </activation>
        <properties>
            <testNGSuite>RegressionSuite.xml</testNGSuite>
        </properties>
    </profile>
    <profile>
        <id>full</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>environment</name>
                <value>full</value>
            </property>
        </activation>
        <properties>
            <testNGSuite>testng.xml</testNGSuite>
        </properties>
    </profile>
</profiles>

And that is a part of my projects tree: project tree

1
  • You have posted NOTHING about the tag CMD. Command Prompt (executable name cmd.exe) is the Microsoft supplied command line interpreter on OS/2, Windows CE, and all Microsoft Windows operating systems. Use this tag for questions regarding programming scripts or on commands available to run from the Command Prompt. Add tags for which version of Windows, and tags describing the task or issue. Commented Jan 11, 2020 at 7:19

2 Answers 2

5
Add below dependency to pom.xml file. It worked for me.

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>3.141.59</version>
    </dependency>
Sign up to request clarification or add additional context in comments.

Comments

0

NoClassDefFoundError

NoClassDefFoundError in Java occurs when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. For example, if we have resolved a method call from a class or accessing any static member of a Class and that Class is not available during run-time then JVM will throw NoClassDefFoundError.

This error message...

java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsElement

...implies that Selenium is trying to resolve the particular class at runtime from org/openqa/selenium/WrapsElement which is no more available.


What went wrong :

As per Installing Selenium libraries - Java installation of Selenium libraries for Java is done using adding the following selenium-java dependency in your project pom.xml:

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>3.X</version>
</dependency>

You seem to have used:

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

which should be sufficient to execute your tests.

So, the other dependency for <artifactId>selenium-common</artifactId> seems unnecessary which is of (Jan 01, 2011) and is as follows:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-common -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-common</artifactId>
    <version>2.0b1</version>
</dependency>

Solution :

Perform the following steps:

  • Remome the unwanted additional dependency of <artifactId>selenium-common</artifactId>
  • Do:
    • maven clean
    • maven install
    • maven test

4 Comments

Thanks for your answer. When I did that it gave me a compilation failure and class file for org.openqa.selenium.WrapsElement not found
@YoussefZahran Can you delete the ~\.m2 folder manually and do a fresh maven compile and let me know the status?
I deleted it and then tried again and I am getting this: [INFO] BUILD FAILURE [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project taf: Compilation failure [ERROR] /C:/Users/youss/eclipse-workspace/taf/src/main/java/pages/CheckOutPage.java:[56,20] cannot access org.openqa.selenium.WrapsElement [ERROR] class file for org.openqa.selenium.WrapsElement not found
@Youssef Zahran Was this issue solved or were you able to find the solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.