2014-02-09 46 views
0

在iOS 7之後我們在使用葫蘆進行UIAlertView驗證時遇到了問題。在iOS7中使用UIAlertView發現葫蘆

現在我能夠檢測使用

wait_for_elements_exist(["view:'_UIModalItemRepresentationView'"], :timeout => 20) 
query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty? 

我從https://gist.github.com/seanoshea/7613671

而在此前的想法警報消息(在iOS 6中),我們能夠探測到的消息和標題明確像這樣

title = query("view:'UIAlertView'",:title).first 
msg = query("view:'UIAlertView'",:message).first 

有沒有什麼辦法可以在iOS7中做到這一點? 「坦率」球員做同樣的我認爲https://github.com/moredip/Frank/pull/262

注意:jmoody Plese幫助我們在葫蘆自動化中使用此iOS 7警報。

+0

我們意識到這個問題。這是(我們相信)UIAutomation中的一個錯誤。 https://github.com/calabash/calabash-ios/issues/215我們建議您提交一份雷達。與此同時,[Chathura Palihakkara](http://stackoverflow.com/users/634678/chathura-palihakkara)發佈的代碼似乎是解決問題的方法。雖然他在紅寶石中得到了-1的CamelCase ...;) – jmoody

+0

對不起CamelCase。這是我第一次遇到紅寶石:)。 –

回答

2

現在我一直在使用這個解決方案。如果有人面臨同樣的問題,可以使用這個,直到我們有一個很好的解

Then /^I should see empty email alert$/ do 
    is_alert_exist_with_text("Email cannot be empty.") 
    sleep(0.5) 
    touch_alert_button("OK") 
end 
########定義功能
def touch_alert_button(button) 
    btn = query("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first.empty? 
    if (btn) 
    screenshot_and_raise "button not found '#{button}'" 
    else 
    touch("view:'_UIModalItemTableViewCell' label marked:'#{button}'").first 
    sleep(0.2) 
    end 
end 

def is_alert_exist_with_text(text) 
    unless query("view:'_UIModalItemRepresentationView' label marked:'#{text}'",).empty? 
    return true 
    else 
    screenshot_and_raise "could not find the text '#{text}' in alert view" 
    end 
end 

而且更多...

def is_alert_exist_with_title_and_message(title, message) 
    elements = query("view:'_UIModalItemRepresentationView' label", 'text') 
    buttons = query("view:'_UIModalItemTableViewCell' label", 'text') 
    textLabels = elements - buttons 

    if (textLabels.count == 2) 
    screenshot_and_raise "Alert Title '#{title}' not found" unless (textLabels[0].eql? title) 
    screenshot_and_raise "Alert Message '#{message}' not found" unless (textLabels[1].eql? message) 
    else 
    screenshot_and_raise "Argument error...isAlertExistWithTitleAndMessage function" 
    end 
end