Change browser in runtime with cypress - cypress

I have 2 tests running using command:
await cypress.run({
browser: "chrome"
})
How can i run second test on eletron with out changing much in config file. Can i use Cypress.config() in my second test to pass browser as electron?

Related

After enabling the "experimentalInteractiveRunEvents" flag to run the after:spec event in Cypress IDE : after:spec event is not calling

I have enabled the "experimentalInteractiveRunEvents": true in cypress.json to run the after:spec event of cypress-testRail-simple plugin through cypress IDE.
link for plugin : https://github.com/bahmutov/cypress-testrail-simple.git
I am using this event in cypress-testRail-simple's plugin.js file.
I have defined plugin in plugins -> index.js
enabled the flag in cypress.json file:
I have multiple spec files.
When running through command line :
npx cypress run
after:spec - getting called after all the spec run finish.
When running through cypress IDE :
npx cypress open
after:spec - called zero time
reference : how to run the cypress in interactive mode with flag enabled
There's a fundamental difference between npx cypress open (interactive mode) and npx cypress run (command line mode).
Interactive mode
All the specs are run as in a single continuous run, as if they had been written as one spec. Because of this, before:spec is called only one.
Command line mode
All specs are run as separate runs, hence two calls to before:spec.
From After Spec API
When running cypress via cypress open, the event will fire when the browser closes.

Unable to run chrome with Testcafe on macOS

I have been trying without success to run tests on chrome using Testcafe in MacOS. I have generated all the certificates required but when launching chrome with testcafe it reports ERR_SSL_VERSION_OR_CIPHER_MISMATCH. Below are the arguments I am passing -
yarn run testcafe --hostname localhost --ssl 'pfx = testingdomain.pfx;rejectunasuthorized=true;--ssl key = testingdomain.key;cert=testingdomain.crt' "chrome --use-fake-ui-for-media-stream --allow-insecure-localhost --allow-running-insecure-content" e2e/testmac.js --live
When I remove loading PFX cert and run below, I am able to get to the webpage, but cant access mic and camera. My command to maximzie browser window also does not work
yarn run testcafe --hostname localhost "chrome --use-fake-ui-for-media-stream --allow-insecure-localhost --allow-running-insecure-content --live" e2e/testmac.js --ssl 'key=testingdomain.key;cert=testingdomain.crt' --live
My simple test -
import { Selector, ClientFunction } from 'testcafe';
fixture`Audio Configuration Combination`.page`http://XXX.XXX.XXXXXX/sandbox/index.html`;
test('Launch SDK,', async (browser) => {
await browser.getCurrentWindow().maximizeWindow().wait(100000);
});
I have problems only on mac. Same setup is working fine on windows. I need to access mic and camera and so passing in "--use-fake-ui-for-media-stream". But I dont see a camera preview. Passing in "--use-fake-device-for-media-stream" loads up fake devices which is something I dont need.
Any help is greatly appreciated.
According to this comment on GitHub, it should be sufficient to use either of the two approaches to mock user media, not necessarily both. If you specify testcafe --hostname localhost, you shouldn't need to specify --ssl at all.
I ran the following test from the GitHub discussion mentioned above on macOS:
mock-media-test.js
fixture `WebRTC`
.page`https://webrtc.github.io/samples/src/content/getusermedia/canvas/`;
test(`test`, async t => t.wait(30000));
I used the following command:
testcafe "chrome --use-fake-ui-for-media-stream" mock-media-test.js --hostname localhost
The test ran as expected, and the page displayed the stream from my camera. The --use-fake-device-for-media-stream flag worked for me as well.

Cypress browser refreshes browser on changing test file

I am using Cypress for end to end testing, and I would like to be able to see all run test suites, in the browser, even after they are run. Currently, after each test suite is completed (test which are stored in separate files), the browser reloads and I cannot see previously run tests, and after the final test suite, the browser closes. Is there an option to change this behavior so that I can run all test files, have all the results visible in the browser and that the browser doesn't close at the end?
I am currently running tests using this command: ./node_modules/.bin/cypress run --headed --spec 'cypress/integration/tests/*'
where /tests is the folder where I currently have my files.
I have added --no-exit but in this case cypress doesn't move to the next test file and only the first one runs.
A workaround solution could be to generate reports with Mochawsome, for each Test Spec, and then merge and view those rendered reports. The reports will contain the results from the tests, test bodies, any errors that occurred and some other bits of information.
If you read through the page in the link it shows you how to generate individual reports then combine them together, and then render them as HTML. These can then be viewed in the browser.
This command can be used to install what's needed npm install --save-dev mochawesome mochawesome-merge mochawesome-report-generator
and then add the Reporter configuration to the cypress.json:
{
"reporter": "mochawesome",
"reporterOptions": {
"reportDir": "cypress/results",
"overwrite": false,
"html": false,
"json": true
}
}
Keep in mind that it may not give you the level of detail that is contained in the Cypress Dashboard in the browser, for example, what was yielded from a request.
Cypress has a lot of possible command with a lot of possible config too.
Read this.
And if you use npm just run like this :
npm run cypress:open
and in your package.json :
"scripts": {
"cypress:open": "cypress open"
}

FETCH converted XHR request is not captured in CYPRESS RUN command

"npx run command" is not catching FETCH calls but same FETCH calls get captured in "npx cypress open" command and my cypress version is 3.4.1 and I use unfetch module in window:before:load cypress EVENT to capture FETCH converted XHR request, if any enter code herebody faced this issue , please provide me the solution.
I haven't used unfetch, I suspect it's due to that. This is what I am using and it works with both npx cypress open and npx cypress run for us. It comes from this issue.
// In cypress/support/index.js
Cypress.on("window:before:load", win => {
win.fetch = null;
});

Cypress how to run before each spec file

I want to reset my database before each "spec" start. NOT before each test
I see that i can add code in support/index.js
before(function () {
cy.exec('npm run db:reset')
// This run only once before ALL the spec
})
beforeEach(function () {
cy.log('RUN BEFORE EACH TEST IN EACH SPEC')
})
I want to run before each spec file. I am using GUI and clicking "Run all specs";
I have multiple spec file and in each spec have multiple test.
UPDATE : My test in GUI failed because database wasn't getting reset. I tried running test in CLI and all tests pass. So does that mean in CLI it does run before each spec ? Is it issue only in GUI ?

Resources