A page object is a class, which can have properties of it's own. You can make header and footer custid's as properties, and compare them as suits your test flow.
Option 1 - Save the values as class variables
class HomePage{
constructor() {
this.headerCustomerid = null;
this.footerCustomerid = null;
}
getcustomerIdOnHeaderSection() {
cy.get(custId locator).then($id => {
this.headerCustomerid = $id.text().trim();
})
}
getcustomerIdOnFooterSection() {
cy.get(custId locator).then($id => {
this.footerCustomerid = $id.text().trim();
})
}
}
// test
const homePage = new HomePage();
homePage.getcustomerIdOnHeaderSection()
homePage.getcustomerIdOnFooterSection()
cy.then(() => {
expect(homePage.headerCustomerid).to.eq(homePage.footerCustomerid)
})
Option 2 - Create a new method to compare
class HomePage{
constructor() {
this.headerCustomerid = null;
this.footerCustomerid = null;
}
getcustomerIdOnHeaderSection() {
cy.get(custId locator).then($id => {
this.headerCustomerid = $id.text().trim();
})
}
getcustomerIdOnFooterSection() {
cy.get(custId locator).then($id => {
this.footerCustomerid = $id.text().trim();
})
}
compareHeaderFooterCustId() {
this.getcustomerIdOnHeaderSection()
this.getcustomerIdOnFooterSection()
expect(this.headerCustomerid).to.eq(this.footerCustomerid)
}
}
// test
const homePage = new HomePage();
homePage.compareHeaderFooterCustId()
Option 3 - Compare in constructor
class HomePage{
constructor() {
getcustomerIdOnHeaderSection()
getcustomerIdOnFooterSection()
}
getcustomerIdOnHeaderSection() {
cy.get(custId locator).then($id => {
this.headerCustomerid = $id.text().trim();
})
}
getcustomerIdOnFooterSection() {
cy.get(custId locator).then($id => {
this.footerCustomerid = $id.text().trim();
})
}
}
// test
const homePage = new HomePage();
cy.then(() => {
expect(homePage.headerCustomerid).to.eq(homePage.footerCustomerid)
})