`import Warehouse from "../../../pagesObjects/cust...
# best-practices
r
Copy code
import Warehouse from "../../../pagesObjects/customerDataPlatform/warehouse.cy";

const warehouse = new Warehouse();

describe("Regression Tests CDP GDPR", () => {
  var completeDate = 0
  var constants = ""

  beforeEach(() => {
    cy.viewport(Cypress.env("viewportWidth"), Cypress.env("viewportHeight"));
    cy.login()
    cy.getPlatformLanguageConstants().then(value => constants = value);
  })


  it('CDP-4071 GDPR - Consent Version. Edit Terms and Conditions', () => {
    cy.getCodeTime().then(value => completeDate = value);
    cy.visitUrl(Cypress.env('urls').cdp.complianceVersions.link)
    cy.then(() => {
      cy.textArea_TypeAndSave(warehouse.editableTermsConditions(),completeDate,warehouse.btnSaveTermsConditions())
    });
    cy.clickModalConfirmation()
    cy.wait(1000)
    cy.checkModal(constants.cdp.gdprModalTermsConditionsTitle,constants.cdp.gdprModalTermsConditions)
    cy.visitUrl(Cypress.env('urls').cdp.complianceVersions.link)
    cy.then(() => {
    cy.checkText(warehouse.editableTermsConditions(),completeDate)
    })
  });

  it('CDP-4072 GDPR - Consent Version. Edit Personalized communications', () => {
    cy.getCodeTime().then(value => completeDate = value);
    cy.visitUrl(Cypress.env('urls').cdp.complianceVersions.link)
    cy.then(() => {
      cy.textArea_TypeAndSave(warehouse.editablePersonalizedCommunications(),completeDate,warehouse.btnSaveConsent())
    });
    cy.clickModalConfirmation()
    cy.wait(1000)
    cy.checkModal(constants.cdp.gdprModalTermsConditionsTitle,constants.cdp.gdprModalTermsConditions)
    cy.visitUrl(Cypress.env('urls').cdp.complianceVersions.link)
    cy.checkText(warehouse.editablePersonalizedCommunications(),completeDate)
  });

});
f
You shouldn't need to call
Cypress.env('urls')
in your
cy.visitUrl()
if you've set your baseUrl correctly (Also, why did you need to make a method for this? Looks like
cy.visit()
should be enough)
You don't need the
cy.then()
after your visitUrl commands. Cypress should handle the chaining under the hood
I personally don't like making custom methods for assertions (eg
checkText
and
checkModal
). I think it's easier for others to understand if you can see the assertions in the spec itself. But that's personal preference
r
I use Cypress.env('urls') because I have many tests with many urls, in this case this test is the same but in others it is not
if I don't use "then" the complete Date variable gives me null
in this case "0" because I have it declared above
f
> if I don't use "then" the complete Date variable gives me null Your chaining is off if you're having to use an empty
cy.then()
. You can place all of your commands in the first
then()
Copy code
cy.getCodeTime().then(value => { completeDate = value;
cy.visitUrl(Cypress.env('urls').cdp.complianceVersions.link);
...

})
r
It is a good practice, I will implement it, thanks
f
> I use Cypress.env('urls') because I have many tests with many urls, in this case this test is the same but in others it is not You can also set your baseUrl in the spec itself. I think it's
Cypress.config('baseUrl', url)
. but docs can confirm that
g
read about aliases. You can avoid all
.then
callbacks and local closure variables if you aliases set in
beforeEach
. Can I write a blog post using your posted code?
r
Yes, that's how I can learn.
send the link later
l
personally, I'd abstract all of the common code into a reusable function.
and I would also try to remve the cy.wait(1000) if possible