我正在使用NightwatchJS来测试带有嵌入式iFrame的页面。测试将打开页面,等待iframe出现。到目前为止,所有测试步骤都有效,但是iFrame的内容告诉我,浏览器无法渲染嵌入式iframe。
夜间监视配置( nightwatch.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...
答案 0 :(得分:1)
您需要切换到框架以检查其内容,例如
.frame(‘botframe’)
检查完框架并想返回到主要的html内容后:
.frame(0)
// or
.frame(null)
//or
.frame()
将使您返回到原始帧。