知道为什么 TestNG 没有运行我的测试吗? 这是类代码(java):
public class main {
@Test
public static void main(String[] args) throws AWTException, InterruptedException
这是 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="test.main"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
我在这里发布了一个用于您的 testng 的演示模板。您只需要参加课程并声明 webdriver 即可。
@BeforeMethod
将在启动任何@Test
之前执行,然后@AfterMethod
希望它能帮助你。
package stackoverflow;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.*;
public class DemoTestNGClass {
public static WebDriver driver;
@BeforeMethod
public void setUp1() throws Exception {
driver= new ChromeDriver();
}
@Test
public void Homepage() throws InterruptedException {
//Your operation
}
@Test
public void ListingPage() throws InterruptedException {
//Your operation
}
@AfterMethod
public void afterresult(){
driver.close();
}
}
TestNG
的 Eclipse 插件。我之前也遇到过这个问题。
我刚刚改变了
import org.junit.Test;
到
import org.testng.annotations.Test;
并且成功了。