java .lang.NoClassDefFoundError: ошибка org / openqa / selenium / WrapsElement при выполнении mvn-теста на основе Selenium - PullRequest
0 голосов
/ 11 января 2020

Итак, я пытаюсь запустить тесты, используя mvn test -P, и он дает мне java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsElement, когда я запускаю его из cmd, хотя он работает нормально из самого затмения.

У меня есть классы страниц src/main/java и мои тесты в src/test/java, я просто не могу понять, почему он отлично работает из затмения, а не из командной строки. Я предполагаю, что это как-то связано с пом. xml, но я не уверен

Вот мой пом. 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>

И это часть моего дерева проектов: дерево проектов

1 Ответ

0 голосов
/ 11 января 2020

NoClassDefFoundError

NoClassDefFoundError в Java происходит, когда Java Виртуальная машина не может найти определенный класс во время выполнения, который был доступен во время компиляции. Например, если мы разрешили вызов метода из класса или получили доступ к любому члену класса stati c и этот класс недоступен во время выполнения, тогда JVM выдаст NoClassDefFoundError.

Это сообщение об ошибке ...

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

... подразумевает, что Selenium пытается разрешить определенный класс во время выполнения из org/openqa/selenium/WrapsElement, который больше недоступен.


Что пошло не так:

Согласно Установка библиотек Selenium - Java Установка библиотек Selenium для Java выполняется с использованием добавив в свой проект следующую селен- java зависимость pom.xml:

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

Вы, похоже, использовали:

<!-- 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>

, которая должна быть достаточным для выполнения ваших тестов.

Итак, другая зависимость для <artifactId>selenium-common</artifactId> кажется ненужной, которая имеет значение (01.01.2011) и выглядит следующим образом:

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

Решение:

Выполните следующие шаги:

  • Напомните ненужное дополнительная зависимость <artifactId>selenium-common</artifactId>
  • Do:
    • maven clean
    • maven install
    • maven test
...