等待时间用于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>
我真的不知道为什么我遇到这个错误。
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
在您的maven pom中,您仅在test
范围内导入实用程序。但是,似乎您正在尝试通过使用main
在正常模式而不是测试模式下运行应用程序。
尝试从pom文件中删除前两个依赖项的<scope>test</scope>
。
顺便说一下,我做了一些阅读,看来该实用程序仅用于测试而非生产。