refined-shampoo-94690
08/02/2022, 2:09 PMcy.origin
. My use case would be to iterate through several URLs in a JSON, visit each site and do the tests.
const clients = {
"urls": [
{
"siteurl": "http://google.com,
"subpage": "/"
},
{
"siteurl": "http://youtube.com,
"subpage": "/"
}
]
};
// cy.visit('/')
it('tests', () => {
clients.urls.forEach( client => {
cy.origin(client.siteurl, () => {
cy.visit(client.subpage);
cy.get("body");
})
});
});
According to the Docs, you cannot directly pass variables into the cy.origin
but is there any way of passing a url to it?red-toddler-79937
08/02/2022, 7:41 PMcy.get('@toggle').get('input').should('have.attr', 'aria-checked').and('match', /false/);
but when I type "/false" it actually passes.
But when I type random stuff like "sdifgjhsdifhjsdfse" it fails as expected. Why is that?red-toddler-79937
08/02/2022, 7:42 PMcy.get('@toggle').get('input').should('have.attr', 'aria-checked', 'true')
, that works. But when I type 'false' it also passes. And then when I type random data it fails as expected.gray-kilobyte-89541
08/02/2022, 7:59 PMred-toddler-79937
08/02/2022, 8:00 PMred-toddler-79937
08/02/2022, 8:00 PMbrainy-librarian-80110
08/03/2022, 3:48 AMbrainy-librarian-80110
08/03/2022, 3:48 AMbrainy-librarian-80110
08/03/2022, 3:49 AMbrainy-librarian-80110
08/03/2022, 3:50 AMstale-optician-85950
08/03/2022, 7:26 AMdescribe('helping', () => {
const clients = {
urls: [
{
siteurl: 'https://www.acme.com',
subpage: '/updates/',
},
{
siteurl: 'https://www.google.co.uk',
subpage: '/search?q=cypress+io',
},
],
};
it('tests', () => {
clients.urls.forEach(client => {
cy.origin(client.siteurl, { args: { client } }, ({ client }) => {
cy.visit(client.subpage);
});
})
});
});
refined-shampoo-94690
08/03/2022, 7:41 AMbillions-lizard-8925
08/03/2022, 10:09 AMflaky-airport-12178
08/03/2022, 10:16 AMflaky-airport-12178
08/03/2022, 10:17 AMwide-hospital-71307
08/03/2022, 11:07 AMgray-kilobyte-89541
08/03/2022, 1:31 PMwindow.getComputedStyles
to get all of them. For more, search https://glebbahmutov.com/cypress-examplesflaky-airport-12178
08/03/2022, 3:47 PMglamorous-country-57678
08/03/2022, 7:07 PMdescribe('visit and interact with home page', () => {
beforeEach(() => {
cy.intercept('GET', 'http://localhost:3001/api/post?*').as('getPosts')
})
it('visit homepage', () => {
cy.visit('/')
})
})
And here is what the CommandLog displays:chilly-magician-64042
08/03/2022, 7:24 PMchilly-magician-64042
08/03/2022, 7:26 PMglamorous-country-57678
08/03/2022, 7:45 PMdescribe('visit and interact with home page', () => {
beforeEach(() => {
cy.intercept('GET', 'http://localhost:3001/api/*').as('getApi')
})
it('visit and interact with home page', () => {
cy.visit('/')
cy.wait('@getApi')
})
})
chilly-magician-64042
08/03/2022, 7:56 PMchilly-magician-64042
08/03/2022, 7:56 PMgray-kilobyte-89541
08/03/2022, 7:58 PMglamorous-country-57678
08/03/2022, 8:14 PMchilly-magician-64042
08/03/2022, 8:16 PMglamorous-country-57678
08/03/2022, 8:18 PMfierce-lion-2381
08/04/2022, 10:51 AMglamorous-country-57678
08/04/2022, 7:55 PMcy.wait()
command I was using in an earlier implementation:
`describe('visit and interact with home page', () => {
const apiURL = ${Cypress.env('apiUrl')}
it('visit and interact with home page', () => {
cy.intercept('GET', ${apiURL}/*
, {
statusCode: 200,
body: {
data: {
id: '1',
},
},
}).as('getApi')
cy.intercept('POST', http://localhost:8545*
, {
statusCode: 200,
body: {
data: {
id: '1',
},
},
}).as('post8545')
// cy.wait('@getApi')
cy.visit('/')
})
})`
Still refactoring this, but the test is passing and the routes display that they are stubbed like they should.