doc/testing_with_selenium.md
You may run the Selenium tests either natively or in docker.
We're making a few assumptions here:
yarn if you haven't already:brew install yarn
If you find you need an older version of yarn, follow these instructions to install the older version and switch to it:
https://stackoverflow.com/a/52525732/3038677
script/prepare/README.md to setup the prepare
script.You'll use the prepare script later to automate installing and updating Canvas
on your computer.
Note: some features of prepare only work if you have access to Instructure's
Gerrit host. See the README for details.
brew install chromedriver --cask # necessary for running tests in Chrome
brew install geckodriver # necessary for running tests in Firefox
Now let's get Canvas ready to run the tests.
cp config/selenium.yml.example config/selenium.yml
cp config/database.yml.example config/database.yml
prepare to install Canvas plugins and dependencies, create databases,
run database migrations, etc:prepare
You might encounter problems with some Ruby dependencies. The "Dependency Installation" section in the public Canvas LMS Github wiki has some useful tips.
4.a. Optional. Run delayed jobs in the foreground (not all Selenium tests need this but some do):
script/delayed_job run
or run it in the background:
script/delayed_job run &
bundle exec rspec spec/selenium
or run a specific Selenium test:
bundle exec rspec spec/selenium/accounts_spec.rb:36
Selenium tests can be run against headless Chrome by changing a few properties in
config/selenium.yml. Specifically, you'll need to set headless to true and
window_size to something that makes sense, like so:
headless: true
window_size: "1237,974"
This can be useful when you don't need to see what your test is doing, since it can run in the background without stealing focus or interrupting other work. It's especially useful when running specs many times to check for flakiness.
See the Selenium section
of the doc/docker/developing_with_docker.md instructions.
For clarity and reliability, prefer using built-in helper methods instead of relying on numerous expect statements to handle asynchronous operations. Canvas provides many useful helper methods in spec/selenium/test_setup/common_helper_methods/ including:
custom_wait_methods.rb - Contains wait_for, wait_for_new_page_load, and other waiting utilitiescustom_page_loaders.rb - Page loading and navigation helperscustom_selenium_actions.rb - Common Selenium actionscustom_validators.rb - Validation helpers for Selenium testsUsing these helpers makes tests more readable and reliable than chains of expect statements.
expect syntax: Use the expect(value).to matcher syntax consistentlycontext blocks to describe different test scenarioslet for test data: Use let to define reusable test data and objects