|
1 year ago | |
---|---|---|
.circleci | 2 years ago | |
cypress | 1 year ago | |
.eslintrc.json | 4 years ago | |
.gitignore | 2 years ago | |
.~lock.240228_Userstory HWPA en.docx# | 1 year ago | |
240228_Userstory HWPA en.docx | 1 year ago | |
240228_Userstory HWPA.docx | 1 year ago | |
Jenkinsfile | 4 years ago | |
README.md | 1 year ago | |
Userstory Editor Schulung Sulzbach Teil 1.docx | 1 year ago | |
cypress.config.js | 1 year ago | |
package-lock.json | 1 year ago | |
package.json | 1 year ago |
README.md
- cd to
cypress-example
folder and runnpm install
✔️ Run tests
- If you installed Cypress via npm:
-
cypress test runner (cypress open):
npm run cy:open:web
ORcypress open --env device=web
(change web to mob to switch to mobile view)
-
cypress headless mode (cypress run):
npm run cy:run:web
ORcypress run --env device=web
-
- If you installed Cypress zip:
- import
cypress-example
folder and you are good to go
- import
💡 Information
ℹ️ Feel free to delete .circleCI
folder and Jenkinsfile
from your machine. (These files are for CI to run tests automatically once a week)
🧪 Tests
📁 Tests are located in cypress/e2e
folder
📁 Custom commands are located in cypress/support
folder (.cmd.js
suffix)
📁 Selectors (CSS selectors) are located in cypress/selectors
folder [only difference from cypress default project structure] - not using page object model(POM) design pattern but keeping selectors (only selectors) separately Read more
Stress test
NOTE: this portion is dependant on having the following library installed: cypress-utils This is available here: https://github.com/trentrand/cypress-utils.git
To ensure your Cypress tests are not irregularly failing with false-negatives, stress testing new test files can be a reliable way of filtering out bad test code.
To stress test one or more test files, simply specify the files to run:
cypress-utils stress-test specFileA specfileB
Additional command-line options may be specified, such as the sample size or number of concurrent threads:
cypress-utils stress-test --trialCount 12 --threads 4
See more command-line options with
cypress-utils stress-test --help
🛠️ Configuration
Config files:
cypress.config.js
- Main config file where default behavior of Cypress can be modified. More infoplugins/index.js
- Plugins file is where we can programmatically alter the resolved configuration More info
This test suite is supporting multiple viewports (mobile and desktop). See plugins/index.js
file
One solution is to use cy.viewport() command inside the test, to change the viewports, but very often websites also check user agent to get the device information(and show the mobile view). Since user agent is something we can't change in the middle of the test, we need to pass config value when launching tests. In cypress.config.js
we have a device
parameter and in plugins file index.js
, we decide viewports and user agent parameter values based on that device value.
💠 IDE setup and recommended extensions
- VS Code with following extensions:
- ESLint - to keep your code tidy
- Add Only - enables to add/remove
.only
with one click - Mocha snippets
❔ Q&A
- Why keep selectors separately (not hard-coded to tests)
- tests are much more readable - css selectors are by design hard to read - even if we add data-test attributes. We might need a 2nd child or want to verify that a selector is a child for another element, like
.class2 > ul:nth-child(2)
(alternativeget().find()
orget().parent()
is bad practice because of this ) - in large projects, we might need to re-use the same selectors. Example: in login test, we want to verify that login was successful and for that, we check settings link visibility in header. But the same settings link is also used in header test.
- selector and test logic is separated - when selector is updated, we just need to update 1 selector file and not multiple tests
- tests are much more readable - css selectors are by design hard to read - even if we add data-test attributes. We might need a 2nd child or want to verify that a selector is a child for another element, like
- Is it still E2E test if we use API's instead of UI?
-
all functionality should be tested from UI once. There is no reason to repeat the same UI actions over and over again in each test. Edit article example. End result will be the same - it will catch exactly the same bugs as
full flow/user journey
test would find, (we need to be careful not to leave 'gaps' though) - tests are faster, more stable and independent with this approach, test suite is still E2E.Example: Application/Website has a bug and login button is not working - our settings test would still pass(if there are no bugs in settings), but login test would fail.
-