-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Current behavior:
We are currently implementing email confirmation test.
We currently download the email file -> parse out the html content of it -> save it locally in fixture/.
In order for cypress.visit('path-to-local-file.html')
to load up the downloaded content, we need to change the baseUrl
that was set in cypress.json
to be empty.
Cypress.config('baseUrl', '
');doesn't switch
baseUrland keeps appending the path to local file to the original
baseUrl`, eg: https://demo.test.com/fixtures/email-content.html
Also tried to follow https://docs.cypress.io/api/plugins/configuration-api.html#Usage but it also fails to switch out baseUrl
.
I couldn't find any workaround.
One method I tried was NOT setting baseUrl
in cypress.json
and specify the main domain everywhere except for visiting local html file. But this also fails because we have a before
hook that generates unique string for email and if you change the domain on cy.visit()
, the before
hook runs and the email file name won't match.
Desired behavior:
Cypress.config('baseUrl', ' ');
should switch baseUrl to none.
Steps to reproduce: (app code and test code)
Posting it as pseudo-code. Will fill in more details if needed.
cypress.json
{
"baseUrl": "https://demo.testing.com",
"userAgent": "testing"
}
test spec file
var emailFileName;
before(function () {
cy.log('ran');
cy.task('generateGuid').then(function ($guid) {
guid = $guid;
emailFileName = 'tester' + guid + '@test.com';
cy.log(emailText);
});
});
it('Register user', function () {
cy.visit('/login'); //-> yields https://demo.testing.com/login
// Fill up registration info then click 'Register' button
cy.wait(5000);
cy.get(sendConfirmEmailButton).click({ force: true });
// wait for 30s to verify email body
cy.wait(20000);
cy.downloadEmailHtml(emailFileName, 'confirmAccount');
});
it('Visit email user', function () {
// Change baseurl
Cypress.config('baseUrl', ' ');
// TODO visit/load the confirm account html file
cy.visit(`cypress/fixtures/confirmAccount_${emailFileName}@test.com.html`);
cy.get('#templateBody')
.contains('Click the button below to confirm your account');
});
Versions
Cypress: 3.1.3
OS: Mac- mojave