Awaitility - java.lang.NoClassDefFoundError 试图从 eclipse 运行 程序时抛出

Awaitility - java.lang.NoClassDefFoundError thrown when trying to run the program from eclipse

等待时间用于 synchronizing asynchronous operations。所以我试图将它用于我的自动化项目来处理同步问题。所以我尝试了一些基本程序。

import static org.awaitility.Awaitility.*;
import static org.awaitility.Duration.*;
import static java.util.concurrent.TimeUnit.*;
import static org.hamcrest.Matchers.*;
import java.util.concurrent.TimeUnit;

 public static void main( String[] args )
        {        
            System.setProperty("webdriver.chrome.driver", "C:/Learning/synchronization/Resources/chromedriver.exe");    
            WebDriver driver = new ChromeDriver();
            driver.manage().window().maximize();
            driver.get("http://www.seleniumeasy.com/test/dynamic-data-loading-demo.html");
            WebElement newUserBtn = driver.findElement(By.id("save"));
         WebElement loadingElement = driver.findElement(By.id("loading"));

            // Get a new User
            newUserBtn.click();

            await().atMost(15,TimeUnit.SECONDS).until(loadingElement::getText, not("Loading..."));
            System.out.println("User profile retrieved");
        }

但是每当遇到下面这行,就会抛出下面的异常

await().atMost(15,TimeUnit.SECONDS).until(loadingElement::getText, not("Loading..."));

错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/awaitility/Awaitility
    at com.testing.automation.synchronization.App.main(App.java:35)
Caused by: java.lang.ClassNotFoundException: org.awaitility.Awaitility
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

然后我想到是否遗漏了任何依赖项导致以下错误。但我不确定。我正在使用 Java 8 版本的 Maven 项目。

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.awaitility/awaitility -->
        <!-- https://mvnrepository.com/artifact/org.awaitility/awaitility -->
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>3.1.2</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.awaitility/awaitility-proxy -->
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility-proxy</artifactId>
            <version>3.1.2</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

我真的不知道为什么会收到此错误。
谁能帮我解决这个问题?

在您的 Maven pom 中,您仅在 test 范围内导入该实用程序。但是,您似乎正在尝试 运行 通过使用 main.

正常模式而不是测试模式的应用程序

尝试从 pom 文件中删除 <scope>test</scope> 前两个依赖项。

顺便说一句,我做了一些阅读,看起来这个实用程序是专为测试而不是生产而设计的。