-
Notifications
You must be signed in to change notification settings - Fork 26
Testing Guidelines
Please make sure you install the necessary requirements before continuing.
Set up
git clone [email protected]:rackerlabs/helix-ui.git
yarn install
cd test; yarn install; yarn run webdriver:update; cd -;
yarn start
Acceptance Tests
yarn test
Running individual tests
Regression tests:
cd test/
yarn test:regression
Note: You can add more tests to this suite by adding data-visreg="YOUR-SECTION-NAME-HERE"
attributes to the html found in docs/components/**/**/index.html
. It'll name your artifacts according to what you placed in the html attribute data-visreg
for the DOM snapshots, as well as the images that get saved in test/artificats/regressionScreenshots
.
Visreg tests:
cd test/
yarn test:visreg
Note: These tests serve as the "behavior"-centric tests in this project. If you find yourself needing to interact with a component in order to trigger state changes, etc., you should put those tests here.
Creating visreg diffs to share
git checkout -b changing-stuff
# change stuff
git commit -am "style(docs): Refactor lots of less"
# get a personal access token from github
cd test/
yarn visreg
Follow the prompts to include your personal access token, as well as your target branch (master is usually what you want).
This concludes the summary of running tests in helix. For a more in-depth view of the above, continue reading!
This project utilizes visual regression testing, a technique that leverages before/after screenshot comparisons to validate that code is behaving as expected. The best introduction to understanding visual regression testing in helix-ui is to study the previous art used in encore-ui, another component-based UI toolkit. This project's visual regression system was created to address situations where the tech stack of your project doesn't align with the tech stack of the testing tool. This was a serious limitation present in the initial visual regression system written, and was the reason we made the switch to this new tool.
Running yarn install
in the root of the helix-ui project will automatically navigate to the test/
directory, and install the dependencies for the testing software. Running yarn start
in the root of the helix-ui project will automatically start a selenium server in the background, and will stop running when you terminate the development server. It runs on port number 4444
.
See: What if yarn run webdriver
fails? Go to the FAQ
Part of ensuring that web components work is examining the state of the DOM in the source code and comparing it to the state of the DOM after it's been rendered in a browser. This is what DOM snapshots aim to test in a streamlined fashion -- they are located in the test/regression/
directory,
Regression tests are automatically generated. All you need to do is to add an attribute, data-visreg="${UNIQUE_TEST_NAME}"
to any demo component's html and the development server will notice these changes, and do two things:
- Take a DOM snapshot of the state of the component demo DOM post-render.
- Take a picture of the browser screen of this section of html.
The DOM snapshots end up here, and the screenshots end up in test/artifacts/regressionScreenshots
.
Visual regression tests are a mixture of "visual" tests (taking screenshots of web pages and/or elements on that page) and "regression" tests (interacting with elements on a page and verifying correct behaviors and/or states).
DOM snapshots get rendered in a reliable way by the browser, regardless of your platform. Running the test suite using Firefox on Windows will render the same output as running it using Firefox on Linux or Mac. This is not the case with visual regression screenshots! For starters, Windows renders system fonts differently than the system fonts on Mac or Linux, so anything you take a picture of that includes text will render differently on machines running different operating systems.
This core concept appears again for things like screen resolutions, external displays, and timezones. Visual regression testing, in order to be reliable for team-based use, has to be delegated to a dedicated build server. This may be possible in the future using Saucelabs, but for now it's easier to leave these artifacts untracked, and expose a custom command for generating one-off catalogs when the developer needs them.
Sauce Labs allows users to run tests in the cloud on more than 700 different browser platform, operating system and device combinations, providing a comprehensive test infrastructure for automated and manual testing of desktop and mobile applications using Selenium, Appium and JavaScript unit testing frameworks.
Sauce Labs offers automated testing for Continuous Integration (CI) and Continuous Delivery (CD) pipelines, and provides plugin integrations with the many CI platforms including: Jenkins, Bamboo, Travis CI, Circle CI and TeamCity.
It is a proxy server that opens a secure connection between a Sauce Labs virtual machine running your browser tests, and an application or website you want to test that's on your local machine or behind a corporate firewall.
Tunnel is a queue that runs all our selenium tests, and all traffic from each of the test are run under your account automatically and transparently.
Setting up
-
Open the terminal and navigate to the root directory of the helix-ui project. Export the Sauce Labs username and access key.
export SAUCE_USERNAME="your username" export SAUCE_ACCESS_KEY="your access key"
-
Go to the password safe and request permission to access the credentials for Sauce Labs:
After successful login to password safe, the credentials
username and access key
are located under the folderhelix-ui
. -
Download Sauce Connect from:
-
Extract the zip file into your desired location. For example,
user/Documents/sc
. -
From the terminal navigate to the bin folder, from the location where you extracted the zip file. For example,
user/Documents/sc/bin
. -
Execute the binary. For example, for Linux users the command is
./sc
. For Windows users execute thesc.exe
file. -
Optional
In order to execute the test scripts in batch mode in our local,export CI=true
This makes the execution of test scripts faster in our local.
-
Complete the setup and run the following command on your local machine:
yarn test --browsers=chrome --components=buttons/index
This will execute your test script wriiten for button component in a chrome browser using Sauce Labs.
-
In order to view the results of the executed test script executes:
Log in to the Sauce Labs web interface. We can watch the test script run and the results appear in the dashboard. https://saucelabs.com/
-
Execute the following command from the root of the helix-ui project.
yarn test --browsers=chrome,edge --components=search,buttons
The above command will test the button and search components in chrome and edge browsers respectively in Sauce Labs.
-
Log in to Sauce Labs by extracting the
username and password
from the password safe. -
Navigate to the Sauce Labs dashboard. https://saucelabs.com/beta/dashboard/builds
-
We will see all our results for all the test scripts that were executed in the dashboard. Click on the respective
result link
to view the result of the test that was executed from the terminal.For example, for the above test, the results can be obtained from: https://saucelabs.com/beta/builds/6bc29dbdc2d6400c8b5c4fde9d5c290c
-
For each component and for each browser there is a separate visual of created by Sauce Labs. For example, for the above test script we will have
4 different links
.-
Search component in Chrome browser. https://saucelabs.com/beta/tests/932e288bf81e4c92949f86a67a8153a9/commands#4
-
Search component in Edge browser. https://saucelabs.com/beta/tests/241b0e29af8a4a02af5de28e184c15c7/commands#4
-
Button component in Edge browser. https://saucelabs.com/beta/tests/3f54ec6064c7477bb65c66a35bcfa2d9/commands#4
-
Button component in Chrome browser. https://saucelabs.com/beta/tests/7b71e7ab3ff2431e958be3e3f42fe718/commands#4
-
-
Navigate to each of the links and click on
play
to view the visual of each component rendered in the browser.
In Sauce Labs, if all the test cases has passed, you would see Build Success (Green color)
along with the test id on the top of the screen.
If any case has failed, then you would see Build Error (Orange color)
along with the test id on the top of the screen.
NOTE: The individual test case that passed or failed are marked by Green tick mark
and Orange exclamation mark
followed by the test case id.
-
Test Runner:
mocha
-
Assertions:
chai
-
Mocks/Spies:
sinon
+sinon-chai
-
Coverage Reporter:
istanbul
(vianyc
)-
report format:
lcov
(browser viewable)
-
report format:
-
DOM APIs:
jsdom
- allows us to test functionality dependent on DOM APIs
-
ESM Compatibility:
esm
- allows use of ES Module
import
/export
syntax in CommonJS environment (i.e., NodeJS)
- allows use of ES Module
-
Runner:
test/run_unit.js
yarn test:unit # run unit tests
yarn test:coverage # generate coverage report
Specs should be defined alongside their target source. For example:
Example spec file for src/helix-ui/utils/index.js
/* src/helix-ui/utils/index.spec.js */
const Utils = require('./index');
describe('utils', function () {
it('it should do stuff', () => {
expect(Utils).to.do.something;
});
});
We ignore *.spec.js
files from coverage details using the nyc.exclude
configuration in package.json
:
"nyc": {
"exclude": ["src/**/*.spec.js", "test/run_unit.js"]
},
Whatever you wrote there gets put into test/bin/visreg.config.ts
. Edit that file and you should be set.
Whatever you entered for your github PAT gets written to test/.github-token
. Delete or edit that to fix your problem.
If your system doesn't respond to:
platform_gecko='linux64'
platform_chrome='linux64'
[ `uname` == 'Darwin' ] && platform_gecko='macos' && platform_chrome='mac64'
then the selenium server artifacts we grab won't run on your system. Windows users: consider adding support for yourself in a pull request. Otherwise, send a message to the maintainers of this repo for help.
Delete the current snapshot, and rerun regression tests (yarn test:regression
). A new snapshot will be generated. Alternatively, you could also navigate to the test directory and run yarn test:regression -u
.
- WCT is very much biased toward working with the latest browser versions, and the current latest version also required Sun Java 8. I had trouble getting it to run at all on earlier java versions, and trouble getting Selenium to progress past starting the browser until updating to the latest firefox.
- WCT seems to favor having your tests in .html files... which felt a little bit weird to me.
- I was not able to get the a11ySuite to work, it just kept saying
a11ySuite is undefined
. - WCT uses Selenium, but very thinly, it seems that the actual tests run in the context of the browser, possibly through selenium's executeScript call.
- Because of the above, referencing elements and testing clicks/other events, etc... happen within the browser scope. Which means you use those APIs, and the mouse events will be synthetic/programmatic.
- WCT seems slightly biased toward polymer, but not overly so.
Things I didn't try, but would like to if we have more time:
- Testing IE on windows
- Testing using the browser exclusively instead of the WCT command line
- Testing using scripts that aren't HTML scripts
Overall, I think this could be a viable replacement for Protractor in the Web Components project.