排毒:iOS 模拟器如何确认警报消息 [英] Detox: iOS Simulator how to confirm alert message

查看:16
本文介绍了排毒:iOS 模拟器如何确认警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自 react-native 的 Alert.

I am using Alert from react-native.

我如何通过按下警报消息上的注销"按钮来排毒?

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

我尝试使用 await element(by.text('Log out')).tap();

但我收到匹配多个元素"的错误消息.据推测,它找到了 3 个具有相同标签的元素.带有注销"标签的原始按钮用于触发警报消息、警报消息标题和我想要排毒的警报消息按钮.

But I get "Multiple elements were matched" error. Presumably it finds 3 elements with same label. The original button with label "Log out" used to trigger the alert message, the alert message title, and the alert message button I want detox to press.

Error Trace: [
  {
    "Description" : "Multiple elements were matched: (
    "<UILabel:0x7fe7964db910; AX=Y; AX.label='Log out'; AX.frame={{41, 234}, {238, 20.5}}; AX.activationPoint={160, 244.25}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{16, 20}, {238, 20.5}}; opaque; alpha=1; UIE=N; text='Log out'>",
    "<UILabel:0x7fe7964dda90; AX=Y; AX.label='Log out'; AX.frame={{198.5, 322.5}, {58, 20.5}}; AX.activationPoint={227.5, 332.75}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{0, 12}, {58, 20.5}}; opaque; alpha=1; UIE=N; text='Log out'>",
    "<RCTText:0x7fe79652f300; AX=Y; AX.label='Log out'; AX.frame={{16, 338.5}, {288, 17}}; AX.activationPoint={160, 347}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{0, 0}, {288, 17}}; alpha=1>"
). Please use selection matchers to narrow the selection down to single element.",
    "Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
    "Error Code" : "5",
    "File Name" : "GREYElementInteraction.m",
    "Function Name" : "-[GREYElementInteraction grey_errorForMultipleMatchingElements:withMatchedElementsIndexOutOfBounds:]",
    "Line" : "956"
  }
]

我想一种方法是使用 .atIndex(),但这意味着每次发生变化时我都需要使用索引来确定正确的元素.

I guess one way is to use .atIndex(), but that means I need to play with indexes every time something changes to determine the correct element.

有没有更好的方法来解决这个问题?

Is there no better way to address this issue?

谢谢.

推荐答案

经过一些修补后,我最终使用了这个:

After some tinkering I ended up using this:

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

不确定这是否适用于每个 iOS 版本,但似乎适用于 10.3 和 11.1

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

使用 Xcode 提供的 View Hierarchy Debugger 查看类型是否因不同的 iOS 版本而改变.

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

这篇关于排毒:iOS 模拟器如何确认警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