admin管理员组文章数量:1431037
Cypress sees my returned strings as objects, so I'm trying to use cy.wrap() to resolve the value as string.
I have a cypress custom mand, like so:
Cypress.Commands.add('emailAddress', () => {
var emailAddress = 'testEmail-' + Math.random().toString(36).substr(2, 16) + '@mail';
return cy.wrap(emailAddress);
})
That I need the return value as a sting in my test:
beforeEach(() => {
var user = cy.emailAddress().then(value => cy.log(value)); // [email protected]
logonView.login(user) // object{5}
})
How do I use the string value for my login and elsewhere in my test?
Something like: logonView.login(user.value)
... but this doesn't work?
Cypress sees my returned strings as objects, so I'm trying to use cy.wrap() to resolve the value as string.
I have a cypress custom mand, like so:
Cypress.Commands.add('emailAddress', () => {
var emailAddress = 'testEmail-' + Math.random().toString(36).substr(2, 16) + '@mail.';
return cy.wrap(emailAddress);
})
That I need the return value as a sting in my test:
beforeEach(() => {
var user = cy.emailAddress().then(value => cy.log(value)); // [email protected]
logonView.login(user) // object{5}
})
How do I use the string value for my login and elsewhere in my test?
Something like: logonView.login(user.value)
... but this doesn't work?
1 Answer
Reset to default 3In Cypress, you cannot return value like this
var user = cy.emailAddress().then(value => cy.log(value));
Instead, you get the return value in the then .then
callback:
cy.emailAddress().then((value) => {
logonView.login(user)
});
So, for you test, you can instead do the following:
describe("My test", () => {
beforeEach(() => {
cy.emailAddress().then((value) => {
logonView.login(user)
});
});
it("should have logged into the App", () => {
// Write your test here
});
});
Or use a variable in the before each block, and access it later in the test:
describe("element-one", () => {
let user;
beforeEach(() => {
cy.emailAddress().then((value) => (user = value));
});
it("it should have user value", () => {
expect(user).to.includes("testEmail");
});
});
本文标签: javascriptHow to extract and use a string value returned from cywrap()Stack Overflow
版权声明:本文标题:javascript - How to extract and use a string value returned from cy.wrap() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745527043a2661883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论