我已经尝试了每种方法,但是我无法让TestCafe等待open_file.seek(0)
属性从元素中删除。
这显然会阻止所有进一步的测试,因为在继续进行此流程之前,我需要单击按钮。
open_file.truncate(0)
无论我提前定义了disabled
,还是从定义中添加或删除fixture('create').page('locahost:3000');
test('one', async => {
const myIframe = Selector('#myIframe');
await t
.typeText('#input', 'words')
.click('#update')
.expect(myIframe.exists).ok('', { timeout: 10000 })
.switchToIframe(myIframe)
const activeStartButton = await Selector('#start').withAttribute('disabled');
await t
.expect(activeStartButton).notOk('', { timeout: 60000, allowUnawaitedPromise: true });
});
,都可以将选择器直接放置在activeStartButton
中,而不必等待,将{{1 }} expect(activeStartButton).notOk`
该错误因我的方法而异,但是对于此代码:
await
答案 0 :(得分:3)
您的代码应如下所示:
const selector = Selector('#start')
.with({visibilityCheck: true});
await t
.expect(selector.exists).ok({timeout: 10000}) // ensure the button is visible on the screen
.hover(selector) // access to the button via the mouse
.expect(selector.hasAttribute("disabled")).notOk({timeout: 10000}) // ensure the field is enabled
.click(selector);
也许您还应该看看say goodbye to flakyness
答案 1 :(得分:1)
此代码:
const mySelector = Selector('any css selector');
await t
.expect(mySelector).notOk()
将始终抛出错误,因为mySelector
的真实性始终为真。因此,上面的代码类似于以下代码:
assert(true).toBe(false)
。
mySelector
上方是一个承诺对象,承诺的真实性始终是真实的。
现在,如果您写:
const mySelector = await Selector('any css selector');
await t
.expect(mySelector).notOk();
mySelector
是一个NodeSnaphsot
对象,它是某种文字对象,上面有很多属性,例如:
{
textContent,
attributes,
id,
clientHeight,
...
}
文字对象的真实性始终是真实的,因此以上
expect
仍会引发错误。
实际上,如果改为使用测试代码,则该问题可能已被完全掩盖:
const mySelector = await Selector('any css selector');
await t
.expect(mySelector).ok();
即使mySelector
不代表DOM中任何现有元素,上述测试代码也始终会通过。
在期望里面,您只应声明使用ok()或notOk()时返回布尔值的Selector的属性或方法。
可能的布尔属性是:
mySelector.hasChildElements
mySelector.hasChildNodes
mySelector.checked
mySelector.focused
mySelector.selected
mySelector.visible
mySelector.exists
可能的方法是:
mySelector.hasClass('className')
mySelector.hasAttribute('attributeName')
.withAttribute('attributeName')只是一个返回Selector对象(即Promise)的过滤器方法,该结果的真实性始终为真。
所以当你写的时候:
const mySelector = Selector('any css selector').withAttribute('attributeName');
或多或少像编写此伪代码:
const mySelector = Selector('any css selector') // returns a collection of Selectors
.toArray() // convert it to an array
.filter((selector) => selector.hasAttribute('attributeName'))
.toPromise() // convert back to a promise object