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();
})
})
<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
.