4

ひょうたん/キュウリのテストで、iOS のアラートビューのテキストにアクセスするにはどうすればよいですか?

NSString *msgString = [NSString stringWithFormat:@"No: %@\n Latitude: %f\n Longitude: %f", wrapper.no, wrapper.latitude, wrapper.longitude];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"msgString" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
// optional - add more buttons:
[alert addButtonWithTitle:@"Yes"];
[alert show];

アラートに期待される内容があることを主張したい:

Feature: Running a test
  As a user using a phone connected to the internet
  I want to have correct sample data retrieved from cache or net
  So I can read the values of the tableview

   Scenario: Testing retrieved data

  Given the app is running
  Then I press "Refresh"
  Then I should see "Some value"
  Then I press "Some value"
  Then I should /*See an alert with "myMessage"*/
  Then I press "OK"

  And take picture

したがって、文字列を単純に「いいえ:」に変更し、文字列から他のすべてを破棄すると、実際には機能しているように見えますが、より複雑な文字列で実行することはできません:(

4

4 に答える 4

4

私はこのコードとその動作をテストしました

ステップ定義ファイル内 (ProjectName/features/step_definitions/my_first_steps.rb) に追加

Then /^I see an alert with "([^\"]*)" text$/ do |message|
    result = query("view:'UIAlertView' label text:'#{message}'").empty?
    if result
        screenshot_and_raise "could not find text field with AlertView with text '#{message}'"
    end
    sleep(STEP_PAUSE)
end

機能ファイルで

Then I see an alert with "Email cannot be empty." text

テキストがメッセージと一致しない場合、スクリーンショットが撮られ、テストに失敗します

しかし、これはシステムアラートではなく、カスタムアラートに対して機能しています..!!

これは、アラートからのメッセージを読む必要がある場合に役立ちます

開い$ calabash-ios console

のようなクエリquery("view:'UIAlertView'",:message)

さらに追加....

または、次のようなものを使用できます

Then /^I wait until alert with text "([^\"]*)" and press "([^\"]*)" button$/ do |message, button|

  wait_for_elements_exist(["alertView child label marked:'#{message}'"], :timeout => 30,  :retry_frequency => 0.3,:timeout_message => "Timed out waiting..",:screenshot_on_error => true )
    if element_exists("alertView child label marked:'#{message}'")
      touch("button marked:'#{button}'")
      sleep(STEP_PAUSE)
    else
      screenshot_and_raise "Alert Element not found"
    end
end
于 2013-05-08T09:33:45.710 に答える