I have the following fixture file call myfile
[
{
"instance": "feature",
"baseUrl": "http://1.1.1.1",
},
{
"instance": "non-feature",
"baseUrl": "http://1.1.1.1",
}
]
and I have the following command to get the baseUrl
Cypress.Commands.add('getBaseUrl',() => {
let baseUrl;
cy.fixture('myfile').then(function (defaultdata) {
this.defaultdata = defaultdata;
var index = this.defaultdata.findIndex(obj => obj.instance ==
Cypress.env('instance'));
baseUrl =this.defaultdata[index].baseUrl;
return baseUrl;
})
})
But when i try to use it I get: log Object{5} instead of the value of baseUrl
describe('Tests', () => {
it('is redirected on visit to /dashboard when not authenticated', function () {
cy.log(cy.getBaseUrl());
})
})
Probably some syncronic logic but i can't manage to make it. If i wrap baseUrl in the command i can see the value but no luck passing it trough.
question from:
https://stackoverflow.com/questions/66067615/with-cypress-get-fixture-data-using-a-command 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…