2015-04-22 52 views
1

我在我的量角器测试之一中有一个滑块,我可以找到盒子并且可以获得属性(即'多少'),但是我怎样才能在盒子中循环,以便我可以测试验证显示器,例如,如何在量角器中测试滑块

profilepage.slides.next() 
expect(profilepage.slide.slideTitle = 'Credentials' 
profilepage.slides.next() 
expect(profilepage.slide.slideTitle = "Info" 
etc. 

控制器:

.controller('ProfileCtrl', function ($scope, ProfileService) { 

    $scope.data = { 
     numViewableSlides: 0, 
     slideIndex: 0, 
     initialInstruction: true, 
     secondInstruction: false, slides: [ 
      { 
       'template': 'templates/slidebox/credentials.html', 
       'viewable': true 
      }, 

      { 
       'template': 'templates/slidebox/contactinfo.html', 
       'viewable': true 
      }, 
      { 
       'template': 'templates/slidebox/employeeinfo.html', 
       'viewable': true 
      }, 
      { 
       'template': 'templates/slidebox/assignmentinfo.html', 
       'viewable': true 
      } 
     ] 
    } 
    . . . 

模板:

<ion-slide-box on-slide-changed="slideChanged(index)" show-pager="true"> 

     <ion-slide ng-repeat="slide in data.slides | filter:{viewable : true}"> 
      <div ng-include src="slide.template"></div> 
     </ion-slide> 

    </ion-slide-box> 

页面对象:

profilepage.prototype = Object.create({}, { 
backButton: { 
    get: function() { 
     return element(by.css('ion-ios7-arrow-back')); 
    } 
}, 
slides: { 
    get: function() { 
     return element.all(by.repeater('slide in data.slides')); 
    } 
}, 
slideTitle: { 
    get: function (id) { 
     element.all(by.repeater('slide in data.slides')).then(function (slidelist) { 
      var titleElement = slidelist[id].element(by.css('#slideName')); 
      return titleElement.getText(); 
     }); 
    } 
}, 
. . . 

规格:

describe('Profile', function() { 

var ppage = new profilepage(); 

beforeEach(function() { 
    browser.ignoreSynchronization = false; 
}); 

it('should have correct lastname and have four slides on profile page', function() { 
    expect(browser.getCurrentUrl()).toEqual('http://localhost:8100/#/profile'); 
    expect(ppage.lastname).toBe('Smith,'); 
    expect(ppage.slides.count()).toEqual(4); 
    browser.sleep(1000); 
}); 

it('should slide all the pages', function(){ 
    expect(browser.getCurrentUrl()).toEqual('http://localhost:8100/#/profile'); 
    // SLIDE EACH PAGE ABOUT HERE <------------ 
    browser.sleep(1000); 
}) 
+0

我不是程序员,但已经与量角器一起工作了一下。 你能解释一下用户的操作是“滑动”到下一个“幻灯片”吗?这是你正在制造/测试的例子吗? http://codepen.io/keithjgrant/pen/vqnaA – user249656

回答

1

这个想法是在spec文件中使用ionic的$ionicSlideBoxDelegate。为此,我们需要使其全球可访问:

var addProtractorSlideBox, nextSlide; 

addProtractorSlideBox = function() { 
    return browser.addMockModule("services", function() { 
    return angular.module("services").run(function($ionicSlideBoxDelegate) { 
     return window._$ionicSlideBoxDelegate = $ionicSlideBoxDelegate; 
    }); 
    }); 
}; 

nextSlide = function() { 
    return browser.executeScript('_$ionicSlideBoxDelegate.next()'); 
}; 

... 

beforeEach(function() { 
    ... 
    addProtractorSlideBox(); 
    ... 
}); 

it('...', function() { 
    ... 
    nextSlide(); 
    ... 
}) 

此模式对其他离子/角度服务非常有用。

+0

它看起来很好,除了它缺少模块(“服务”,[])一个新模块的空括号:) – Andrej