【发布时间】:2021-09-10 12:33:59
【问题描述】:
我是赛普拉斯的新手,我正在尝试使用现有网页实现一些简单的测试。我对结果有点困惑,因为我调用了两次 invoke():第一次检查初始值 (0%),第二次设置新值并检查更改,但它没有t 工作,它告诉我它找不到我正在搜索的属性。代码如下:
describe('My first test', function(){
beforeEach(() => {
cy.visit("https://www.wikiwand.com/en/IPv4")
})
it('test1', function() {
const opt = cy.get("#main_menu > li").eq(3).click()
const sty = opt.get(".noUi-origin").first()
sty.invoke("attr", "style").should("include", "left: 0%;")
sty.invoke("attr", "style", "left: 100%;").should("have.attr", "style", "left: 100%;")
})
})
我只需点击菜单栏上的个性化按钮,我想更改 serif 或 sans 的值。两个invoke()的顺序有问题?错误是:
*Timed out retrying after 4000ms: cy.invoke() errored because the property: attr does not exist on your subject.
cy.invoke() waited for the specified property attr to exist, but it never did.
If you do not expect the property attr to exist, then add an assertion such as:
cy.wrap({ foo: 'bar' }).its('quux').should('not.exist')*
开
sty.invoke("attr", "style", "left: 100%;").should("have.attr", "style", "left: 100%;")
有人知道吗?
【问题讨论】:
-
所以你的元素在 style 属性下同时提到了
left: 0%;和left: 100%;?如果您可以共享元素的整个 html,那就太好了。 -
@AlapanDas 它是维基百科wikiwand.com/en/IPv4 上的网页,您可以通过inspect 看到那里的html。左边是在html下的style属性,是的。
-
是的,我后来知道了。我已经回答了你的问题,你可以检查一下。
标签: testing automated-tests cypress invoke