簡體   English   中英

如何在實習生js中打開新的瀏覽器窗口?

[英]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.remoteexecuteexecuteAsync 例如,只需打開一個新窗口,您可以執行以下操作:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM