Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在intern js中打开新的浏览器窗口?_Javascript_Selenium_Intern_Leadfoot - Fatal编程技术网

Javascript 如何在intern js中打开新的浏览器窗口?

Javascript 如何在intern js中打开新的浏览器窗口?,javascript,selenium,intern,leadfoot,Javascript,Selenium,Intern,Leadfoot,我正在自动化应用程序的UI测试。在某些情况下,我希望我的测试脚本关闭当前浏览器并通过打开新浏览器运行下一个测试。问题是我不知道如何在intern中打开新的浏览器窗口remote.get(URL)不执行我在此处要执行的操作。有人能帮忙吗 我已经更新了我的问题,包括代码以及。不过,我的问题很直截了当如何使用intern from inside test打开新的浏览器窗口?。 虽然如果你想看到代码,请评论,我会写下来。 谢谢 您可以使用窗口打开新窗口。打开。诀窍在于您希望在远程浏览器中运行该命令。In

我正在自动化应用程序的UI测试。在某些情况下,我希望我的测试脚本关闭当前浏览器并通过打开新浏览器运行下一个测试。问题是我不知道如何在intern中打开新的浏览器窗口
remote.get(URL)
不执行我在此处要执行的操作。有人能帮忙吗

我已经更新了我的问题,包括代码以及。不过,我的问题很直截了当如何使用intern from inside test打开新的浏览器窗口?。 虽然如果你想看到代码,请评论,我会写下来。 谢谢


您可以使用
窗口打开新窗口。打开
。诀窍在于您希望在远程浏览器中运行该命令。Intern(技术上是Leadfoot)为您提供了两种在
上执行此操作的方法。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

您可以使用
窗口打开新窗口。打开
。诀窍在于您希望在远程浏览器中运行该命令。Intern(技术上是Leadfoot)为您提供了两种在
上执行此操作的方法。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

你试过
window.open()
?是的,我试过了,但我不确定如何在脚本中包含
window
,因为它给出了
window未定义的错误。嗯。。。除此之外,没有实习经验:PSo您需要在queston中添加一些代码。窗口应该可以工作,但它并没有在脚本中定义。需要更多信息。更新了我的问题以添加代码。您是否尝试过
窗口.open()
?是的,我尝试过,但我不确定如何在脚本中包含
窗口
,因为它给出了
窗口未定义
错误。嗯。。。除此之外,没有实习经验:PSo您需要在queston中添加一些代码。窗口应该可以工作,但它并没有在脚本中定义。需要更多信息。更新了我的问题以添加代码。感谢@jason0x43的回复。你的答案基本上会打开一个新标签。我想做的和你的答案不一样。我想:1。执行第一个测试时关闭浏览器(现在没有浏览器)。2.打开新浏览器并执行下一个测试。如果要关闭现有的浏览器窗口,请在第二个
getAllWindowHandles
之前添加一个
closeCurrentWindow
。我想您可能希望保持它处于打开状态以进行调试。至于打开新选项卡与新窗口,请尝试提供窗口参数,如
window.open('url','name','height=500,width=600')
。感谢@jason0x43的响应。你的答案基本上会打开一个新标签。我想做的和你的答案不一样。我想:1。执行第一个测试时关闭浏览器(现在没有浏览器)。2.打开新浏览器并执行下一个测试。如果要关闭现有的浏览器窗口,请在第二个
getAllWindowHandles
之前添加一个
closeCurrentWindow
。我想您可能希望保持它处于打开状态以进行调试。至于打开新选项卡与新窗口,请尝试提供窗口参数,如
window.open('url','name','height=500,width=600')