如何在我的Protractor测试运行之前设置浏览器大小?

4

我有以下的protractor测试。它可以正常运行。但是,由于我的测试对gridster瓷砖的像素位置非常敏感,所以我需要添加一些代码来将浏览器打开到全屏状态。如何实现?

describe('DragAndDrop Test', function () {
require('protractor');
require('jasmine-expect');


beforeAll(function () {
    context = new Context();
    context.get();
    browser.waitForAngular();
    browser.driver.manage().window().maximize();

});

it('should drag and drop Application Experience tile', function () {

    //a = angular.element(document).find('h3')[1]
    //target is where we are dragging the box to.  Box is the Box
    var target = { x: 300, y: 50 };
    var box = element(by.cssContainingText('h3', 'Application Experience'));
    var infoSpot = element(by.cssContainingText('h3', 'Application Experience'));


    //scope is going to hold the scope variables that tell us where the box is located
    //get the standardItems Scope


    box.evaluate('dashboards').then(function(scope) {
        //make sure the box we are using is initially set in column 0 and Row 0
        expect(scope['1'].widgets[0].col).toEqual(0);
        expect(scope['1'].widgets[0].row).toEqual(0);
    });

    //drag and drop the box somewhere else.
    browser.actions().dragAndDrop(box, target).perform();
    browser.waitForAngular();
    browser.driver.sleep(5000);

    //get the updated scope
    box.evaluate('dashboards').then(function(scope) {
        //test to see that the box was actually moved to column 1 and row 0
        expect(scope['1'].widgets[0].col).toEqual(1);
        expect(scope['1'].widgets[0].row).toEqual(0);
    });
});
});

var Context = function () {
this.ignoreSynchronization = true;
    //load the website
    this.get = function () {
        browser.get('http://127.0.0.1:57828/index.html#/dashboard');
    };
};
2个回答

2
我认为更好的做法是在您的配置文件中完成这个操作。
onPrepare: function() {
browser.manage().window().setSize(1600, 1000);
}

or

onPrepare: function() {
browser.manage().window().maximize();
}

1

您已经在beforeAll函数中拥有了这行代码,它将在任何测试运行之前最大化您的浏览器:

browser.driver.manage().window().maximize();

然而,在一些操作系统上,Chrome浏览器仅能在垂直方向上最大化窗口,而无法在水平方向上。有两个选择:
a)将宽度明确设置为预定义值,例如:
browser.driver.manage().window().setSize(1200, 768);
b) 使用Javascript函数获取屏幕分辨率并相应地设置窗口大小。
var width = GET_WIDTH;
var height = GET_HEIGHT;    
browser.driver.manage().window().setSize(width, height);

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