2015-06-01 56 views
0

是否有人成功使用量角器來檢測離子拾音器警報? 我嘗試了所有建議here的解決方法,但沒有運氣。 我需要量角器來檢測警報並檢查警報中的文字。量角器+離子拾音器

+0

您能否提供一個可重複使用的公共站點示例? – alecxe

回答

3

這裏是我寫來測試彈出存在階級和以確保文本在標題和正文中是正確的:

var TestUtilities = function(){ 
    this.popup = element(by.css('.popup-container.popup-showing.active')); 

    //Tests to see if $ionicPopup.alert exists 
    this.popupShouldExist = function() { 
     expect(this.popup.isDisplayed()).toBeTruthy(); 
    }; 

    //Tests to see if $ionicPopup.alert contains the text provided in the argument exists in the header 
    this.popupContainsHeaderText = function (text) { 
     this.popupShouldExist(); 
     expect(this.popup.element(by.css('.popup-head')).getText()).toMatch(text); 
    }; 

    //Tests to see if $ionicPopup.alert contains the text provided in the argument exists in the body 
    this.popupContainsText = function (text) { 
     this.popupShouldExist(); 
     expect(this.popup.element(by.css('.popup-body')).getText()).toMatch(text); 
    }; 
}; 

module.exports=TestUtilities; 

也查看本網站更多關於在量角器中測試離子的問題,它談到如何檢查彈出是否存在:http://gonehybrid.com/how-to-write-automated-tests-for-your-ionic-app-part-3/

+0

完美答案!這完全回答了我的問題,包括如何檢查標題和正文中的文本,都包含在一個很好的通用實用程序類中。謝謝!! –

0

離子彈出只是由DOM元素組成,所以你應該能夠使用普通的定位器來查找/測試它們。由於它們不是由警報組成的,因此您鏈接的問題的解決方法可能無用。

0

我明白了 - 我看到很多問題都試圖以非常複雜的方式來完成,但最終我嘗試了這一點,結果證明這很簡單。

檢查你的元素,並找到自己的NG-重複值,然後

var button = element(by.repeater('button in buttons')).getText()

您還需要有瀏覽器坐在莫名其妙的一對夫婦秒,所以它不解析而測試離子彈出實際上並不存在。

爲此,browser.sleep(3000);

這就是它!但是,獲取那裏的另一個按鈕被證明是一個小問題。 var button = element(by.repeater('button in buttons')).get(0).get(1) return undefined不是函數。

如果您喜歡,請接受答案!如果我弄清楚如何獲得其他按鈕,我會在這裏發佈。

var popup = element(by.css('.popup-container.popup-showing.active')); 

而且在測試::

+0

這不適合我。我得到了:NoSuchElementError:找不到使用定位器的元素:by.repeater(「按鈕中的按鈕」) –

+0

你必須檢查元素,看看它們用於中繼器,即香蕉香蕉? – realization

2

我已經通過設置彈出變量,如下所示成功測試離子彈出窗口

expect(popup.isDisplayed()).toBeTruthy(); 
+0

非常感謝!這工作。另見http://gonehybrid.com/how-to-write-automated-tests-for-your-ionic-app-part-3/ –