[英]I'm running testng from command line but no tests get executed
如果我从Eclipse IDE运行testng.xml,那么一切都会很好; 但是如果我尝试从命令行运行它们,那么我会看到以下内容
我的课程如下,当我从Eclipse IDE运行时,其测试运行良好:
package package1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Example1 {
public static WebDriver driver;
@BeforeTest
public void launchBrowser() {
System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
}
@Test(priority = 1)
public void verifygoogleTitle() {
driver.get("http://www.google.com");
Assert.assertEquals("Google", driver.getTitle());
}
@Test(priority = 2)
public void verifyyahooTitle() {
driver.get("https://in.yahoo.com");
Assert.assertEquals("Yahoo", driver.getTitle());
}
@Test(priority = 3)
public void verifybankofindiaTitle() {
driver.get("http://www.bankofindia.co.in/english/home.aspx");
Assert.assertEquals("Bank Of India - Home", driver.getTitle());
}
@AfterClass
public void closeBrowser() {
driver.close();
}
}
我的testng.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="package1.Example1"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
[更新]扩展日志:
我有类似的问题。 如果我是从Eclipse运行的,但是testng.xml运行良好,但是从命令提示符运行的时候; 进行0次测试后得出结果,没有错误。
我的问题是在我的类路径设置中。 我已经将所有TestNG jar文件保存在eclipse项目的lib目录中的一个单独的文件夹中(以便更好地组织),而其余的jar文件则直接位于lib目录中。 当我将lib也添加到我的类路径中时,它运行良好。
设置类路径= D:\\ workspace \\ SeleniumTrials \\ bin; D:\\ workspace \\ SeleniumTrials \\ lib \\ TestNG *; D:\\ workspace \\ SeleniumTrials \\ lib * java org.testng.TestNG testng.xml
让我在这里简单说明您的问题:
Install New Software
或Eclipse Market Place
单独(手动)安装(添加TestNG库)TestNG。 相反,我们可以简单地在pom.xml
指定TestNG依赖项,如下所示: <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope> </dependency>
优点: maven-surefire-plugin
为我们完成了所有下载和配置。
A. Run As TestNG Test
(Eclipse,通过.java文件)
B.以Run As TestNG Suite
(Eclipse,通过testng.xml)
C. Run As maven test
(Eclipse,通过pom.xml)
D.命令行选项。
对于命令行执行: 我们必须在pom.xml
中指定在哪里找到testng.xml
。 例如:
<suiteXmlFiles> <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> </suiteXmlFiles>
为达到这个,
湾 我们必须将testng.xml
移到src/main/resources
C。 通过命令行将目录更改为项目文件夹。
d。 清除以前的依赖项。
即 安装必要的依赖项。
F。 安装构建并执行测试用例。
让我知道这是否回答了您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.