我正面临testNG无法在类路径中找到类的错误。但我很确定我已经提到了正确的课程路径。
这是我的testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="User Registration suite 1" verbose="1" >
<test name="Regression suite 1" >
<classes>
<class name="com.vaannila.domain.UserTest"/>
</classes>
</test>
</suite>
这是我的UserTest.java类:
package com.vaannila.domain;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;
//Java imports
import java.util.concurrent.TimeUnit;
import java.util.List;
public class UserTest {
private WebDriver driver;
private String baseUrl;
@BeforeTest
public void beforeTest() throws Exception {
//giving the location where selenium chrome driver is located in my file system
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
//if chrome driver has to work on a CI server, then we have to additionally install xvfb and reboot the server. So, we are going to circumvent all that and leverage chrome sans GUI via headless mode.
ChromeOptions co = new ChromeOptions();
//Now we have to add headless arguments to our chrome driver
co.addArguments("--headless");
co.addArguments("--start-maximized");
//initializing a chrome driver with driver object
driver = new ChromeDriver(co);
//asking the chrome driver to implicitly wait for 5 seconds before moving on
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//setting the value of baseUrl variable
baseUrl = "http://xx.xx.xx.xx:9999/myuser/userRegistration.htm";
}
@Test
public void userreg() throws InterruptedException{
//this step opens up chrome browser with the aforementioned application
driver.get(baseUrl);
//getting web elements of name and password. Then we send info to those via sendKeys()
System.out.println("Getting ready to register a user by getting details from them");
WebElement name = driver.findElement(By.id("name"));
WebElement password = driver.findElement(By.id("password"));
name.sendKeys("aditya");
password.sendKeys("aditya123");
System.out.println("fields set...");
//getting radio element buttons in our user registration webpage
WebElement radio1 = driver.findElement(By.id("gender1"));
WebElement radio2 = driver.findElement(By.id("gender2"));
WebElement radio3 = driver.findElement(By.id("gender3"));
//toggling radio buttons
radio1.click();
System.out.println("Radio 1 button is selected");
radio2.click();
System.out.println("Radio 2 button is selected");
radio3.click();
System.out.println("Radio 3 button is selected");
//Selecting country from Drop down ( Used Id to identify the element )
Select options = new Select(driver.findElement(By.id("country")));
//selecting India option via select by visible text
options.selectByVisibleText("India");
//Using sleep command so that the change is visible
Thread.sleep(2000);
//selecting USA via select by index mechanism
options.selectByIndex(2);
//using sleep command so that the change is visible
Thread.sleep(2000);
//Print all the options for the selected drop down and select one option of your choice
// Get the size of the Select element
List<WebElement> optionsize = options.getOptions();
int iListSize = optionsize.size();
//using for loop to go through all options in drop down
for(int i=0;i<iListSize;i++) {
//storing the value of an option sValue variable
String sValue = options.getOptions().get(i).getText();
//printing out the variable
System.out.println(sValue);
// Putting a check on each option that if any of the option is equal to 'USA' then select it
if(sValue.equals("India")) {
options.selectByIndex(i);
break;
}
}
//Getting the textarea element of our webpage
WebElement textbox = driver.findElement(By.id("aboutYou"));
textbox.sendKeys("I am a good boy who is looking to learn java");
//getting checkbox elements of our webpage and toggling them
WebElement option1c = driver.findElement(By.id("community1"));
option1c.click();
if(option1c.isSelected()) {
System.out.println("Checkbox is toggled on");
} else {
System.out.println("Checkbox is toggled off");
}
//selecting another element (mailing list option) in our webpage
WebElement mail = driver.findElement(By.id("mailingList1"));
mail.click();
if(mail.isSelected()) {
System.out.println("Checkbox is toggled on");
} else {
System.out.println("Checkbox is toggled off");
}
//getting the submit option of our webpage
WebElement query = driver.findElement(By.cssSelector("input"));
query.click();
System.out.println("done submitting...");
//clearing all the fields of our webpage
name.clear();
password.clear();
textbox.clear();
System.out.println("Fields cleared...");
}
@AfterTest
public void afterTest() throws Exception {
driver.close();
}
}
这是我的build.xml文件:
<?xml version="1.0" ?>
<project name="UserRegistrationAnt" default="war" basedir="." xmlns:sonar="antlib:org.sonar.ant">
<!-- Beginning of project dir definition -->
<property name="testng.xml.file" value="testng.xml" />
<property name="basedir" location="." />
<property name="src" location="${basedir}/src" />
<property name="lib" location="${basedir}/WebContent/WEB-INF/lib" />
<property name="build" location="${basedir}/target/classes" />
<property name="war-file" location="${basedir}/dist" />
<property name="test-reports" location="{basedir}/test-reports" />
<!-- End of project dir definition -->
<!-- Beginning of sonar properties definition -->
<property name="sonar.host.url" value="http://xx.xx.x.xxx:9000" />
<property name="sonar.projectKey" value="9bc89a6e0d659c33ef4b61b27dc486b1f9075241" />
<property name="sonar.projectName" value="9bc89a6e0d659c33ef4b61b27dc486b1f9075241" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="${src}" />
<property name="sonar.java.binaries" value="${build}" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<!-- End of sonar properties definition -->
<!-- Definition of external dependencies location -->
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Making dirs for compiled, war file and test reports-->
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${war-file}" />
<mkdir dir="${test-reports}" />
</target>
<!-- Compilation of our source and test code -->
<target name="compile" depends="init" >
<javac destdir="${build}" debug="true" srcdir="${src}" classpathref="compile.classpath" includeantruntime="false" />
</target>
<!-- Execution of testng -->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="compile.classpath" />
<target name="tests" depends="compile">
<testng outputdir="${test-reports}" classpathref="compile.classpath" haltOnFailure="true">
<classpath location="{build}" />
<xmlfileset dir="${basedir}" includes="${testng.xml.file}" />
</testng>
</target>
<!-- Execution of sonar analysis -->
<target name="sonar" depends="compile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- update the following line or put sonar-ant-task-*.jar in $ANT_HOME/.ant/lib folder -->
<classpath path="/opt/ant/apache-ant-1.10.5/lib/sonarqube-ant-task-2.5.jar" />
</taskdef>
<!-- Execute SonarQube scanner for ant analysis -->
<sonar:sonar />
</target>
<target name="war" depends="compile">
<war destfile="{war-file}/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="${basedir}/WebContent"/>
<lib dir="${lib}"/>
<classes dir="${build}"/>
</war>
</target>
<!--target name="clean">
<delete dir="dist" />
<delete dir="build" />
<delete dir="reports" />
</target-->
<target name="all" depends="init, compile, tests, sonar, war" description="one single target to fire up every ant build stage" />
</project>
关于这个错误我完全是空白。我已经引用了this link,但我的构建在eclipse IDE和cmd.exe中没有出现故障,但在Atlassian bamboo CI服务器中出现上述错误时失败。所以这个问题和我的完全不同。我无法清理并在CI服务器中进行构建。
我需要帮助来解决这个错误。
糟糕...我在qazxsw poi目标下错过了qazxsw poi附近的qazxsw poi。
抱歉,添麻烦了。
一个指向每个人的指针:对类名,变量替换等非常小心。一个简单而愚蠢的错误可能会使你的进程停止,而这些错误很难找到。
问候
阿迪亚