How visit multiple domains of different origin in a single test - Implemented
Thimmaraju G
Automation Trainer |Clients ??| Playwright | Cypress.io |SerenityJS | Selenium| Protractor |API | Performance | Conduct free Seminars and Webinars on Manual and Automation Testing | Stay tuned
Working with Links and cy.origin() Implementaion
cy.origin()
In normal use, a single Cypress test may only run commands in a single origin, a limitation determined by standard web security features of the browser. The?cy.origin()?command allows your tests to bypass this limitation.
describe('Automation - Working With Links', function ()
? it('Cypress Test Case - Understanding Links and how to work with Links', function () {
? ?
cy.visit('https://www.wikipedia.org/');
? ? cy.get('a').contains('Commons').click();
? ? cy.origin('https://commons.wikimedia.org', () => {
//Verify Url after navigating diferent origin
? ? ? cy.url().should("eq", "https://commons.wikimedia.org/wiki/Main_Page")
? ? ? cy.get('.mainpage-welcome-sitename').should('contain.text', 'Wikimedia Commons');
? ? ?
//Verify links count in a Page
cy.get('a').should('have.length', 684)
? ? ? cy.get('a').its('length').then((elelength) => {
? ? ? ? var lengthcount = elelength
? ? ? ? cy.log(lengthcount)
? ? ? ? expect(lengthcount).to.equal(684)
? ? ? })
? ? ? cy.get('.vector-menu-content-list').eq(5).find('a').its('length').then((elelength) => {
? ? ? ? cy.log(elelength)
? ? ? ? expect(elelength).to.equal(5)
? ? ? })
//Get the Link Text
? ? ? cy.get('.vector-menu-content-list').eq(5).find('a').then((txt) => {
? ? ? ? var x = txt.text()
? ? ? ? cy.log(x)
? ? ? })
? ? })
? })
})
This will be very usefull, if your login test involves multiple Origins.
Ex: SSO Login..etc.
Let me know in comments, If you need any other specific topic to be covered in future.
If any one want ot attend Cypress Automation tool full course live Training.
Connect with me on : https://wa.me/917207774066
Website: www.dbsqatechnologies.com
Cheers !
~Raju