【问题标题】:Lost UI Shared Context Error - Running protractor tests in headless chrome丢失 UI 共享上下文错误 - 在无头 chrome 中运行量角器测试
【发布时间】:2019-03-14 04:03:39
【问题描述】:

我正在尝试使用 chrome 在本地运行量角器测试,但在无头模式下,我看到了 docs 并在我的配置文件中添加了适当的选项:

capabilities: {
    browserName: 'chrome',
    shardTestFiles: true,
    chromeOptions: {
      args: [ '--headless', '--disable-gpu', '--window-size=800,600' ]
    }
  }

运行时遇到如下错误:

[1009/122000.081:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.

我尝试删除 --disable-gpu 标志,因为我读到这在未来版本的 Chrome 中可能不需要。我目前安装了最新的 Chrome (69.0.3497.100) 并且正在使用 Windows 7。

为了让测试在无头模式下运行,我需要做什么?我的目的是检查我是否可以在本地以无头模式正常运行,然后我想让它在 linux Jenkins 节点上也以 Chrome 无头模式运行,我们目前正在使用 XVFB,但在测试超时时证明它太不稳定了例子。

谢谢

编辑

关于其他人将此标记为重复 - 我应该说当我尝试使用无头选项时我的测试无法运行,而没有设置 chrome 选项,Chrome 会按预期启动并且测试运行并成功通过。

我的测试失败,没有找到此类元素的类型错误,如果我查看失败的屏幕截图,我只会看到黑色背景内的白色方块(可能根据我设置的 --window-size 选项)

【问题讨论】:

  • 希望对您有所帮助:stackoverflow.com/questions/50143413/…
  • 我不是重复的,因为我的测试仅在无头模式下运行时才会失败@Infern0
  • @DebanjanB 这不是重复的,请参阅我的编辑

标签: angularjs angular selenium google-chrome protractor


【解决方案1】:

正如您提到的,您在 linux Jenkins 节点上使用 Chrome 无头模式,您需要考虑以下几个因素:


--禁用显卡

Headless Chrome 首次由 Google 团队 发布为 GA(通用可用性) 时,文章 Getting Started with Headless Chrome 提到:

--disable-gpu \                # Temporarily needed if running on Windows.

一个注释被添加为:

现在,如果您在 Windows 上运行,您还需要包含 --disable-gpu 标志。

根据Headless: make --disable-gpu flag unnecessary 的讨论,很明显:

--disable-gpu 标志在 LinuxMac OSX 上不再需要。一旦 bug SwiftShader fails an assert on Windows in headless mode 得到修复,它在 Windows 上也将变得不必要。

您可以在讨论ChromeDriver showing Lost UI Shared Context

中找到关于幕后发生的事情的详细讨论

所以第一步你需要删除参数:'--disable-gpu'


不稳定的测试

您似乎正在使用参数--window-size=800,600 执行测试,这意味着减少了Viewport

为了利用最大可能的Viewport,您必须通过参数将Chrome 浏览器 初始化为最大化 模式:'start-maximized' p>


角度

Angular 的角度来看,您可以通过使用正确的expected_conditions 来避免超时。您可以在WebDriverWait not working as expected中找到有关不同预期条件的详细讨论


--无头

最后,我不确定您在 中的确切含义...当我尝试使用 headless 选项时,我的测试无法运行,而没有设置 chrome 选项...。或许参数 '--headless' 只能通过 chromeOptions 调用,而没有其他选择。

【讨论】:

    【解决方案2】:

    我在运行时遇到同样的错误 [1010/161441.019:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context。

    但我的测试运行完美。我有你提到这个https://gist.github.com/cvuorinen/543c6f72f8ec917ebfd596802d387aa3

    希望下面的内容对你有帮助

    https://cvuorinen.net/2017/05/running-angular-tests-in-headless-chrome/

    https://developers.google.com/web/updates/2017/04/headless-chrome

    【讨论】:

      猜你喜欢
      • 2018-10-13
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多