微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的测试注释不起作用,eclipse 要求 main 方法

如何解决我的测试注释不起作用,eclipse 要求 main 方法

我用@Test 尝试了 selenium 代码,但是 eclipse 没有运行它并要求使用 Main 方法。 我添加了 Maven 项目并将 Selenium 和 TestNG 依赖项添加到 pom.xml 请帮助解决我面临的问题 示例代码

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class BaseTest {
    @Test
    public void openbrowser() {
        File file = new File("./src/test/resources/config.properties");
      
    FileInputStream fileInput = null;
    try {
        fileInput = new FileInputStream(file);
    } catch (FileNotFoundException e) {
        e.printstacktrace();
        System.out.println("File not found");
    }
    Properties prop = new Properties();
    
    //load properties file
    try {
        prop.load(fileInput);
    } catch (IOException e) {
        e.printstacktrace();
        System.out.println("Values not found");
    }
    System.setProperty("webdriver.chrome.driver","./src/test/resources/drivers/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get(prop.getProperty("baseURL"));
}

}

在运行它时,我正面临着

Error: Main method not found in class com.digivalsolutions.digiassess.LoginTest,please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

我的 pom.xml 文件

 <dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.3.0</version>
    <scope>test</scope>
</dependency>

解决方法

我认为您应该为您的 IDE 安装 TestNG。您可以查看此 link 了解更多详情。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。