There are multiple projects inside our repo.
Eg.
MainProject/
SubProject_1/
SubProject_2/
After I installed cypress, "Cypress" folders were created for each project.
MainProject/
Cypress
SubProject_1/
Cypress
SubProject_2/
Cypress
Now in package.json file I've got;
Script
{
"cypress:open": "cypress open",
}
When I run npm run cypress:open, it opens up UI for root directory. Which is;
MainProject/
Cypress
If I want to open cypress for different folder as below, how should I try modify the script ?
SubProject_1/
Cypress
Please note that, I've got cypress v10.
When I run Cypress open --project ./SubProject_1/Cypress, it created a folder /SubProject_1/Cypress.
Thanks
I think you want to specify the config file for the particular project,
See Specifying an Alternative Config File
"open:sub1": "cypress open --config-file SubProject_1/cypress.config.js"
Each project config would specify the folders relative to that project.
Related
We do not use the Component Testing feature in Cypress, which was introduced in version 10.x and above. Its an additional burden to close it every time before we land into the test runner.
You can use the --e2e flag when running Cypress via command line to launch directly to the end-to-end test suite. Assuming you're using npm, that would be:
npx cypress open --e2e
If you have a package.json file where you store your scripts, you can modify that script as well.
...
"cypress:open": "npx cypress open --e2e",
...
npm run cypress:open
I am trying to use script aliases in the package.json file.
In order for something like this to open the test runner,
"cy:open:prod": "cypress open --env ENV=production",
I run the command npm run cy:open:prod in the command line in the same folder that package.json is located.
The script runs and opens the test runner, however no spec files are found.
In all the examples I have found it describes this approach. Is there something I am missing in configuation to point it to where my spec files are?
Thanks in advance.
There is nothing basically wrong with the scripts in package.json, they look normal and would not cause the problem you mention.
I suggest you check the specPattern setting in configuration, it should match the naming convention you have chosen to use for your specs.
See e2e settings for more details.
Of you still have trouble with it, start a new project and let Cypress set the configuration for you, it will automatically match up the specPattern to the default value.
I have a Cypress downloaded in zip file for Windows and extracted locally and when I am trying to run any tests, seems like Cypress recurively trying to create an integration/cypress/integration.. folder and failing
Error: ENAMETOOLONG: name too long, stat
'C:\Users\user\work\sources\services\automation\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress\integration\cypress
Is there a workaround for that?
Have you tried change the default integration folder path in your cypress.json file?
Something like
integrationFolder: Another Path
if that solves the issue problably the integration Folder location was misconfigured
I have project B linked to project A with npm link and am trying to run tests from B in A. Project A builds the entire front end and could use other modules than just B and so I want to be able have the test runner use A and its tests but also use tests from the linked project (assuming the linked projects all use similar Cypress directory structures). I first tried this by setting the testFiles attribute in the config to an array like [/path/to/ProjectATestingRoot/integration/**/*.*", "/path/to/ProjectBTestingRoot/integration/**/*.*"]
and running Cypress with integrationFolder to be from project A. While I'm able to see all my tests when I open Cypress, only project A's tests can be run. When I run project B's they get stuck when the browser loads the test and displays the "Your tests are loading..." screen for eternity.
Is there any way that I could run tests from outside the set integration folder? I thought I could write a little plugin to copy the testing files over but that seems more laborious than needed.
Using spec should solve the problem
npx cypress run --spec [abloluteFolderPath}
"testFiles": "**/*.{feature,spec.tsx}",
"integrationFolder": ".",
"ignoreTestFiles": "**/node_modules/**/*{feature,spec.js}"
Add this to your cypress.json. It adds all the files with .spec.tsx ignoring the ones inside the node_module.
https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/unit-testing__application-code
There are 2 options
1 You can specify integrationFolder in the cypress.json
{
//....
"integrationFolder": "cypress/tests"
// or
// "integrationFolder": "tests"
}
More information https://docs.cypress.io/guides/references/configuration#Folders-Files
2 You can specify integration folder for each test run
npx cypress --config integrationFolder=cypress/tests
npx cypress --config integrationFolder=tests
More information https://github.com/cypress-io/cypress/issues/2256#issuecomment-544408366
I have mocked integration tests in the default /cypress/integration directory and have end-to-end tests in /cypress/e2e. I'm attempting to add a script to my package.json file which will specifically run the E2E tests.
I have the following scripts defined:
"scripts": {
"cy:run": "cypress run",
"test:e2e": "npx cypress run --spec \"cypress/e2e/**/*.spec.ts\"",
}
When I do a npm run test:e2e, I see the following:
npx cypress run --spec "cypress/e2e/**/*.spec.ts"
Can't run because no spec files were found.
We searched for any files matching this glob pattern:
cypress\e2e***.spec.ts
I've also tried running a specific test in the command line using the following two commands with the same unsuccessful result:
npx cypress run --spec "cypress\e2e\enterprise\taxpayer.spec.ts"
npm run cy:run -- --spec "cypress\e2e\enterprise\taxpayer.spec.ts"
The spec file itself starts with a describe() function block.
This answer says you can use an equals sign, but that's also not working for me.
Any idea why Cypress is not recognizing my test?
Updating your spec file folder should be done via cypress.json (this sits outside your cypress folder and inside the root directory). You need to include this:
"integrationFolder": "./cypress/e2e"
Hence, the CLI should be:
npx cypress run --spec "cypress/e2e/enterprise/taxpayer.spec.ts"
Other configuration (e.g. screenshot folder, etc.) can be found here:
https://docs.cypress.io/guides/references/configuration.html#Folders-Files