LoginSignup
2
3

More than 5 years have passed since last update.

Xcode8のXCTestでアラートの任意のボタンを押す

Last updated at Posted at 2016-10-05

Xcode7のXCTestでは...

app.alerts.collectionViews.buttons["hoge"].tap() 

Xcode8のXCTestでは...

app.alerts.buttons["hoge"].tap() 
  • collectionViewsを挟むと、XCUIElementQueryがアラートのボタンを見つけてくれなくなっているようだ

試しに(lldb)でpoすると...

  • po app.alerts.collectionViews.buttonsだとOutput:が出ない
(lldb) po app.alerts.collectionViews.buttons
    t =   320.73s     Use cached accessibility hierarchy for hoge
    t =   320.74s     Find: Descendants matching type Alert
    t =   320.75s     Find: Descendants matching type CollectionView
Find: Target Application 0x6080000afd20
  Output: {
    Application 0x600000776b00: {{0.0, 0.0}, {414.0, 736.0}}, label: 'fuga'
  }
  ↪︎Find: Descendants matching type Alert
    Output: {
      Alert 0x6000007777c0: traits: 72057602627862528, {{72.0, 237.7}, {270.0, 261.0}}, label: '退会'
    }
    ↪︎Find: Descendants matching type CollectionView
      ↪︎Find: Descendants matching type Button
  • po app.alerts.buttonsだとちゃんと見つけてくれる
(lldb) po app.alerts.buttons
    t =   116.83s     Use cached accessibility hierarchy for hoge
    t =   116.84s     Find: Descendants matching type Alert
    t =   116.85s     Find: Descendants matching type Button
Find: Target Application 0x6080000afd20
  Output: {
    Application 0x600000776b00: {{0.0, 0.0}, {414.0, 736.0}}, label: 'fuga'
  }
  ↪︎Find: Descendants matching type Alert
    Output: {
      Alert 0x6000007777c0: traits: 72057602627862528, {{72.0, 237.7}, {270.0, 261.0}}, label: '退会'
    }
    ↪︎Find: Descendants matching type Button
      Output: {
        Button 0x6000007786c0: traits: 8589934593, {{72.0, 366.0}, {270.0, 44.0}}, label: '退会する'
        Button 0x600000778e40: traits: 8589934593, {{72.0, 454.7}, {270.0, 44.0}}, label: 'キャンセル'
      }

ネット上にある、XCTestのコードではapp.alerts.collectionViews.buttons["hoge"]が結構多いけど、たぶん、Xcode8では正常に動かないと思う

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3