【问题标题】:Can someone explain what evaluate() and dragAndDrop() are calling in the following Angular Test Code?有人可以解释以下 Angular 测试代码中调用的 evaluate() 和 dragAndDrop() 吗?
【发布时间】:2016-08-26 16:10:09
【问题描述】:

以下代码用于测试使用 Protractor 的 angular-Gridster 应用程序的拖放方向。

我是下面这些函数调用的新手,有人能解释一下evaluate() 的意义吗——API 定义太混乱了,还有dragAndDrop()? -- 在任何地方都找不到这个函数

describe('DragAndDrop Test', function () {

require('jasmine-expect');

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

});

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

    //target is where we are dragging the box to.  Box is the Box
    var target = { x: 400, y: 400 };
    var box = element(by.css('.ng-scope.gridster-item'));

    //scope is going to hold the scope variables that tell us where the box is located
    //see the documentation for angular gridster on github for info on scope variable
    //get the standardItems Scope
    box.evaluate('standardItems').then(function (scope) {

        //make sure the box we are using is in column 0 and Row 0
        expect(scope[0].col).toEqual(0);
        expect(scope[0].row).toEqual(0);
    });

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

    //get the updated scope
    box.evaluate('standardItems').then(function (scope) {

        //test to see that the box was actually moved to column and row 2, better test
        expect(scope[0].col).toEqual(2);
        expect(scope[0].row).toEqual(2);
    });
    //this is to test the pixel location which is not the best
    box.getLocation().then(function (location) {
        expect(location.x).toEqual(476);
    });
});
});

var Context = function () {

//load the website
this.get = function () {
    browser.get('https://rawgit.com/ManifestWebDesign/angular-gridster/master/index.html#/main');
};
};

【问题讨论】:

    标签: javascript angularjs protractor gridster


    【解决方案1】:

    evaluate() 将在您调用它的元素范围内评估表达式。当您需要访问范围内的特定变量时很有用:

    评估输入,就好像它在当前元素的范围内一样。


    dragAndDrop() 是一个“浏览器操作”,继承自 WebDriverJS(请记住,Protractor 是建立在 WebDriverJS 之上的):

    执行“拖放”操作的便利功能。这 目标元素可以移动到另一个元素的位置,或者通过 偏移量(以像素为单位)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 2023-04-02
    • 2020-05-29
    • 2016-11-21
    • 1970-01-01
    相关资源
    最近更新 更多