Jquery 使用cypress访问iframe中的元素时出错
我是cypress/javascript/jquery的新手,非常感谢您的帮助!我正在尝试一种使用cypress访问iframe中的元素的方法,这里建议使用:。我在.its命令中遇到了一个cypress错误,随后在getInDocument自定义命令中出现了错误 这是测试中html代码的摘录:Jquery 使用cypress访问iframe中的元素时出错,jquery,iframe,cypress,Jquery,Iframe,Cypress,我是cypress/javascript/jquery的新手,非常感谢您的帮助!我正在尝试一种使用cypress访问iframe中的元素的方法,这里建议使用:。我在.its命令中遇到了一个cypress错误,随后在getInDocument自定义命令中出现了错误 这是测试中html代码的摘录: <iframe id="iframeDiag" style="width:100%;height:100%;border:none;padding:0px;z-index:1001;" src="h
<iframe id="iframeDiag" style="width:100%;height:100%;border:none;padding:0px;z-index:1001;" src="https://<snip>">
#document
<snip>
<button _ngcontent-c11="" class="btn btn-md pointer btn-primary" type="button">Next</button>
<snip>
</iframe>
.get是成功的。.its存在以下错误:
cypress_runner.js:126133 Uncaught TypeError: Cannot convert object to primitive value
at baseToString (cypress_runner.js:126133)
at toString (cypress_runner.js:134455)
at Function.trim (cypress_runner.js:136853)
at cypress_runner.js:157797
at cypress_runner.js:126802
at baseForOwn (cypress_runner.js:124887)
at cypress_runner.js:126771
at Function.forEach (cypress_runner.js:131239)
at Object._logValues (cypress_runner.js:157794)
at Object.logFormatted (cypress_runner.js:157783)
at EventEmitter. (cypress_runner.js:157457)
at EventEmitter.emit (cypress_runner.js:121451)
at EventEmitter. (cypress_runner.js:101916)
at EventEmitter.emit (cypress_runner.js:121451)
at Object.emit (cypress_runner.js:101958)
at Object. (cypress_runner.js:100786)
我应该关注打字错误吗?从表面上看,这似乎是一个cypress错误,但我意识到这可能是正在测试的应用程序代码
或者可以忽略这一点,转而关注.getInDocument命令中的选择器
任何帮助都将不胜感激!谢谢 事实上,我认为有效的东西没有用。为了防止有人发现问题,我们会继续尝试。我不能相信这种方法的创始人,因为我不记得是从哪里得到的(从兔子洞里钻出来的!):
我确实收到了可访问性冲突,因此axe正在工作,但iframe中没有任何内容(iframe中确实存在冲突)。事实上,我认为有效的东西没有。为了防止有人发现问题,我们会继续尝试。我不能相信这种方法的创始人,因为我不记得是从哪里得到的(从兔子洞里钻出来的!): 我确实收到了可访问性冲突,因此axe正在工作,但iframe中没有任何内容(iframe中确实存在冲突)
cypress_runner.js:126133 Uncaught TypeError: Cannot convert object to primitive value
at baseToString (cypress_runner.js:126133)
at toString (cypress_runner.js:134455)
at Function.trim (cypress_runner.js:136853)
at cypress_runner.js:157797
at cypress_runner.js:126802
at baseForOwn (cypress_runner.js:124887)
at cypress_runner.js:126771
at Function.forEach (cypress_runner.js:131239)
at Object._logValues (cypress_runner.js:157794)
at Object.logFormatted (cypress_runner.js:157783)
at EventEmitter. (cypress_runner.js:157457)
at EventEmitter.emit (cypress_runner.js:121451)
at EventEmitter. (cypress_runner.js:101916)
at EventEmitter.emit (cypress_runner.js:121451)
at Object.emit (cypress_runner.js:101958)
at Object. (cypress_runner.js:100786)
it ('Checking Accessibility', () => {
// inject axe into iframes
cy.window()
.then((win) => {
var iframe = win.document.getElementsByTagName('iframe')[0];
console.log('Inject axe into iframe '+iframe.id);
var script = iframe.contentWindow.document.createElement("script");
script.src = '../js/axe.min.js';
script.type = 'text/javascript';
iframe.contentWindow.document.body.appendChild(script);
//wait(6000);
const axe = require('axe-core');
return win.axe.run(iframe, { iframes: true} );
})
.then(({ violations }) => {
if (violations.length) {
cy.wrap(violations, { log: false }).each(v => {
Cypress.log({
name: 'a11y error!',
consoleProps: () => v,
message: `${v.id} on ${v.nodes.length} Node${
v.nodes.length === 1 ? '' : 's'
}`
})
})
}
return cy.wrap(violations, { log: false })
})
.then(violations => {
assert.equal(
violations.length,
0,
`${violations.length} accessibility violation${
violations.length === 1 ? '' : 's'
} ${violations.length === 1 ? 'was' : 'were'} detected`
)
})
});