java - TestNG 未在 eclipse 上运行测试

标签 java eclipse selenium automation testng

知道为什么 TestNG 没有运行我的测试吗? 这是类代码(java):

public class main {
@Test
public static void main(String[] args) throws AWTException, InterruptedException 

这是 eclipse 上的路径: enter image description here

这是 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 的演示模板。您只需要参加类(class)并声明 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();
        }

    }

关于java - TestNG 未在 eclipse 上运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46765098/

相关文章:

java - 如何使用Java正则表达式提取特定单词前后的字符串

Java内部类和静态嵌套类

java - 如何在 OpenCV for Android 的 Touch 框架上绘制多个矩形?

java - 无法点击 'Text' 内的 'dropdown list'

java - 我如何在 testNG 中使用 IAnnotationTransformer?

java - Elasticsearch 传输客户端连接

eclipse - Tomcat 5.5 部署 - 不上课

java - 无法从数据库检索数据。出现运行时错误。这是我的 servlet DBController.java 的一个实例

testing - “断言”与 Selenium 中的 'verify'

java - 安卓磨损 : Is there any reason to use a Time object rather than a Calendar object?