代码之家  ›  专栏  ›  技术社区  ›  AnOldSoul

Chrome驱动程序尝试在CI服务器中加载页面时超时,但在本地工作

  •  3
  • AnOldSoul  · 技术社区  · 8 年前

    我的前端自动化套件正在运行,不幸的是chrome驱动程序无法定位元素。服务器有网络连接,我可以从CI服务器ping url。

                [14:35:40][Step 1/1]       org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of Proxy element for: DefaultElementLocator 'By.id: login_email' (tried for 60 second(s) with 500 milliseconds interval)
                [14:35:40][Step 1/1]        at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
                [14:35:40][Step 1/1]        at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
                [14:35:40][Step 1/1]        at stepdefs.LoginSteps.iFillEmailWithValidEmailAddress(LoginSteps.java:115)
                [14:35:40][Step 1/1]        at ?.When I fill email with valid OTA email address(login.feature:6)
                [14:35:40][Step 1/1]       Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"login_email"}
                [14:35:40][Step 1/1]         (Session info: headless chrome=69.0.3497.100)
                [14:35:40][Step 1/1]         (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.9.0-6-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
                [14:35:40][Step 1/1]       Command duration or timeout: 0 milliseconds
                [14:35:40][Step 1/1]       For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
                [14:35:40][Step 1/1]       Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
                [14:35:40][Step 1/1]       System info: host: 'intelligence-teamcity', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.0-6-amd64', java.version: '1.8.0_181'
                [14:35:40][Step 1/1]       Driver info: org.openqa.selenium.chrome.ChromeDriver
                [14:35:40][Step 1/1]       Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.42.591071 (0b695ff80972cc..., userDataDir: /appdata/TeamCity/buildAgen...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:20897}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 69.0.3497.100, webStorageEnabled: true}
                [14:35:40][Step 1/1]       Session ID: d4f4672a9d49645e1bc8af8b54627aae
    

    下面是我如何创建我的Chrome驱动程序实例。

    System.setProperty("webdriver.chrome.driver",
                "browser-drivers/chromedriver");
    final ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--allow-running-insecure-content");
        chromeOptions.addArguments("window-size=1920x1080");
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--disable-extensions");
        chromeOptions.setExperimentalOption("useAutomationExtension", false);
        chromeOptions.addArguments("--proxy-server='direct://'");
        chromeOptions.addArguments("--proxy-bypass-list=*");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    
        chromeDriver = new ChromeDriver(capabilities);
    

    我做错什么了?为什么它在我的服务器上工作而不是在服务器上(它也安装了Chrome)?任何帮助都将不胜感激。

    更新:当它与UI一起运行时,工作正常。只是无头不起作用

    2 回复  |  直到 8 年前
        1
  •  1
  •   Jesus García Godoy    8 年前

    看起来无头模式不支持不安全的证书,然后页面就不会打开,只打开一个空白页面,找不到任何内容。

    除了

    capabilities.setCapability("acceptSslCerts", true);
    capabilities.setCapability("acceptInsecureCerts", true);
    
        2
  •  0
  •   Bruno Müller    8 年前

    我在前端测试的时候也遇到过类似的问题。尝试降级到稳定的Chrome/Chrome驱动程序版本,看看这是否能修复任何问题。大多数时候,像这样的非理性问题只是通过降级到某些版本来解决的。