Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法找到或加载主类testABCD_Java - Fatal编程技术网

Java 无法找到或加载主类testABCD

Java 无法找到或加载主类testABCD,java,Java,我创建了一个java应用程序,还导入了selenium服务器独立jar 我的类名是Abc,在calss one测试程序中,打开Firefox浏览器,执行一些任务 我也运行了配置和运行,但它给出了错误的主类不是fount import java.util.regex.Pattern; import java.util.concurrent.TimeUnit; import org.junit.*; import static org.junit.Assert.*; import static or

我创建了一个java应用程序,还导入了selenium服务器独立jar 我的类名是Abc,在calss one测试程序中,打开Firefox浏览器,执行一些任务

我也运行了配置和运行,但它给出了错误的主类不是fount

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Abc {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.google.co.in/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testABCD() throws Exception {
    driver.get(baseUrl + "about:home");
    driver.findElement(By.id("searchText")).clear();
    driver.findElement(By.id("searchText")).sendKeys("google.com");
    driver.findElement(By.id("searchSubmit")).click();
    driver.findElement(By.id("lst-ib")).clear();
    driver.findElement(By.id("lst-ib")).sendKeys("gmail.com");
    driver.findElement(By.linkText("Gmail - Google")).click();
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

您提供了一个名为
ABC
的类,而没有其他类。您报告(在问题标题中)投诉是找不到类
testABC
。根据您所说和介绍的内容,我不明白为什么错误消息会令人惊讶。找不到类
testABC

可能我弄错了,但编译器是否在抱怨找不到主类或找不到主方法?如果你想执行你的类,你需要

public static void main(String args[]){
//something
}

还是我完全错了?

您不是在创建独立的程序,而是编写了junit测试

由于您使用的是junit测试用例,如果您使用的是junit 4,那么您应该按照以下方式通过命令行运行:

java -cp .:<path to junit*.jar> org.junit.runner.JUnitCore Abc
java-cp.:org.junit.runner.JUnitCore Abc
如果您使用的是Junit 3,则应使用:

java -cp .:<path to junit*.jar> junit.textui.TestRunner Abc
java-cp.:junit.textui.TestRunner Abc
注意:前提是您已经编译了junit测试用例,并且已经有了类文件


如果您使用的是像eclipse这样的IDE(因为您说过运行配置),那么应该单击RunAs->junit test。

您需要使用“junit”启动器配置来运行它,我认为@alias_boubou是正确的,但您提供了一些更详细的信息。您有“运行配置”是什么意思?您使用的是哪个IDE?你到底在干什么?确切的错误消息是什么?