Atlassian Bamboo Logs:[testng] 在类路径中找不到类:com.vaannila.domain.UserTest
Posted
技术标签:
【中文标题】Atlassian Bamboo Logs:[testng] 在类路径中找不到类:com.vaannila.domain.UserTest【英文标题】:Atlassian Bamboo Logs: [testng] Cannot find class in classpath: com.vaannila.domain.UserTest 【发布时间】:2018-09-02 08:32:12 【问题描述】:我正面临 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 竹 CI 服务器中失败并出现上述错误。所以这个问题和我的完全不同。我无法在 CI 服务器中清理和构建。
我需要帮助解决此错误。
【问题讨论】:
【参考方案1】:糟糕...我在build
附近错过了$
tests
目标。
抱歉给您添麻烦了。
一个指向所有人的指针:要非常小心类名、变量 换人等等。一个简单而愚蠢的错误可以带来你的进步 停止,而且这类错误很难找到。
问候
阿迪亚
【讨论】:
请接受您自己的答案,以便问题结束。以上是关于Atlassian Bamboo Logs:[testng] 在类路径中找不到类:com.vaannila.domain.UserTest的主要内容,如果未能解决你的问题,请参考以下文章
RoboCopy + Atlassian Bamboo 持续集成
ruby Atlassian Bamboo的示例serverspec测试
Jenkins 和 Atlassian Bamboo 的集成
将 Atlassian Bamboo 用于 .Net 项目的 CI