新设置 eclipse 和 TestNG。我已经从 selenium 网站下载了 Jar 文件 zip,但在执行示例时失败配置:@BeforeMethod setUp java.lang.NoClassDefFoundError:即将到来
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.Assert;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@BeforeMethod
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://tssgmsw006:8080";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testLogin() throws Exception {
driver.get(baseUrl + "/GSSR/views/supplierSelectionAction.action");
driver.findElement(By.linkText("Advanced")).click();
driver.findElement(By.linkText("Basic")).click();
}
@AfterMethod public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
Assert.fail(verificationErrorString);
}
}
}
输出:-
FAILED CONFIGURATION: @BeforeMethod setUp java.lang.NoClassDefFoundError: com/google/common/base/Function
将此 zip 文件的 srcs 文件夹中存在的所有 jar 文件添加到 eclipse 中的构建路径。
http://selenium.googlecode.com/files/selenium-java-2.37.0.zip
我也面临同样的问题。但是,如果您添加所有 JAR 文件(包括 bin 文件夹),则可以解决此错误。