This is a workshop about writing your first TestCafe tests and running them locally and with the Sauce Labs Testrunner Toolkit
For Demonstration Purposes Only
The code in these scripts is provided on an "AS-IS" basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub.
This folder contains a few exercises with answers about writing your first TestCafe tests.
The folder also contains a simple setup for TestCafe which can be run locally and with the Sauce Labs
saucectl
-runner.
- Free Sauce account
- Make sure you know how to find your Sauce Labs Username and Access Key by going to the Sauce Labs user settings page
You can install Node.js from the node.js website:
https://nodejs.org/en/download/
Or using Node Version Manager (NVM): https://npm.github.io/installation-setup-docs/installing/using-a-node-version-manager.html
The current version is 18. And any new version from 14+ should be fine
To check if Node was installed, open a terminal and run the command:
node -v
and:
npm -v
I'm using VSCode. But you can use any editor such as WebStorm, or Atom
Install TestCafe package globaly by running the command:
npm install -g testcafe
check it was installed by running the command:
testcafe -v
- Sign up for a free GitHub account
- Fork this repository
- Make sure you are logged into GitHub
- Click the Fork in the upper right of the GitHub.
- Give the repo a ⭐ while you're here 🤩
- Instead of forking this repository, you can clone the project by opening a new terminal and using the following command:
git clone https://github.com/eyaly/testcafe-sauce-workshop.git
- Make sure you are in the root of the project
- Run the following command in the terminal
testcafe chrome tests/specs/demoTest.js
It will run the demoTest file, and the logs will look like this
Expand to see the logs
% testcafe chrome tests/specs/demoTest.js
Using locally installed version of TestCafe.
Running tests in:
- Chrome 108.0.0.0 / Big Sur 11
Demo Fixture
This is a Demo Test :-)
✓ Demo Test
1 passed (3s)
-
Make sure you are in the root of the project
-
Install all dependencies by running the following command in the terminal
npm install
This will install all dependencies, including the
saucectl
CLI.
- The workshop folder holds an 'exe' folder and an 'answers' folder.
The project also contains this folder with tests that you can run locally and on SauceLabs.
To run the tests on your local machine, the only thing you need to have is Chrome. If you have it you can run this
command in a new terminal
testcafe chrome tests/specs/**/*spec.*
It will run all tests in your local Chrome browser.
To run the examples, use the saucectl
-command and select a configuration. This can be done by opening a terminal and type in the
following command:
# For the EU DC, where `#` is the number of the example
npx saucectl run -c ./.sauce/config-ex#.yml
# For the US DC, where `#` is the number of the example
npx saucectl run -c ./.sauce/config-ex#.yml --region us-west-1
Note:
npx
is used here becausesaucectl
is one of thedevDependencies
in this project. Whensaucectl
is installed globally (withnpm install -g saucectl
) then you can usesaucectl
without thenpx prefix
Note: To see all options that
saucectl
is providing type innpx saucectl --help
and in Sauce Labs doc
All below mentioned examples can be found in the .sauce
-folder. You can run the configurations by running
the following command from the root of this folder
# By default all configs run on the EU DC, if you run `saucectl` directly from the command line and you
# want to run on the US DC then add `--region us-west-1` at the end
npx saucectl run -c ./.sauce/config-ex#.yml
Note: The
#
stands for the number of the below mentioned examples.
config-ex1.yml
provides a minimum configuration needed to run the TestCafe tests.
In this example, all tests are executed on a single chrome browser in sequential order.
config-ex2.yml
breaks apart the execution of the tests such that they can run in parallel on separate chrome browsers.
config-ex3.yml
run the login tests on:
- Windows 10 with Chrome, Firefox and MicroSoftEdge
- MacOS 11 with Safari, Chrome, Firefox and MicroSoftEdge
config-ex4.yml
run all tests on iOS simulators
Note: More options can be found in the TestCafe on Sauce Labs documentation
Using saucectl
does not automatically start a Sauce Connect tunnel, which may be advantageous if you want to use an existing tunnel, or if you do not require a Sauce Connect tunnel with your TestCafe tests.
If you would like to run tests with an existing Sauce Connect tunnel, use the flag --tunnel-name
like this
saucectl run --tunnel-name myTunnel
or see the above section on the TestCafe on Sauce Labs documentation.