2016-05-01 21 views
1

以下代码用于使用量角器测试角度Gridster应用程序的拖放方向。我是新来的这些函数调用下面,有人会友好地解释评估()的意义 - API定义太混乱了,dragAndDrop()? - 无法在任何地方找到此功能有人可以解释什么评估()和dragAndDrop()在以下Angular测试代码中调用?

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'); 
}; 
}; 

回答

2

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

将输入评估为当前元素的范围。


dragAndDrop()是一个“浏览器操作”,并从WebDriverJS(记住,量角器是建立在WebDriverJS顶部)继承:

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

+0

谢谢,你能解释评估()有点简单吗? –

+0

@KunalOjha我可能只是引用你的例子用法和相关的线程 - 应该清除的东西:http://stackoverflow.com/a/20620056/771848,http://stackoverflow.com/a/27629579/771848,HTTP ://stackoverflow.com/a/36385225/771848,http://stackoverflow.com/a/35946919/771848 ... – alecxe

+0

它呢,谢谢! –

相关问题