famous-restaurant-30435
09/23/2022, 3:05 PMmysterious-belgium-25713
09/23/2022, 3:54 PMfamous-restaurant-30435
09/23/2022, 3:55 PMfamous-restaurant-30435
09/23/2022, 4:04 PMclever-table-91477
09/23/2022, 5:05 PMclever-table-91477
09/23/2022, 5:16 PMrequire('cypress-xpath');
in setupNodeEvents(on, config) {}
block as well as in e2e.js
, not sure where exactly it should go. Then when I run the test with cy.xpath(''), it fails with this error cy.xpath is not a function
. Maybe someone can help me, it must be something obvious that I don't seemysterious-belgium-25713
09/23/2022, 5:16 PMjs
Cypress.on('fail', (error, runnable) => {
debugger
// we now have access to the err instance
// and the mocha runnable this failed on
throw error // throw error to have test still fail
})
abundant-dentist-45237
09/23/2022, 5:30 PMbrave-river-4142
09/23/2022, 5:49 PMmysterious-belgium-25713
09/23/2022, 6:42 PMjs
require('cypress-xpath');
Is in the file cypress/support/e2e.jsfamous-restaurant-30435
09/23/2022, 6:50 PMmysterious-belgium-25713
09/23/2022, 7:40 PMjs
import './commands'
var isFailed = false;
var failedTitle;
Cypress.on('fail', (error, runnable) => {
failedTitle = runnable.fullTitle();
isFailed = true
throw error
})
afterEach(function() {
if(isFailed){
cy.screenshot(`The failed test is ${failedTitle}`,{capture: "fullPage"})
isFailed = false
}
})
This gives you 2 screenshots one the default when it failed.
And the second a screenshot that makes a fullpage with the failed test title.
Hope this will help youfamous-restaurant-30435
09/23/2022, 7:45 PMmysterious-belgium-25713
09/23/2022, 7:45 PMgray-kilobyte-89541
09/23/2022, 8:55 PMlimited-barista-33480
09/24/2022, 12:36 AMstrong-energy-6158
09/24/2022, 6:32 AMstale-optician-85950
09/24/2022, 8:12 AMadventurous-rose-66394
09/24/2022, 8:43 PMstrong-energy-6158
09/25/2022, 6:40 AMmicroscopic-advantage-2187
09/25/2022, 7:08 AMbefore
in support files since I only want to run them once and before the other fileslittle-umbrella-9653
09/25/2022, 7:45 AMdazzling-pillow-26039
09/25/2022, 7:53 AMmicroscopic-advantage-2187
09/25/2022, 8:05 AMfancy-mechanic-10638
09/25/2022, 8:10 AMcy.intercept('post', '/path', {fixture: 'someFile'})
is there a way to then modify the file beyond that? It's a big JSON object, and for the 4 tests I want each one to slightly change a few values.mysterious-belgium-25713
09/25/2022, 1:22 PMfamous-restaurant-30435
09/25/2022, 2:01 PMjavascript
cy.fixture("calculator/monthlyRepayment.json").then((json) => {
cy.intercept("POST", "**/full", (req) => {
//you can use the request here if you need data that is included in the request
let name = req.body.username;
json.username = name;
req.reply(json);
});
});
You can see more documentation here: https://docs.cypress.io/api/commands/intercept#Controlling-the-outbound-request-with-req-continuebulky-park-99069
09/25/2022, 6:24 PMbulky-park-99069
09/25/2022, 6:26 PMstale-optician-85950
09/25/2022, 6:39 PMcy.session()
is well documented on that page, so I'm not sure what extra you're expecting in an example repo.
Anyhow you can also use this plugin from @gray-kilobyte-89541 https://github.com/bahmutov/cypress-v10-preserve-cookie