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

查看:109
本文介绍了排毒: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天全站免登陆