NIghtwatch.js:嵌入式iframe无法加载



我正在使用NightwatchJS来测试带有嵌入式iFrame的页面。测试将打开页面,等待 iframe 出现。到目前为止,所有测试步骤都有效,但 iFrame 的内容告诉我浏览器无法呈现嵌入式 iframe。

Nightwatch Confignightwatch.conf.js

"chrome" : {
    "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "nativeElements": true
    }
},

测试代码

.waitForElementVisible('//iframe[@id = "botframe"]')
.element('xpath', '//iframe[@id = "botframe"]', (r) => console.log(r))
.assert.containsText('//iframe[@id = "botframe"]', 'Hello')

输出

✔ Element <//iframe[@id = "botframe"]> was visible after 61 milliseconds.
{ sessionId: '76685e966809e760c639d589ba318693',
    status: 0,
    value: { ELEMENT: '0.5426473824985356-1' } }
✖ Testing if element <//iframe[@id = "botframe"]> contains text: "Hallo" in 1000 ms. - expected "Hallo" but got: "<br><p>Da Ihr Browser keine eingebetteten Frames anzeigen kann...

您需要切换到框架才能检查其内容,例如

.frame(‘botframe’)

检查完框架并希望返回到主要 html 内容后:

.frame(0)
// or
.frame(null)
//or
.frame()

将使您返回到原始帧。