Tie*_*udt 10 angularjs-e2e protractor ionic-framework ionic e2e-testing
有类似的问题(下面链接)但没有解决这个问题.我正在为一个离子项目编写量角器测试.当Ionic Loading对话框出现并消失时,我需要执行测试.
我已经用应用程序的骨干和需要进行的测试创建了一个repo.解决这个问题并解决问题(我在下面描述了这个问题):https://github.com/TmanTman/StackoverflowQ.只需在conf.js中调整适用于您系统的Chrome的路径即可.
要模拟异步离子加载对话框,我只需将其添加到空白离子项目中的控制器:
$interval( function() {
$ionicLoading.show({
template: 'Async ionicLoading',
duration: 5000
});
}, 5000 , 1);
})
Run Code Online (Sandbox Code Playgroud)
我需要让量角器等待对话框出现,做一些测试,等待对话框消失,然后再进行一些测试.我在测试文件中的最新尝试是:
it('should only test when ionicLoading appears', function() {
browser.wait(function(){
return element(by.css('.loading-container.visible.active')).isPresent();
}, 10000);
var ionicLoadingText = element(by.css('.loading-container.visible.active')).getText();
expect(ionicLoadingText).toEqual('Async IonicLoading');
})
it('should only test once ionicLoading disappears', function() {
browser.wait(function() {
var deferred = protractor.promise.defer();
var q = element(by.css('.loading-container.visible.active')).isPresent()
q.then( function (isPresent) {
deferred.fulfill(!isPresent);
});
return deferred.promise;
});
expect(1).toEqual(1);
})
Run Code Online (Sandbox Code Playgroud)
我试图避免使用同步睡眠功能,因为我的代码是高度异步的.我尝试了无数的变化,但我无法让它发挥作用.我用于信息的链接包括:
问题是双重的:
1)从我可以推断出,$ ionicLoading方法的duration属性是使用超时函数实现的.量角器与$ timeout不兼容.因此,不使用duration属性,可以使用$ interval调用隐藏$ ionicLoading对话框(调整问题中的代码):
$interval( function() {
$ionicLoading.show({
template: 'Async IonicLoading'
});
$interval( function() {
$ionicLoading.hide();
}, 5000, 1)
}, 5000 , 1);
Run Code Online (Sandbox Code Playgroud)
2)检测异步更改的代码如下:
it('should only test when ionicLoading appears', function() {
browser.wait(function() {
var deferred = protractor.promise.defer();
var q = element(by.css('.loading-container.visible.active')).isPresent()
q.then( function (isPresent) {
deferred.fulfill(isPresent);
});
return deferred.promise;
}, 10000);
var ionicLoadingText = element(by.css('.loading-container.visible.active')).getText();
expect(ionicLoadingText).toEqual('Async IonicLoading');
})
it('should only test once ionicLoading disappears', function() {
browser.wait(function() {
var deferred = protractor.promise.defer();
var q = element(by.css('.loading-container.visible.active')).isPresent()
q.then( function (isPresent) {
deferred.fulfill(!isPresent);
});
return deferred.promise;
}, 10000);
expect(1).toEqual(1);
})
Run Code Online (Sandbox Code Playgroud)
然后两个测试通过.
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |