WIP: Replace PhantomJS with headless Chrome for Rspec and Spinach tests
To run:
You need to download ChromeDriver 2.31 and install it: http://chromedriver.storage.googleapis.com/index.html?path=2.31/
Current Issues:
-
unknown error: an X display is required for keycode conversions, consider using Xvfb
(e.g. https://gitlab.com/gitlab-org/gitlab-ce/builds/18894684).
Bug report: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772. Some users mention compiling with use_ozone
on Chrome and ChromeDriver solves this problem.
Alternatives: Use xvfb (https://github.com/Automattic/wp-e2e-tests/issues/515#issuecomment-301165065)
-
https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/27344249: Selenium does not support status_code
: https://stackoverflow.com/questions/7908907/how-to-test-the-response-code-with-capybara-selenium -
https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/28861088: Selenium does not support response_headers
-
https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/28877991: Selenium does not support network_traffic
: https://stackoverflow.com/questions/12034013/is-there-any-way-to-log-http-requests-responses-using-selenium-webdriver-firefo/12036058#12036058
Be sure to read https://makandracards.com/makandra/7617-change-how-capybara-sees-or-ignores-hidden-elements about how Chrome/Selenium behaves differently with hidden elements.
Closes #30876 (moved)
Merge request reports
Activity
- Resolved by Stan Hu
mentioned in issue #30876 (moved)
added 1 commit
- 5854ab2f - Convert variants of trigger('click') -> click
- Resolved by username-removed-636429
mentioned in merge request !12071 (merged)
added 212 commits
-
74fbc694...043f8c26 - 210 commits from branch
master
- 0f943c94 - Merge branch 'master' into sh-headless-chrome-support
- 3f81586e - Remove unnecessary ChromeDriver
-
74fbc694...043f8c26 - 210 commits from branch
added ~889916 test labels
added 2731 commits
-
3f81586e...faa2a123 - 2730 commits from branch
master
- 408df2ed - Merge branch 'master' into sh-headless-chrome-support
-
3f81586e...faa2a123 - 2730 commits from branch
mentioned in issue #35900 (closed)
marked the checklist item
unknown error: an X display is required for keycode conversions, consider using Xvfb
(e.g. https://gitlab.com/gitlab-org/gitlab-ce/builds/18894684). as completedadded 1 commit
- ded77e21 - Rename remove_cookie -> delete_cookie in Capybara helper for Selenium driver
@stanhu Thanks for putting the actual command line you used to do this mass-replace! :)
mentioned in merge request !12931 (merged)
added 982 commits
-
ded77e21...2925850c - 981 commits from branch
master
- 09baadca - Merge branch 'master' into sh-headless-chrome-support
-
ded77e21...2925850c - 981 commits from branch
assigned to @mikegreiling
added 1 commit
- 50701b58 - Fix implementation of resize_window for Selenium
added 1 commit
- a5e096ce - Expand Chrome window size to make specs pass
added 1 commit
- 08172ff5 - Expand Spinach window size and remove unsupported trigger calls
added 1 commit
- 7b70d012 - Add return value in form input to make add member specs pass
added 124 commits
-
7b70d012...2b950014 - 123 commits from branch
master
- 07f8105f - Merge branch 'master' into sh-headless-chrome-support
-
7b70d012...2b950014 - 123 commits from branch
While watching TV, I got a bunch more specs to pass here. :) There are a number of unsupported features in Selenium (e.g. retrieving HTTP status codes/headers, inspecting network calls, etc.) that are being used in GitLab with PhantomJS. I think we're better off removing them and/or adding those checks into the controller, if possible.
I also found two bugs in Capybara when trying to call
accept_alert
in headless Chrome:- https://github.com/teamcapybara/capybara/pull/1902
- https://github.com/teamcapybara/capybara/pull/1903
UPDATE: These changes aren't needed if we update the seleinum-webdriver gem, which I have already done.
Edited by Stan Huadded 1 commit
- ad73d242 - Bump selenium-webdriver to 3.5.0 to make Capybara work properly
Doing some further research into methods we can use to obtain HTTP header and status code information from the requests in our integration tests...
In the lengthy selenium issue discussion about why they don't intend to support this feature, they suggest using something like BrowserMob Proxy to obtain these data.
Having looked into BrowserMob proxy, there are some serious downsides... for one, it requires a JAVA runtime which we'd have to bake into our build images. It also apparently has some irritating bugs with the ruby bindings available.
This article lays out some alternatives through the use of browser extensions, and it sounds like a much more workable solution to me.
added 1 commit
- a2cd32b7 - Fix snippets spec: send_keys only works with text areas
added 1 commit
- 247138d4 - Accept the confirm modal to make comment on commit spec to pass
So, here's the idea I'm running with at the moment...
We can create a really simple rack middleware that is only injected on
Rails.env.test?
(similar to how we implementRequestBlockerMiddleware
). This middleware will log the most recent request and response info to emulatepage.status_code
,page.response_headers
, andpage.network_traffic
for inspection via some rspec helper methods (something likelast_request.status_code
orlast_request.response_headers
).added 1 commit
- fab88bc3 - Fix a few failing tests in Spinach merge request specs for Selenium
added 1 commit
- 767dffcc - Fix a few failing specs due to missing accept_confirm
added 202 commits
-
767dffcc...441ba5f3 - 200 commits from branch
master
- d3e81673 - Merge branch 'master' into sh-headless-chrome-support
- 7b5722c8 - Fix a number of failed Spinach tests with Selenium needing accept_alert
-
767dffcc...441ba5f3 - 200 commits from branch
added 61 commits
-
ebd5c309...36ba84cb - 59 commits from branch
master
- 541a082c - Rename find('.ace_editor') -> find('.ace_text-input') to make Chrome happy
- 3e75b7fa - Merge branch 'master' into sh-headless-chrome-support
-
ebd5c309...36ba84cb - 59 commits from branch
added 61 commits
-
ebd5c309...36ba84cb - 59 commits from branch
master
- 541a082c - Rename find('.ace_editor') -> find('.ace_text-input') to make Chrome happy
- 3e75b7fa - Merge branch 'master' into sh-headless-chrome-support
-
ebd5c309...36ba84cb - 59 commits from branch
added 91 commits
-
3e75b7fa...84336b84 - 90 commits from branch
master
- 841a5ef5 - Merge branch 'master' into sh-headless-chrome-support
-
3e75b7fa...84336b84 - 90 commits from branch
added 91 commits
-
3e75b7fa...84336b84 - 90 commits from branch
master
- 841a5ef5 - Merge branch 'master' into sh-headless-chrome-support
-
3e75b7fa...84336b84 - 90 commits from branch
added 156 commits
-
841a5ef5...ce578272 - 154 commits from branch
master
- 7b223f38 - Merge branch 'master' into sh-headless-chrome-support
- 4a4aae7f - Bump .gitlab-ci image to use git 2.13
-
841a5ef5...ce578272 - 154 commits from branch
added 1 commit
- dda33bd7 - Rename JavaScript click -> click() to make karma tests pass
added 1 commit
- 7b79ec07 - Fix milestone Spinach tests by confirming modal only if it is present
added 1 commit
- 3e4b7e98 - Use find_link instead of incorrect jQuery to make Selenium test pass
@mikegreiling I wonder if https://github.com/miyagawa/rack-vcr would work to capture the network calls.
added 100 commits
-
3e4b7e98...19dfd9e9 - 97 commits from branch
master
- 127a986d - Merge branch 'master' into sh-headless-chrome-support
- 55e5c84e - Merge branch 'master' into sh-headless-chrome-support
- 4ab7d2f9 - Fix branch creation Spinach test by clicking on the dropdown
Toggle commit list-
3e4b7e98...19dfd9e9 - 97 commits from branch
added 1 commit
- 1899d543 - Change trigger('click') and trigger('mouseover') -> click
added 1 commit
- 07e95212 - Fix recent_searches_spec.rb by clicking on buttons instead of relying on hidden elements
mentioned in issue #36961
Was going to help with this but @jschatz1 wanted me to work on repo editor first
added 704 commits
-
f0459035...685066cd - 703 commits from branch
master
- 41e5ec8f - Merge branch 'master' into sh-headless-chrome-support
-
f0459035...685066cd - 703 commits from branch
added 1 commit
- 2d58626a - Changed helper methods to use the click method
@jivanvl Yes, I've been merging
master
here. Please feel free to do that, but do not rebase.@stanhu I tried to merge
master
into this, but some of the specs that were already passing started to fail locally. Is there any chance that we could pair on the conflict resolution? Some of those are really trickyadded 660 commits
-
2d58626a...33010da2 - 659 commits from branch
master
- 4c0beb6c - Merge branch 'master' into sh-headless-chrome-support
-
2d58626a...33010da2 - 659 commits from branch
Since this is a very large set of changes, and some of these changes are likely backward-compatible with our PhantomJS/Poltergeist powered specs, I wonder if it would be a good idea to start back-porting as much of these test fixes as possible into master as we do them. This way our ultimate headless Chrome MR will be leaner and less prone to merge conflicts as we continuously merge changes from master.
We might have a showstopper with tests that require cookies, take a look at
spec/features/merge_requests/user_posts_diff_notes_spec.rb
It requires to set a cookie prior to each test, so if I try to use the
set_cookie
method from capybara we get a:undefined method `set_cookie' for #<Capybara::Selenium::Driver:0x00000005ac0580>
So ok this could be worked around using the
execute_script
method from the selenium web driver and set the cookie from the document itself. So if I do:page.driver.execute_script("document.cookie='galleta=true';")
I get a
Failed to set the 'cookie' property on 'Document': Access is denied for this document
So I found it weird that there's no support to adding cookies via the chrome driver and according to the spec we have a "partially complete" support on the "Add Cookie" feature.
https://chromium.googlesource.com/chromium/src/+/master/docs/chromedriver_status.md
We might have to wait a bit until to fully complete the migration of our test suite to chrome headless until this is solved
added 166 commits
-
4c0beb6c...9b137533 - 165 commits from branch
master
- 27a28d99 - Merge branch 'master' into sh-headless-chrome-support
-
4c0beb6c...9b137533 - 165 commits from branch
We might have a showstopper with tests that require cookies, take a look at
spec/features/merge_requests/user_posts_diff_notes_spec.rb
It requires to set a cookie prior to each test, so if I try to use the
set_cookie
method from capybara we get a:undefined method `set_cookie' for #<Capybara::Selenium::Driver:0x00000005ac0580>
I don't think this is a problem. After spending some time researching this, it seems we can set cookies with selenium by using
page.driver.browser.manage.add_cookie
.Here's how we need to modify the syntax:
# before page.driver.set_cookie('sidebar_collapsed', 'true') # after visit '/' page.driver.browser.manage.add_cookie(name: 'sidebar_collapsed', value: 'true')
The
visit '/'
is important becauseadd_cookie
will fail when the browser is currently at an initialabout:blank
page. You need to visit some page in the app's domain before you can set cookies...We could create a simple helper method for this.
The
visit '/'
is important becauseadd_cookie
will fail when the browser is currently at an initialabout:blank
page. You need to visit some page in the app's domain before you can set cookies...@mikegreiling In which case, we should probably visit the 404 page, as its static and thus way faster. Maybe we should wrap this with a method which that can be called in a
before
block, that registers the unset action by itself.@zj unfortunately using the
/
root path is the only one I’ve managed to get working. It seems that the cookie path gets set to whatever the current page’s path is, meaning that cookie will only work in pages who’s path includes the cookie’s path (passingpath: '/some/path'
to set this explicitly doesn’t seem to work).If the path were
/404.html
I don’t know if the cookie would work in/foo/bar/merge_requests/12/diffs
Has anyone been able to handle header manipulation with Selenium? I've been looking around and well things don't look that promising.
Apparently Selenium WebDriver API doesn't support this, according to this GitHub issue
There are some recommended workarounds floating around, but I was wondering if anyone else has done some research of this topic beforehand.
There was some discussion about this earlier in the thread: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12244#note_37466296
added 198 commits
-
d4f3fca9...137c5822 - 197 commits from branch
master
- 76de6327 - Merge branch 'master' into sh-headless-chrome-support
-
d4f3fca9...137c5822 - 197 commits from branch
added 1 commit
- 299213dd - Replaced trigger calls for click, fixed click_on call
added 165 commits
-
7fb47732...3b2d68d3 - 164 commits from branch
master
- b4af5468 - Merge branch 'master' into sh-headless-chrome-support
-
7fb47732...3b2d68d3 - 164 commits from branch
added 5 commits
- 92a3887c - fixed spec/features/issues/filtered_search/dropdown_assignee_spec.rb
- 9d48177c - fixed spec/features/admin/admin_users_spec.rb
- 7a090d59 - fixed spec/features/admin/admin_groups_spec.rb
- 27c00d2e - fixed spec/features/dashboard/groups_list_spec.rb
- 1ec2486c - fixed spec/features/projects/deploy_keys_spec.rb
Toggle commit listadded 4 commits
Toggle commit listadded 1 commit
- 5072ecc6 - Replaced trigger click calls for click, also fixed ace_editor-input test
added 209 commits
-
b452b0c7...a7976905 - 208 commits from branch
master
- bd2822ce - Merge remote-tracking branch 'origin/master' into sh-headless-chrome-support
-
b452b0c7...a7976905 - 208 commits from branch
added 166 commits
-
62364576...18fee306 - 165 commits from branch
master
- f682cc18 - Merge branch 'master' into sh-headless-chrome-support
-
62364576...18fee306 - 165 commits from branch
Looks like the ChromeDriver has been updated to 2.32
https://sites.google.com/a/chromium.org/chromedriver/downloads
mentioned in merge request gitlab-build-images!59 (merged)
@jivanvl I was incorrect earlier when I said we hadn't locked our chromedriver version. I have opened a MR in gitlab-build-images!59 (merged) to update it.
added 36 commits
-
f682cc18...5a23af92 - 35 commits from branch
master
- 356e9aa8 - Merge branch 'master' into sh-headless-chrome-support
-
f682cc18...5a23af92 - 35 commits from branch
added 3 commits
When I was trying this particular spec
gfm_autocomplete_spec.rb
I found out that the ChromeDriver does not support unicode characters from the SMP plane and beyond, only from the BMP plane. So when you try to test something like this'💃speciąl someone💃'
Chrome will throw this particular error:
Selenium::WebDriver::Error::UnknownError: unknown error: ChromeDriver only supports characters in the BMP
I found out that the team behind the chrome driver did manage to get a fix in but the last comment of this thread points out to not being fixed
https://bugs.chromium.org/p/chromedriver/issues/detail?id=187#c12
Any ideas on a work around for this?
added 466 commits
-
035bf5d4...3cbab382 - 465 commits from branch
master
- 02838d5b - Merge branch 'master' into sh-headless-chrome-support
-
035bf5d4...3cbab382 - 465 commits from branch
mentioned in commit simonwex/gitlab-ce@5d4f377b