我右键单击 testng.xml 并作为 testng Suite 运行,但其中的类未运行。
这是我的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mytestpack" >
<test name="Firefox Test">
<parameter name="browser" value="Firefox"/>
<classes>
<class name="mytestpack.MyTestClass" />
</classes>
</test>
</suite>
这是 MyTestClass 代码:
package testing_pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class MyTestClass {
private static WebDriver driver;
@Parameters({"browser"})
@BeforeTest
public void setup(String browser) {
System.out.println(browser);
// If the browser is Firefox, then do this
if(browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
// If browser is IE, then do this
}
}
@Test
public static void test() {
driver.get("http://only-testing-blog.blogspot.in");
String i = driver.getCurrentUrl();
System.out.println(i);
}
@AfterTest
public void teardown() {
driver.close();
}
}
该类本身运行得非常好。不明白为什么 testng 不运行它。它不会抛出任何错误,只是显示:
[TestNG] Running:
C:\Users\Laptops\Desktop\eclipse\workspace\testproject\src\mytestpack\testng.xml
===============================================
mytestpack
Total tests run: 0, Failures: 0, Skips: 0
===============================================
谢谢
最佳答案
将 testng.xml
中的套件名称从 mytestpack
更改为 testing_pack
。 MyTestClass
类位于不同的包下。
关于java - testng.xml 未运行类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29786051/