当我尝试将我的测试用例作为Java Application运行时,它会成功执行。但是当我通过Ant运行它时,我收到的错误是找不到WebDriver类定义。但是,我已经包括了相应的罐子。
请让我知道我哪里出错。
以下测试用例的java文件位于C:\ Automation_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();
}
}
所有的selen罐子都在C:\ Automation_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>
在运行Ant Build时,我收到以下错误消息:
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