Я преобразовал свой проект Selenium TestNG в maven и написал ту же команду на том же веб-элементе, в версии, отличной от maven, объект был обнаружен, но в maven он не смог его найти (java .lang. NoClassDefFoundError)
это была команда:
// Define Ad
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector("span.close.js-rebateHook")));
WebElement Ad_X = driver.findElement(By.cssSelector("span.close.js-rebateHook"));
// Closes ad if exists
if (Ad_X.isDisplayed()) {
//act.doubleClick(Ad_X).perform();
Ad_X.click();
System.out.println("Closed Ad");
}
else {
;
}
это был результат консоли при запуске maven:
[ERROR] Logo_Exsists(testcases.OpenZafulTest) Time elapsed: 7.9 s <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/Coordinates
at testcases.OpenZafulTest.Logo_Exsists(OpenZafulTest.java:53)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.interactions.Coordinates
at testcases.OpenZafulTest.Logo_Exsists(OpenZafulTest.java:53)
это был результат консоли при запуске без maven (напечатал, а также закрыл объявление):
Closed Ad
, а это мой 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>ZafulSelMaven4</groupId>
<artifactId>ZafulSelMaven4</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ZafulSelMaven4</name>
<url>http://maven.apache.org</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.argument.target>${maven.compiler.target}</maven.compiler.argument.target>
<maven.compiler.argument.source>${maven.compiler.source}</maven.compiler.argument.source>
<appium-java-client.version>7.1.0</appium-java-client.version>
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<suiteXmlFile>testng.xml</suiteXmlFile>
<java.version>1.8</java.version>
<!--Dependency Versions-->
<selenium.version>3.141.59</selenium.version>
<assertj-core.version>3.15.0</assertj-core.version>
<testng.version>7.1.0</testng.version>
<query.version>2.0.0-BETA3</query.version>
<!--Plugin Versions-->
<driver-binary-downloader-maven-plugin.version>1.0.18</driver-binary-downloader-maven-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<!--Configuration Properties-->
<overwrite.binaries>false</overwrite.binaries>
<read.timeout>30000</read.timeout>
<connection.timeout>40000</connection.timeout>
<retry.attempts>4</retry.attempts>
<browser>chrome</browser>
<threads>1</threads>
<remote>false</remote>
<headless>true</headless>
<seleniumGridURL/>
<platform/>
<browserVersion/>
<proxyEnabled>false</proxyEnabled>
<proxyHost/>
<proxyPort/>
<proxyUsername/>
<proxyPassword/>
</properties>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${appium-java-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>${selenium.version}</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>query</artifactId>
<version>${query.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>selenium-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<suitename>Test_Suite</suitename>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>${driver-binary-downloader-maven-plugin.version}</version>
<configuration>
<rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml</customRepositoryMap>
<overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist>
<onlyGetDriversForHostOperatingSystem>false</onlyGetDriversForHostOperatingSystem>
<fileDownloadRetryAttempts>${retry.attempts}</fileDownloadRetryAttempts>
<fileDownloadReadTimeout>${read.timeout}</fileDownloadReadTimeout>
<operatingSystems>
<windows>true</windows>
<linux>true</linux>
<mac>true</mac>
</operatingSystems>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
<systemPropertyVariables>
<browser>${browser}</browser>
<screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
<remoteDriver>${remote}</remoteDriver>
<gridURL>${seleniumGridURL}</gridURL>
<desiredPlatform>${platform}</desiredPlatform>
<desiredBrowserVersion>${browserVersion}</desiredBrowserVersion>
<proxyEnabled>${proxyEnabled}</proxyEnabled>
<proxyHost>${proxyHost}</proxyHost>
<proxyPort>${proxyPort}</proxyPort>
<proxyUsername>${proxyUsername}</proxyUsername>
<proxyPassword>${proxyPassword}</proxyPassword>
<headless>${headless}</headless>
<!--Set properties passed in by the driver binary downloader-->
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
<webdriver.edge.driver>${webdriver.edge.driver}</webdriver.edge.driver>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<!--This goal makes the build fail if you have test failures-->
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Если кто-нибудь знает причину этой проблемы или как ее исправить, это очень поможет