[英]How to open new browser window in intern js?
我正在自动化应用程序的UI测试。 在某些情况下,我希望我的测试脚本关闭当前浏览器并通过打开新的浏览器运行下一个测试。 问题是我无法弄清楚如何在实习生中打开新的浏览器窗口。 remote.get(URL)
不能执行我想在这里执行的操作。 有人可以帮忙吗?
我已经更新了我的问题,以包括代码。 我的问题很简单。 如何从测试内部使用实习生打开新的浏览器窗口? 。 尽管如果您想查看代码,请发表评论,我会写下来。 谢谢。
// in tests/functional/index.js
define([
'intern!object',
'intern/chai!assert',
'Automation/ConfigFiles/dataurl',
'Automation/pages/login/loginpage',
'intern/dojo/node!fs',
'intern/dojo/node!leadfoot/helpers/pollUntil'
], function (registerSuite, assert, dataurl, LoginPage, fs, pollUntil) {
registerSuite(function () {
var loginPage;
var values;
return {
setup: function () {
var data = fs.readFileSync(loginpage, 'utf8');
json = JSON.parse(data);
values = json.values;
loginPage = new LoginPage(this.remote, json.locator);
return this.remote
.get(require.toUrl(json.locator.URL)).setFindTimeout(60000000000).sleep(5000)
},
beforeEach:function() {
// here i want to open new window
},
'valid loginname lands to password page':function () {
loginPage.submitLoginName(values.unamevalue);
loginPage.isPasswordPageDisplayed().then(function(isPasswordPageDisplayed) {
assert.true(isPasswordPageDisplayed, 'password page is not displayed, Invalid Login name');
})
},
'successful login': function () {
loginPage
.login(values.unamevalue, values.pwdvalue)
loginPage.isLoginSuccess().then(function (loginSuccess) {
assert.isTrue(loginSuccess, 'Login Failed');
});
},
afterEach: function () {
return this.remote.closeCurrentWindow()
}
};
});
});
您可以使用window.open
打开一个新窗口。 诀窍是您要在远程浏览器中运行该命令。 实习生(技术上是Leadfoot)为您提供了两种在this.remote
execute
此操作的this.remote
: execute
和executeAsync
。 例如,只需打开一个新窗口,您可以执行以下操作:
this.remote.execute(function () {
window.open();
})
打开新窗口后,需要切换到该窗口才能与之交互。 脚本可能类似于:
var windowHandles;
this.remote
.getAllWindowHandles()
.then(function (handles) {
windowHandles = handles;
})
.execute(function () { window.open() })
.sleep(500)
.getAllWindowHandles()
.then(function (handles) {
// compare the new handles to windowHandles to figure out which
// is the new window, then switch to it
return this.remote.switchToWindow(newWindowHandle);
})
.get('some_new_url')
// rest of test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.