强制浏览器在新标签页中打开

3

我有一个执行上传操作的应用程序。我似乎无法关闭文件系统弹出窗口。它不会破坏测试,它在后台继续运行,但我有一点想看测试,四分之一的屏幕被遮盖了。所以我想解决这个问题的方法就是强制在新标签页中完成测试的其余部分。我不知道如何做到这一点。

以下是我的上传代码:

var uploadPathLink = element(by.css('button.btn.btn-select'));
var path = require('path');
//the file to upload
fileToUpload,
//this is variable that inserts the path to find file to upload
absolutePath = path.resolve(__dirname, fileToUpload);
//inserts the path
uploadPathLink.sendKeys(absolutePath);

与这个问题相关:上传模态框在发送文件路径后无法关闭

@JeffC 这非常相似,但是它使用的是过时的 Protractor 语法版本。 - Nicole Phillips
1个回答

3
要打开一个新选项卡,可以通过键盘输入通常使用的命令(CONTROL+T)来实现。以下是一个示例 -
element(by.tagName('html')).sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "t")); //If you are using MAC then replace CONTROL with COMMAND
//element can be any element in your DOM

稍后,您可以使用getWindowHandle()切换到新标签页。希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接