0

我正在自动化我的应用程序的 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()
        }
    };
  });
});
4

1 回答 1

2

您可以使用 . 打开一个新窗口window.open。诀窍是您想在远程浏览器中运行该命令。实习生(技术上是 Leadfoot)在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
于 2017-01-26T20:10:36.803 回答