Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/selenium-tests: selenium tests that replicate the existing e2e tests #3664

Closed
wants to merge 17 commits into from

Conversation

BoardJames
Copy link

Description

Since Cypress only supports Chrome (and derivatives) currently and it has some other limitations to do with tab navigation and selection I decided to explore Selenium testing.

It still has limitations - notably actions like Shift+Click or key combinations like Ctrl+a don't seem to be possible on Firefox because Selenium web-driver for node does not support the new W3C web driver specification yet.

Run in Chrome:

npm run test-browser

Run in Firefox:

test_browser=firefox npm run test-browser

Note in theory you should be able to change the test_browser environment variable to specify other browsers like ie, edge and safari but I have not tried it yet.

How Has This Been Tested?

The tests have been run on Firefox and Chrome on Linux Mint.

Screenshots (jpeg or gifs if applicable):

selenium-tests-demo

Types of changes

New feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@BoardJames BoardJames self-assigned this Nov 27, 2017
@youknowriad
Copy link
Contributor

I'm aware Cypress has limitations but I personally don't think we should use several frameworks for our tests. If we were to change, I think we should change all our tests and from previous experiences, Selenium adds a lot of burden and maintainability issues because of random errors. I think we should just hold on testing those areas for now or try to test the smaller bits using unit tests.

Not saying we shouldn't look for alternatives for Cypress in the future if we find it doesn't do the job properly but It has proven to be stable and pretty easy to maintain and work with IMO.

@BoardJames
Copy link
Author

I'm aware Cypress has limitations but I personally don't think we should use several frameworks for our tests. If we were to change, I think we should change all our tests and from previous experiences, Selenium adds a lot of burden and maintainability issues because of random errors. I think we should just hold on testing those areas for now or try to test the smaller bits using unit tests.

I have already ported all the existing Cypress tests so we can switch to Selenium completely. It was actually a pretty nice experience. The main point of trickiness was loading up the new page because I had to dismiss a confirmation popup and ensure that the editor was set to visual mode. Things are more verbose but I enjoy the control that it gives you. The only errors I have received so far have not been "random" but were due to changes in page structure (ie changed class names) and they would have also needed to be changed in Cypress.

Not saying we shouldn't look for alternatives for Cypress in the future if we find it doesn't do the job properly but It has proven to be stable and pretty easy to maintain and work with IMO.

We're already hit major limitations in Cypress. @ephox-mogran tried to test keyboard navigation with it and found it could not send a Tab key ( cypress-io/cypress#299 - it looks like this may have been fixed now). I tried to test selection with it and found that typing does not set the selection realistically. I can not test the behavior of Autocomplete with it after spending a day trying and it took me 20minutes to get the test working using Selenium. Weirdly Cypress does not actually seem to be testing the behaviour of Chrome - it is testing the behavior of Cypress which just happens to run in Chrome... Cypress is rapidly evolving at the moment. It may turn out to be a great environment for testing in future but it is insufficient at the moment.

Another counterpoint is that Cypress only tests Chrome (and derivatives). The majority of the developers already test in Chrome every day because that is the primary browser used for development so we really need automated tests that can run on other browsers like Edge, Firefox and Safari.

@codecov
Copy link

codecov bot commented Jan 4, 2018

Codecov Report

Merging #3664 into master will decrease coverage by 1.74%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3664      +/-   ##
==========================================
- Coverage   39.19%   37.45%   -1.75%     
==========================================
  Files         300      277      -23     
  Lines        7095     6707     -388     
  Branches     1307     1222      -85     
==========================================
- Hits         2781     2512     -269     
+ Misses       3620     3536      -84     
+ Partials      694      659      -35
Impacted Files Coverage Δ
editor/components/warning/index.js 0% <0%> (-100%) ⬇️
components/panel/row.js 0% <0%> (-100%) ⬇️
blocks/block-controls/index.js 0% <0%> (-100%) ⬇️
components/panel/color.js 0% <0%> (-100%) ⬇️
blocks/color-palette/index.js 0% <0%> (-90.91%) ⬇️
blocks/alignment-toolbar/index.js 16.66% <0%> (-83.34%) ⬇️
editor/components/post-last-revision/check.js 0% <0%> (-75%) ⬇️
editor/components/post-taxonomies/index.js 28.57% <0%> (-57.15%) ⬇️
blocks/block-alignment-toolbar/index.js 33.33% <0%> (-55.56%) ⬇️
blocks/autocompleters/index.js 0% <0%> (-42.11%) ⬇️
... and 162 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7557026...8f72a17. Read the comment docs.

@gziolo gziolo removed their request for review January 27, 2018 17:21
@youknowriad
Copy link
Contributor

Valid points about cypress here, we're going with Google puppeteer right now. Let's give it try and see how it goes.

Thanks for your time trying alternatives.

#5618

@youknowriad youknowriad deleted the add/selenium-tests branch March 23, 2018 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants