ChromeDriver偶尔挂起,DevTools请求失败。 Chrome无法访问错误

时间:2018-01-25 16:15:42

标签: google-chrome selenium-webdriver webdriver google-chrome-devtools selenium-chromedriver

测试失败偶尔会出现" Chrome无法访问的错误"。

Throwing a WebDriver exception: chrome not reachable
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.26 seconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'XXXXXXXX', ip: 'XXXXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: Driver
Exception : org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'XXXXXXXX', ip: 'XXXXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: Driver
[ERROR] Driver Initialize - Error initializing driver for browser 'CHROME'.  chrome not reachable
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.26 seconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'XXXXXXXXXX', ip: 'XXXXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: Driver

org.openqa.selenium.WebDriverException: chrome not reachable
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.26 seconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:01:39.354Z'
System info: host: 'XXXXXXXX', ip: 'XXXXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: Driver

当我进行一些日志记录时,我发现错误是DevTools请求失败。偶尔会发生这种情况。看起来chromedriver为每个测试创建了一个新的调试端口,有时Chromedriver无法连接到新端口。不知道为什么,也不知道如何解决它。有人经历过这个吗?

    [1516896066.375][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension="C:\Users\mna7158\AppData\Local\Temp\scoped_dir6732_10840\internal" --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12923 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\mna7158\AppData\Local\Temp\scoped_dir6732_15347" data:,
[1516896066.431][DEBUG]: DevTools request: http://localhost:12923/json/version
[1516896068.429][DEBUG]: DevTools request failed
[1516896068.480][DEBUG]: DevTools request: http://localhost:12923/json/version
[1516896068.688][DEBUG]: DevTools request failed
[1516896068.739][DEBUG]: DevTools request: http://localhost:12923/json/version
[1516896070.481][DEBUG]: DevTools request failed
[1516896070.532][DEBUG]: DevTools request: http://localhost:12923/json/version
[1516896070.742][DEBUG]: DevTools request failed
[1516896070.793][DEBUG]: DevTools request: http://localhost:12923/json/version
[1516896072.532][DEBUG]: DevTools request failed

规格:

  • Chrome版本64(64位)
  • OS = Windows 7
  • Chromedriver 2.35
  • Selenium-Java 3.7.1

我收到此错误的示例代码。

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class chromeDriverExample {
public WebDriver driver;
WebDriverWait wait;

@BeforeMethod
public void beforeMethod() {
    System.setProperty("webdriver.chrome.driver", "src//test//resources//drivers//chromedriver.exe");
    System.setProperty("webdriver.chrome.verboseLogging", "true");
    driver = new ChromeDriver();
    wait = new WebDriverWait(driver, 30);
}

@AfterMethod
public void afterMethod() {
    driver.close();
    driver.quit();
}

@Test(invocationCount = 15)
public void chromeTest() {
    driver.get("https://google.com");
    wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
}

}

1 个答案:

答案 0 :(得分:2)

这可能或可能不相关,但我看到类似的东西。由于我的本地Chrome自动更新(macOS)到v64,我们看到非常零星的Selenium TimeoutExceptions。如果我捏造我的Chrome版本并将其固定在版本63,则不会发生这种情况。在v64中已经破坏或改变了一些东西,但我正在努力解决问题。我不知道新的ChromeDriver是否迫在眉睫,并且会修复它。