Lost UI Shared Context Error - Running protractor

2019-07-26 23:33发布

I am attempting to run protractor tests locally using chrome but in headless mode, I have seen the docs and added the appropriate options to my config file:

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

Upon running, I encounter the following error:

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

I tried removing the --disable-gpu flag as I read this may not be needed in future version of Chrome. I currently have latest Chrome installed (69.0.3497.100) and am using windows 7.

What do I need to do in order to get the tests running in headless mode? My intention is to check I can run in headless mode fine locally and then I want to get it running also in Chrome headless mode on a linux Jenkins node, where we are currently using XVFB but its proving to be too flaky with timeouts in tests for example.

Thanks

EDIT

With regards to others marking this as a duplicate - I should have said that my tests fail to run when I attempt to use the headless option, without the chrome options set, Chrome launches as expected and the test run and pass successfully.

My tests fail with no such element found type errors and if I view the screenshots taken on the failures, I just see a white square inside a black background (probably as per the --window-size option I was setting)

2条回答
Animai°情兽
2楼-- · 2019-07-27 00:07

I have the same error while running [1010/161441.019:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.

but my test runs perfect.I have you referred this https://gist.github.com/cvuorinen/543c6f72f8ec917ebfd596802d387aa3

I hope this below may help you

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

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

查看更多
姐就是有狂的资本
3楼-- · 2019-07-27 00:20

As you mentioned you are using Chrome headless mode on a linux Jenkins node you need consider a few factors as follows:


--disable-gpu

When Headless Chrome was first released as GA (General Availability) by Google Team the article Getting Started with Headless Chrome mentioned that :

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

A note was added as :

Right now, you'll also want to include the --disable-gpu flag if you're running on Windows.

As per the discussion Headless: make --disable-gpu flag unnecessary it was clear that :

The --disable-gpu flag is no longer necessary on Linux or Mac OSX. It will also become unnecessary on Windows as soon as the bug SwiftShader fails an assert on Windows in headless mode is fixed.

You can find a detailed discussion on What happened under the hood in the discussion ChromeDriver showing Lost UI Shared Context

So as a first step you need to remove the argument: '--disable-gpu'


flaky tests

You seem to be executing your tests with the argument --window-size=800,600 which implies a reduced Viewport.

In order to utilize the maximum possible Viewport you must initialize the Chrome Browser in maximized mode through the argument: 'start-maximized'


angular

From Angular perspective, you can avoid timeouts by using the proper expected_conditions. You can find a detailed discussion about different expected_conditions in WebDriverWait not working as expected


--headless

Finally, I am not sure what exactly you meant as in ...my tests fail to run when I attempt to use the headless option, without the chrome options set.... Perhaps the argument '--headless' can be invoked only through chromeOptions and no other alternative.

查看更多
登录 后发表回答