Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 运行Selenium ant构建-ClassNotFound(简单测试)_Java_Maven_Selenium_Selenium Webdriver - Fatal编程技术网

Java 运行Selenium ant构建-ClassNotFound(简单测试)

Java 运行Selenium ant构建-ClassNotFound(简单测试),java,maven,selenium,selenium-webdriver,Java,Maven,Selenium,Selenium Webdriver,尝试运行书中的第一个测试:Selenium Testing Tools Cookbook,但是当我在项目根文件夹中的CLI中键入ant时,第一个简单测试会得到一个ClassNotFound pl.divix.selenium.chapter01.GoogleSearchTest java.lang.ClassNotFoundException: pl.divix.selenium.chapter01.GoogleSearchTest at java.base/java.lang.ClassLo

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

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

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();
    }
}
包pl.divix.selenium.chapter01;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.By;
导入org.openqa.selenium.support.ui.ExpectedCondition;
导入org.openqa.selenium.support.ui.WebDriverWait;
导入org.junit.*;
导入静态org.junit.Assert.*;
公共类谷歌搜索测试{
私有网络驱动程序;
@以前
公共作废设置(){
驱动程序=新的FirefoxDriver();
driver.manage().window().maximize();
驱动程序。获取(“http://www.google.com");
}
@试验
public void testGoogleSearch(){
WebElement=driver.findElement(By.name(“q”));
元素。clear();
元素。sendKeys(“硒测试…”);
元素。提交();
新的WebDriverWait(驱动程序,10)。直到(新的ExpectedCondition(){
公共布尔应用(WebDriver d){
返回d.getTitle().toLowerCase().startsWith(“selenium testing…”);
}
});
assertEquals(“Selenium testing…-Szukaj w Google”,driver.getTitle());
}
@之后
public void tearDown()引发异常{
driver.quit();
}
}
pom.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>
<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>

4.0.0
pl.divix.selenium
硒书
0.0.1-快照
org.seleniumhq.selenium
硒爪哇
3.14.0
测试
朱尼特
朱尼特
4.12
测试
1.6
1.6
运行
mvn clean test
不会引发任何异常并成功通过编译


更新日期:2019年9月11日结果是我的
destdir
错误,它指向的是报表,而不是
=“${bin}”
。这正按预期工作。

结果是我在
中使用了错误的destdir。您的“lib”目录中是否定义了带有GoogleSearchTest类的JAR文件?这是Ant寻找它的地方,根据你的脚本。@nickolay.laptev不,我不知道,我怎样才能触发它出现在那里?