Testcafe - Tests
How to write and maintain testcafe tests
This document describes how one can start writing tests on a test cafe project , and debug of the tests.
Procedure to write general testcafe test
- Find a test case and area that has to be automated.
- Find the ‘-tests.js’ file that the test case has to be added or create a new folder and new .js file for the test under src/test/Testcafe.
- Identify and add the page objects with the selectors information under respective file under src/test/Testcafe/page-objects.
- Identify the need for methods that can be reused by other tests and add it under the page object file.
- Each ‘-tests.js’ file has headers that import the necessary page objects.
- Fixtures innholds URL, before and aftereach test procedures.
- Test cafe tests has a basic format as below.
- Use ’t.debug()' in a testcafe test to start debugging of the test.
- Use breakpoints for the steps to be debugged.
- Use ‘console.log(variable_name)’ to find the runtime value of an variable - which will be logged in VS Code Terminal.
- Rename the test to “test.only” - this will only run the specific test case.
- in testRunner.js, Set “chrome” as browser, Reduce the speed to 0.8 (percentage), debugOnFail : True, stopOnFirstFail: True
- Use ‘–inspect –debug-brk’ in the command line when starting the tests.
- Check for the logs in junit.xml.
- Testcafe continues to work towards implementing a method to debug an application interactively. Refer: https://github.com/DevExpress/testcafe/issues/3244
Basics on POM and Selectors
- config.json has the URLs and app names used in different environment
- Use of objects from POM
- Import page – ‘import page_name from path_to_the_file
- Declare an object for the page - let object_name = new page_name();
- Id – starts with ‘#’
- Class – starts with ‘.’
- Html -> “ul > li”
- test.skip – to skip a test in a test run (The results for the tests goes to Others)