如何在量角器测试运行之前设置浏览器大小?

时间:2016-05-05 00:05:21

标签: angularjs protractor

我在下面列出了以下量角器测试。它运行正常。但是我需要添加一些代码才能将浏览器打开到全屏,因为我的测试对gridster tile的像素位置很敏感。如何才能做到这一点?

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 个答案:

答案 0 :(得分:2)

我认为更好的做法是在配置中执行此操作。

onPrepare: function() {
browser.manage().window().setSize(1600, 1000);
}

or

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

答案 1 :(得分:1)

您已在document.getElementById('link').onclick = function() { if( document.getElementById('option1').checked) { location.href = '/product/option1.html'; } else { location.href = '/product.html'; } }; 功能中使用此行,这将在运行任何测试之前最大化您的浏览器:

beforeAll

但是,在某些操作系统上,Chrome浏览器不会水平地,垂直地最大化窗口。您有两种选择:

a)明确将宽度设置为某个预定义值,例如:

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

b)使用Javascript函数获取屏幕分辨率并相应地设置窗口大小。

browser.driver.manage().window().setSize(1200, 768);