Detox: iOS Simulator how to confirm alert message

前端 未结 3 2007
忘掉有多难
忘掉有多难 2020-12-11 01:14

I am using Alert from react-native.

How do I get detox to press the \"Log out\" button on the alert message?

I tried using await element(by.te

相关标签:
3条回答
  • 2020-12-11 01:32

    After some tinkering I ended up using this:

    await element(by.label('Log out').and(by.type('_UIAlertControllerActionView'))).tap();
    

    Not sure if this will work for every iOS version, but seem to work on 10.3 and 11.1

    Use View Hierarchy Debugger provided by Xcode to see if the type has changed for a different version of iOS.

    0 讨论(0)
  • 2020-12-11 01:49

    You can now press on native dialogs. Tested on iOS. (did not test on Android)

    If your button says "OK" ie:

    Alert.alert(
      `Are you sure you would like to remove this image as the coming soon image?`,
      undefined,
      [
        {
          text: "No",
          style: "cancel",
        },
        {
          text: "OK",
          style: "destructive",
          onPress: this.onRemoveHero,
        },
      ]
    );
    

    You would click this by doing:

    element(by.label("OK")).atIndex(0).tap();
    
    0 讨论(0)
  • 2020-12-11 01:55

    It should work with finding element by text

    await element(by.text('Log out')).tap();
    

    Demo repo: https://github.com/FDiskas/demonas/blob/c703840a991b2f3d96a18ac8c5120ee1d5f901f8/e2e/firstTest.spec.ts#L11

    0 讨论(0)
提交回复
热议问题