gpt4 book ai didi

cypress - 在 cypressIO 中使用别名时出现错误消息

转载 作者:行者123 更新时间:2023-12-02 20:10:27 24 4
gpt4 key购买 nike

使用时收到以下错误消息:“TypeError: 无法读取未定义的属性“文本””

我已经按照文档中的方式完成了操作:https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases

有人能看出我做错了什么吗?

beforeEach(() => {
cy.visit('http://localhost:4200/');
loginPage.login();
timeFilter.button.click();
cy.get('#title').invoke('text').as('text');
});

it('should show text', () => {
console.log(this.text);
});

最佳答案

阅读 cypress 文档,我遇到的问题是使用箭头函数,并且我没有使用 .then() 访问闭包中的别名。我一这样做,它就起作用了:

cy.get('#title').invoke('text').as('text');

it('should show text', () => {
cy.get('#main').then(function () {
console.log(this.text);
});
});

或者在 it() 回调中使用 function() 而不是 () =>

cy.get('#title').invoke('text').as('text');

it('should show text', function() {
console.log(this.text);
});

关于cypress - 在 cypressIO 中使用别名时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53726090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com