使用Selenium和Chromedriver运行测试时出现问题。
系统:Windows 10。
浏览器:Chrome 81.0.4044.113。
ChromeDriver:81.0.4044.69。
JDK:14.0.1。
Selenium Client:3.141.59。
IDE:IntelliJ(带有Maven)。
我已经完成的事情:
更新了JDK版本。
通过cmd运行chromedriver.exe,然后验证http://localhost:{port} /状态可用。
更新了chromedriver + chrome浏览器。
重新启动系统。
无需赘言,以上所有方法均无效。 我希望能对此提供一些帮助,在过去的几周中,我一直在尝试对其进行修复,但没有成功。
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'L1000121335', ip: '10.0.0.7', os.name: 'Windows 10', os.arch: 'amd64', os.version:
'10.0', java.version: '14.0.1'
Driver info: driver.version: CustomChromeWebDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:202)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:188)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
at com.ge.miconnect.automation.driverutils.CustomChromeWebDriver.<init>(CustomChromeWebDriver.java:15)
at com.ge.miconnect.automation.driverutils.DriverFactory.setChromeLocalDriver(DriverFactory.java:71)
at com.ge.miconnect.automation.driverutils.DriverFactory.getDriver(DriverFactory.java:41)
at com.ge.miconnect.automation.SeleniumTestBase.startUpBrowser(SeleniumTestBase.java:55)
at com.ge.miconnect.automation.SeleniumTestBase.concreteBeforeMethod(SeleniumTestBase.java:44)
at com.ge.miconnect.automation.testngutils.TestBase.beforeMethod(TestBase.java:52)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:340)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:294)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:683)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:510)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1510)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:26576/status] to be available after 20003 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197)
... 45 more
Caused by: java.util.concurrent.TimeoutException
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:204)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:155)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 46 more
编辑:
SeleniumTestBase
public abstract class SeleniumTestBase extends TestBase {
protected ExtendedWebDriver driver = null;
public void concreteBeforeMethod(ITestContext context) {
String givenRunner = context.getCurrentXmlTest().getParameter("runner");
String givenBrowser = context.getCurrentXmlTest().getParameter("browser");
startUpBrowser(givenBrowser, givenRunner);
}
private void startUpBrowser(String browser, String runner) {
driver = DriverFactory.getDriver(browser, runner);
}
}
DriverFactory
public class DriverFactory {
public static ExtendedWebDriver getDriver(String browser, String runner) {
ExtendedWebDriver driver = null;
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
MutableCapabilities browserCapability = setDesiredCapabilitiesByBrowserName(desiredCapabilities, browser);
if (runner.contentEquals("local")) {
if (browser.contentEquals("firefox"))
driver = setFirefoxLocalDriver((FirefoxOptions) browserCapability);
if (browser.contentEquals("chrome")) {
assert browserCapability instanceof ChromeOptions;
driver = setChromeLocalDriver((ChromeOptions) browserCapability);
}
}
if (runner.contentEquals("remote")) {
try {
String url = "placeholderURL";
System.out.println("Create RemoteWebDriver of " + desiredCapabilities.hashCode());
driver = new CustomRemoteWebDriver(url, browserCapability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return driver;
}
private static CustomChromeWebDriver setChromeLocalDriver(ChromeOptions options) {
String path = null;
if (SystemUtils.IS_OS_WINDOWS)
path = System.getProperty("user.dir") + "/../selenium-tester/drivers/chromedriver.exe";
if (SystemUtils.IS_OS_LINUX)
path = System.getProperty("user.dir") + "/selenium-tester/drivers/chromedriver";
assert path != null;
System.setProperty("webdriver.chrome.driver", path);
return new CustomChromeWebDriver(options);
}
}
CustomChromeWebDriver
public class CustomChromeWebDriver extends ExtendedWebDriver {
public CustomChromeWebDriver(ChromeOptions options) {
this._driver = new ChromeDriver(options);
}
}
扩展的WebDriver
public class ExtendedWebDriver {
protected WebDriver _driver;
}