Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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
在Ant构建selenium测试时获取java.lang.NoClassDefFoundError:org/openqa/selenium/WebDriver_Java_Apache_Selenium_Ant - Fatal编程技术网

在Ant构建selenium测试时获取java.lang.NoClassDefFoundError:org/openqa/selenium/WebDriver

在Ant构建selenium测试时获取java.lang.NoClassDefFoundError:org/openqa/selenium/WebDriver,java,apache,selenium,ant,Java,Apache,Selenium,Ant,当我尝试将测试用例作为Java应用程序运行时,它会成功执行。但当我通过Ant运行它时,我得到一个错误,即找不到WebDriver类定义。但是,我已经包含了相应的jar 请告诉我哪里出了问题 下面,测试用例的java文件位于C:\Automation\U Practice\DEPAutomation\src\workflows中 package workflows; import java.io.IOException; import org.openqa.selenium.By; impor

当我尝试将测试用例作为Java应用程序运行时,它会成功执行。但当我通过Ant运行它时,我得到一个错误,即找不到WebDriver类定义。但是,我已经包含了相应的jar

请告诉我哪里出了问题

下面,测试用例的java文件位于C:\Automation\U Practice\DEPAutomation\src\workflows中

package workflows;

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class UploadToken {

public static void main(String[] args) throws InterruptedException, IOException {

    // Variable Declaration
    WebDriver driver = new FirefoxDriver();
    Actions action = new Actions(driver);
    String baseUrl = "https://staging.maas360.com/emc/";
    //String expectedTitle = "MaaS360";
    //String actualTitle = "";
    String uname = "3043275_sagrawal";
    String password = "admin@123";

    //Open Home Page
    driver.manage().window().maximize();
    driver.get(baseUrl);

    //Login
    driver.findElement(By.id("EMail")).sendKeys(uname);
    driver.findElement(By.id("Password")).sendKeys(password);
    driver.findElement(By.id("submit")).click();


    //Go to Enrollments Page
    Thread.sleep(5000);
    WebElement deviceMenu = driver.findElement(By.xpath(".//*[@id='203']"));
    WebElement enrollments = driver.findElement(         By.xpath(".//[@id='766']"));
    action.moveToElement(deviceMenu).perform();
    Thread.sleep(5000);
    enrollments.click();

    //Go to Streamlined Enrollment page
    Thread.sleep(10000);
    driver.switchTo().frame(driver.findElement(By.id("Content")));
    WebElement streamlineButton = driver.findElement(By.id("streamlinedEnrollButton"));
    streamlineButton.click();

    //Upload Token
    Thread.sleep(10000);
    driver.findElement(By.id("tokenNameInput")).sendKeys("Token 1");
    WebElement browseButton = driver.findElement(By.xpath("//input[@id='fileInputTokenFile']"));
    browseButton.click();
    Thread.sleep(10000);

    Runtime.getRuntime().exec("C:/Users/akhandelwal/Desktop/akash.exe");
    Thread.sleep(5000);
    driver.findElement(By.id("confirmFormSubmit")).click();

    //Authenticate token upload
    Thread.sleep(5000);
    driver.findElement(By.id("passwordtext")).sendKeys(password);
    driver.findElement(By.id("confirmPasswordFormSubmit")).click();
    Thread.sleep(10000);

    //Close Browser
    driver.quit();
  }
 }
selenium的所有jar都驻留在C:\Automation\u Practice\DEPAutomation\lib中

这是我的build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="DEP" default="exec" basedir=".">

<!-- set global properties for this build -->
 <property name="src" location="./src"/>
 <property name="build.dir" location="${basedir}/build"/>
 <property name="external.jars" value=".\lib"/>
 <property name="TestOperation.dir" value="${external.jars}/TestOperation" />
 <property name="test.dir" value="${src}/workflows"/>


 <target name="setClasspath">
    <path id="classpath_jars">

        <pathelement path="${basedir}/"/>
        <fileset dir="${external.jars}">
            <include name="**/*.jar"/>
        </fileset>
    </path> 
    <pathconvert pathsep=";" property="test.classpath" refid="classpath_jars" />
 </target>

 <target name="clean">
    <echo message="----------Delete the binary folder and create it again----------" />
    <delete dir="${build.dir}"/>
    <mkdir dir="${build.dir}"/>           
 </target>

 <target name="compile" depends="clean,setClasspath">
    <echo message="----------Compile the source files to ${build.dir}----------" />
    <echo message="classpath:${test.classpath}"/>
    <javac srcdir="${test.dir}" destdir="${build.dir}" debug="on" includeantruntime="false">
        <classpath refid="classpath_jars"/>
    </javac>                    
 </target>

 <target name="exec" depends="compile">
    <jar destfile="${TestOperation.dir}/TestOperation.jar" basedir="${build.dir}">
        <manifest >
            <attribute name="Main-Class" value="workflows.UploadToken" />
        </manifest>
    </jar>

    <java fork="true"  jar="${TestOperation.dir}/TestOperation.jar" />     
 </target>
