【发布时间】:2019-01-22 03:18:19
【问题描述】:
我想让 cypress 找到我的 iframe。我发现了一个 GitHub 问题,它讨论了关于 iframe 的 cypress 限制的变通方法,this 是我采用的解决方案。
Cypress.Commands.add('iframe', { prevSubject: 'element' }, $iframe => {
return new Cypress.Promise(resolve => {
$iframe.on('load', () => {
resolve($iframe.contents().find('body'));
});
});
});
这里是我实际使用这个命令的地方。
context("Basic simple test", () => {
it("can visit our app", () => {
cy.visit("http://localhost:3000");
cy.get('#haha').iframe();
})
})
这是我的 iframe 代码。
<StyledFrame
sandbox="allow-forms allow-scripts allow-same-origin allow-modals allow-popups allow-presentation"
title="sandbox"
id="hahah"
srcDoc={this.state.isLoading ? loader : this.state.bundle}
/>
但是,Cypress 告诉我它找不到 ID 为 haha 的元素。
【问题讨论】:
标签: javascript reactjs iframe cypress