使用 webdrivermanager-x.x.x.jar 时不是 download/init 浏览器驱动程序(没有 Maven)
Not download/init browser driver when used webdrivermanager-x.x.x.jar (without Maven)
对于我的 Selenium/Java 项目 [没有 Maven],使用 webdrivrmanager-1.7.2.jar 自动为 chromedriver 下载二进制文件,但我收到 "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory" 消息。
我的代码:
package selenium_webdriver_api;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.ChromeDriverManager;
public class Topic_29_ManageBrowserVersion {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
ChromeDriverManager.getInstance().version("2.33").setup();
// Or: ChromeDriverManager.getInstance().setup();
}
@Before
public void setupTest() {
driver = new ChromeDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
driver.get("https://github.com/bonigarcia/webdrivermanager");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
}
WebDriverManager 依赖于几个库,例如 slf4j-api
、commons-io
、gson
等(请参阅其 pom.xml for the complete list). If you are using WebDriverManager without the help of a build tool (e.g. Maven, Gradle) you need to resolve these dependencies manually. The other option is to generate a fat jar from the source, for example using the maven-assembly-plugin
(info here) or maven-shade-plugin
(info )。
对于我的 Selenium/Java 项目 [没有 Maven],使用 webdrivrmanager-1.7.2.jar 自动为 chromedriver 下载二进制文件,但我收到 "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory" 消息。 我的代码:
package selenium_webdriver_api;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.ChromeDriverManager;
public class Topic_29_ManageBrowserVersion {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
ChromeDriverManager.getInstance().version("2.33").setup();
// Or: ChromeDriverManager.getInstance().setup();
}
@Before
public void setupTest() {
driver = new ChromeDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
driver.get("https://github.com/bonigarcia/webdrivermanager");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
}
WebDriverManager 依赖于几个库,例如 slf4j-api
、commons-io
、gson
等(请参阅其 pom.xml for the complete list). If you are using WebDriverManager without the help of a build tool (e.g. Maven, Gradle) you need to resolve these dependencies manually. The other option is to generate a fat jar from the source, for example using the maven-assembly-plugin
(info here) or maven-shade-plugin
(info