</project>
Buildfile: C:\Automation_Practice\DEPAutomation\build.xml
clean:
     [echo] ----------Delete the binary folder and create it again----------
   [delete] Deleting directory C:\Automation_Practice\DEPAutomation\build
    [mkdir] Created dir: C:\Automation_Practice\DEPAutomation\build
setClasspath:
compile:
     [echo] ----------Compile the source files to C:\Automation_Practice\DEPAutomation\build----------
     [echo] classpath:C:\Automation_Practice\DEPAutomation;C:\Automation_Practice\DEPAutomation\lib\TestOperation\TestOperation.jar;C:\Automation_Practice\DEPAutomation\lib\apache-mime4j-0.6.jar;C:\Automation_Practice\DEPAutomation\lib\bsh-1.3.0.jar;C:\Automation_Practice\DEPAutomation\lib\cglib-nodep-2.1_3.jar;C:\Automation_Practice\DEPAutomation\lib\commons-codec-1.10.jar;C:\Automation_Practice\DEPAutomation\lib\commons-collections-3.2.1.jar;C:\Automation_Practice\DEPAutomation\lib\commons-exec-1.3.jar;C:\Automation_Practice\DEPAutomation\lib\commons-io-2.4.jar;C:\Automation_Practice\DEPAutomation\lib\commons-lang3-3.4.jar;C:\Automation_Practice\DEPAutomation\lib\commons-logging-1.1.3.jar;C:\Automation_Practice\DEPAutomation\lib\cssparser-0.9.16.jar;C:\Automation_Practice\DEPAutomation\lib\gson-2.3.1.jar;C:\Automation_Practice\DEPAutomation\lib\guava-18.0.jar;C:\Automation_Practice\DEPAutomation\lib\hamcrest-core-1.3.jar;C:\Automation_Practice\DEPAutomation\lib\hamcrest-library-1.3.jar;C:\Automation_Practice\DEPAutomation\lib\htmlunit-2.17.jar;C:\Automation_Practice\DEPAutomation\lib\htmlunit-core-js-2.17.jar;C:\Automation_Practice\DEPAutomation\lib\httpclient-4.4.1.jar;C:\Automation_Practice\DEPAutomation\lib\httpcore-4.4.1.jar;C:\Automation_Practice\DEPAutomation\lib\httpmime-4.4.1.jar;C:\Automation_Practice\DEPAutomation\lib\jcommander-1.29.jar;C:\Automation_Practice\DEPAutomation\lib\jetty-io-9.2.11.v20150529.jar;C:\Automation_Practice\DEPAutomation\lib\jetty-util-9.2.11.v20150529.jar;C:\Automation_Practice\DEPAutomation\lib\jna-4.1.0.jar;C:\Automation_Practice\DEPAutomation\lib\jna-platform-4.1.0.jar;C:\Automation_Practice\DEPAutomation\lib\junit-dep-4.11.jar;C:\Automation_Practice\DEPAutomation\lib\nekohtml-1.9.22.jar;C:\Automation_Practice\DEPAutomation\lib\netty-3.5.7.Final.jar;C:\Automation_Practice\DEPAutomation\lib\phantomjsdriver-1.2.1.jar;C:\Automation_Practice\DEPAutomation\lib\sac-1.3.jar;C:\Automation_Practice\DEPAutomation\lib\selenium-java-2.46.0-srcs.jar;C:\Automation_Practice\DEPAutomation\lib\selenium-java-2.46.0.jar;C:\Automation_Practice\DEPAutomation\lib\serializer-2.7.2.jar;C:\Automation_Practice\DEPAutomation\lib\testng-6.8.5.jar;C:\Automation_Practice\DEPAutomation\lib\websocket-api-9.2.11.v20150529.jar;C:\Automation_Practice\DEPAutomation\lib\websocket-client-9.2.11.v20150529.jar;C:\Automation_Practice\DEPAutomation\lib\websocket-common-9.2.11.v20150529.jar;C:\Automation_Practice\DEPAutomation\lib\xalan-2.7.2.jar;C:\Automation_Practice\DEPAutomation\lib\xercesImpl-2.11.0.jar;C:\Automation_Practice\DEPAutomation\lib\xml-apis-1.4.01.jar
    [javac] Compiling 3 source files to C:\Automation_Practice\DEPAutomation\build
exec:
      [jar] Building jar: C:\Automation_Practice\DEPAutomation\lib\TestOperation\TestOperation.jar
     [java] java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
     [java]     at java.lang.Class.getDeclaredMethods0(Native Method)
     [java]     at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
     [java]     at java.lang.Class.privateGetMethodRecursive(Unknown Source)
     [java]     at java.lang.Class.getMethod0(Unknown Source)
     [java]     at java.lang.Class.getMethod(Unknown Source)
     [java]     at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
     [java]     at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
     [java] Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
     [java]     at java.net.URLClassLoader.findClass(Unknown Source)
     [java]     at java.lang.ClassLoader.loadClass(Unknown Source)
     [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     [java]     at java.lang.ClassLoader.loadClass(Unknown Source)
     [java]     ... 7 more
     [java] Error: A JNI error has occurred, please check your installation and try again
     [java] Exception in thread "main" 
     [java] Java Result: 1
BUILD SUCCESSFUL
Total time: 2 seconds