gpt4 book ai didi

java - 运行 Selenium ant build - ClassNotFound(简单测试)

转载 作者:搜寻专家 更新时间:2023-11-01 03:15:13 25 4
gpt4 key购买 nike

尝试运行本书中的第一个测试:Selenium Testing Tools Cookbook,但是当我键入 ant 时,我得到了第一个简单测试的 ClassNotFound 在我的项目根文件夹内的 CLI 中。

pl.divix.selenium.chapter01.GoogleSearchTest

java.lang.ClassNotFoundException: pl.divix.selenium.chapter01.GoogleSearchTest
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

build.xml

<?xml version="1.0" encoding="UTF-8" ?>
<project name="tests" default="exec" basedir=".">
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="bin" value="./bin" />
<property name="report" value="./report" />

<path id="test.classpath">
<pathelement location="${bin}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="init">
<delete dir="${bin}" />
<mkdir dir="${bin}" />
</target>

<target name="compile" depends="init">
<javac source="1.8" srcdir="${src}" fork="true" destdir="${report}">
<classpath>
<pathelement path="${bin}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>

<target name="exec" depends="compile">
<delete dir="${report}"></delete>
<mkdir dir="${report}"/>
<mkdir dir="${report}/xml"/>

<junit printsummary="true" haltonfailure="no">
<classpath>
<pathelement path="${bin}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>

<test name="pl.divix.selenium.chapter01.GoogleSearchTest" haltonfailure="no" todir="${report}/xml" outfile="TEST-result">
<formatter type="xml" />
</test>
</junit>

<junitreport todir="${report}">
<fileset dir="${report}/xml">
<include name="TEST*.xml"/>
</fileset>
<report format="frames" todir="${report}/html"/>
</junitreport>
</target>

<!--<manifest>
<attribute name="GoogleSearchTest" value="pl.divix.selenium.chapter01"/>
</manifest>!-->


</project>

GoogleSearchTest.java

package pl.divix.selenium.chapter01;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.*;

import static org.junit.Assert.*;

public class GoogleSearchTest {
private WebDriver driver;

@Before
public void setUp() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.google.com");
}

@Test
public void testGoogleSearch() {
WebElement element = driver.findElement(By.name("q"));
element.clear();
element.sendKeys("Selenium testing...");
element.submit();

new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("selenium testing...");
}
});

assertEquals("Selenium testing... - Szukaj w Google", driver.getTitle());
}

@After
public void tearDown() throws Exception {
driver.quit();
}
}

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>pl.divix.selenium</groupId>
<artifactId>SeleniumCookbook</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties><maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target></properties>
</project>

运行mvn clean test 不会抛出任何异常并成功通过编译。

UPDATE 11/09/2019 结果我错了 destdir 它指向报告而不是 ="${bin}"。现在一切正常。

最佳答案

原来我在 <javac 中的 destdir 有误指向报告而不是 ="${bin}"的部分。现在一切正常。

关于java - 运行 Selenium ant build - ClassNotFound(简单测试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57845756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com