This is a base project using the testcafe
framework for JavaScript to handle the automated functional tests and reporting.
- Install TestCafe globally
$ npm install -g testcafe
If you want to update the version just use:
$ npm update -g testcafe
- Run the following command to run the test:
$ testcafe <browser> --disable-page-reloads
This project includes a small script to turn XPath to CSS, this doesn't support -
or _
. Use with the following command:
$ node xpathToCSS.js --path <xpath>
For example:
$ node xpathToCSS.js --path /html/body/ui_view/div[2]/top-panel/div/student-top-panel/div/div/a[3]/span
> html > body > ui > div:nth-of-type(2) > top > div > student > div > div > a:nth-of-type(3) > span
We use several options to run and validate tests that come with TestCafe:
- Screenshots on Failure (-S): takes screenshots when a test fails, needs the screenshot folder to be specified.
- Screenshot Folder (-s <path>): this is used to specify wich folder the screenshot need to be saved.
- Skip JS Errors (-e): this enables tests no to fail if there is a JS error on the console.
- Reporter (-r <reporter>): used to specify wich type of reporter to use and the output.
- Disable Page Reloads (--disable-page-reloads): this prevents testcafe from refreshing the whole app for every test and keep session alive.
The project has many npm
commands ready to be used, just put npm run <command>
:
test
: does a normal run of testcafe.
- Flags:
- -e
- --disable-page-reloads
test:screenshot
: runs the tests but generates screenshots when a test fails.
- Flags:
- -e
- --disable-page-reloads
- -S
- -s screenshots
test:bs
: runs the tests on browserstack, by default runs on anSamsung Galaxy S8
.
- Flags:
- -e
- --disable-page-reloads
- -S
- -s screenshots
- -r spec,xunit:report.xml
For this to work you need to have BROWSERSTACK_USERNAME
and BROWSERSTACK_ACCESS_KEY
on your environment variables.
test:ci
: runs tests in headless mode for chrome and firefox.
- Flags:
- -e
- --disable-page-reloads
- -S
- -s screenshots
- -r spec,xunit:report.xml
test:multiple
: runs tests on multiple browsers at the same time, by default onchrome, ie, edge and firefox
.
- Flags:
- -e
- --disable-page-reloads
- -S
- -s screenshots