While running Cypress scripts, some of the cases are getting failed. I want to run only those failed cases to run again.
How can I run only failed test cases in Cypress?
As long as its not integrated directly in Cypess, you can use a npm package like cypress-run
npm install cypress-run --save
Then edit then run command in the package.json and replace the command
cypress run by for example cypress-run --retries 4, this will retry the failed tests 4 times
Cypress has released version 5.0 which has support for retries, see https://docs.cypress.io/guides/guides/test-retries.html for more information
Just add this line in your cypress.json file.
{
"retries":2
}
It will retry your failed Test case for twice.
Related
When I run all my component cypress tests locally on a Macbook pro on a react-vite project with around ~10 tests, I get the following error:
An uncaught error was detected outside of a test:
TypeError: The following error originated from your test code, not from Cypress.
> Failed to fetch dynamically imported module: http://localhost:5173/__cypress/src/cypress/support/component.ts
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
the error is not Consistant and doesn't show up on every run. It also throws on a random test every run. How can I solve this?
update: I think a possible lead could be that I import files on my project with the absolute paths pattern.
For example:
import {comp1, comp2} from 'components'
where as components is configured in my tsconfig.ts file
ok so after countless attempts to fix this and also encountering terminal freezes when I execute
cypress run.
I've gave up and created a bash script to run each of the tests in the code base separately:
set -x
#!/bin/bash
for file in $( find . -type f -name '*.spec.cy.tsx' );
do yarn cypress run --component --browser chrome --spec $file || exit 1
done
for now it seems to get the job done. Hope this helps anyone else that encounters this
I'm running into an error in my testing environment for Typescript where jest <file-path> isn't working, but npm tests is. I have a sample file main.test.ts with the following test:
import * as main from './main';
test('is 1 + 1 = 2?', () => {
expect(1 + 1).toBe(2)
})
Running npm test I have no issues running my tests , and all are said to pass. However, running jest main.test.ts (and similar issues for jest ./src/main.test.ts) I am getting the following error:
Test suite failed to run
Jest encountered an unexpected token
To the best of my knowledge, npm is running jest so I don't see why this might be happening. Thanks
I've a test cases written in cucumber and cypress. The test case run successfully through cypress Test runner, but fails while running through headless mode using the command.
node_modules\.bin\cypress run --spec **/*.features
CypressError: Timed out retrying: `cy.click()` failed because this element is not visible:
Questions:
what is the possible reason to have this element not visible error?
How can i handle the wait in headless mode?
The fix is :
Fix all your issues displayed on the console w.r.t xpaths, sync or
any such.
I am running the protractor Suite (spec file having multiple test cases), If any test case fails, protractor does not continue with the next test case execution and all the rest of test cases also fail.
EXPECTED BEHAVIOR:
Upon failure on any test case, protractor should continue with next test case execution.
I used "Protractor-Fail-Fast" Npm package to stop the rest test case execution if any test case fail. But ideally I am not looking for the same.
But this will not help me!
Just for reference: In Visual Studio MS test, If I created ordered test (same as Spec file in protractor having multiple test cases) and then set test setting like "continue on failure", ordered test execution will continue even if some test case failed.
I am looking for a similar test setting or any solution for protractor.
If you dont't want to stop all tests run just stop using Protractor-Fail-Fast library? Protractor tests run till the end by default even if some of the tests are failed.
set ignoreUncaughtExceptions: true in config file as following:
/**
* If set, Protractor will ignore uncaught exceptions instead of exiting
* without an error code. The exceptions will still be logged as warnings.
*/
ignoreUncaughtExceptions?: boolean;
you can get above description from here
export.config = {
...
ignoreUncaughtExceptions: true
}
Is it normal behavior for karma start, karma init, npm test to not exit after running? I want to run additional commands but I have to open another window to do it.
I believe you should try below config parameter for Karma..
singleRun
Type: Boolean
Default: false
CLI: --single-run, --no-single-run
Description: Continuous Integration mode.
If true, Karma will start and capture all configured browsers, run tests and then exit with an exit code of 0 or 1 depending on whether all tests passed or any tests failed.
Source - http://karma-runner.github.io/1.0/config/configuration-file.html