我想存储一个值,然后执行一个操作并断言该值没有改变。我确实有一个有效的代码,但如果有更优雅的解决方案,我希望得到输入。
基本思想是:
describe('Store and compare a value', () => {
it('store and compare', () => {
cy.login()
cy.visit('url2')
cy.get('.total-count-results').invoke('text')
.then((text) => {
const counts = text
cy.get('.medium.col100 > .filterwrapper > input').type('Test Dummy',{force: true})
cy.get('.medium.col100 > .filterwrapper > input').type('{enter}')
cy.get('.total-count-results').invoke('text')
.then((text) => {
const new_counts = text
expect(new_counts).to.eq(counts)
})
})
})
})
Run Code Online (Sandbox Code Playgroud)
这是我能想到的最好的处理异步性的方法。
我想扩展这个问题,因为我有类似的问题:
我想要,cy.get('#lead_name').type('foo')但在加载表单时它被不透明度 0.9 的元素覆盖:
<div class="blockUI blockOverlay" style="z-index: 1000; border: none; margin: 0px; padding: 0px; width: 665px; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.9; cursor: wait; position: absolute;"></div>
Run Code Online (Sandbox Code Playgroud)
当我开始断言时
cy.get('#lead_name').should('be.visible)
Run Code Online (Sandbox Code Playgroud)
它通过了断言(也许是因为不透明度?),但是当我尝试在字段中输入时,我收到了该元素被覆盖的错误消息。
当我尝试断言覆盖层不再存在并添加
cy.get('.blockUI blockOverlay').should('not.exist')
Run Code Online (Sandbox Code Playgroud)
即使该元素确实存在,Cypress 也会通过断言并覆盖其他元素并cy.get('#lead_name').type('foo')失败。
有什么办法可以解决这个问题吗
//This does not work it's just a sample to explain what I want to do
//test if the element I want to get is not covered
cy.get('#lead_name').should('not.be.covered')
//or test if the element …Run Code Online (Sandbox Code Playgroud)