我正在尝试为我的登录页面编写UI测试。该页面有一些简介动画,一个搜索字段(用于查找要连接到的正确服务器),然后一旦他们选择了正确的服务器,就会出现一个用户名和密码字段。
到目前为止,这是我的测试:
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"searchTextField")]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"searchTextField")] performAction:grey_typeText(@"gtX9Vn23k1")];
[[EarlGrey selectElementWithMatcher:grey_anyOf([self matcherForUITableViewCell], nil)] performAction:grey_tap()];
[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"usernameTextField")]
assertWithMatcher:grey_interactable()] performAction:grey_tap()];
[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"usernameTextField")]
assertWithMatcher:grey_interactable()] performAction:[GREYActions actionForTypeText:@"Why isnt this working?"]];这个测试失败了。
EarlGrey正确选择并键入第一个文本字段(searchTextField)。
EarlGrey正确地选择了表视图单元格!
然后,EarlGrey正确地选择了usernameTextField,但是失败了来键入文本,在超时后给出了以下错误:
Exception: ActionFailedException
Reason: Action 'Type "Why isnt this working"' failed.
Element matcher: (respondsToSelector(accessibilityIdentifier) && accessibilityID("usernameTextField"))
Complete Error: Error Domain=com.google.earlgrey.ElementInteractionErrorDomain Code=1 "Keyboard did not disappear after resigning first responder status of <GHDLoginTextField: 0x7fa96a616bd0; baseClass = UITextField; frame = (150 387; 468 29); text = ''; opaque = NO; autoresize = RM+BM; tintColor = UIDeviceWhiteColorSpace 1 1; gestureRecognizers = <NSArray: 0x7fa96a55d5d0>; layer = <CALayer: 0x7fa96a616a80>>" UserInfo={NSLocalizedDescription=Keyboard did not disappear after resigning first responder status of <GHDLoginTextField: 0x7fa96a616bd0; baseClass = UITextField; frame = (150 387; 468 29); text = ''; opaque = NO; autoresize = RM+BM; tintColor = UIDeviceWhiteColorSpace 1 1; gestureRecognizers = <NSArray: 0x7fa96a55d5d0>; layer = <CALayer: 0x7fa96a616a80>>}“键盘”在退出"“的第一个响应者状态后并没有消失。
有人知道这是怎么回事吗?奇怪的是,顺便说一句,EarlGrey似乎在出错之前就选择了下一个字段(Password字段)。我在那里没有UI代码来选择密码字段。
更新:我在这个文本字段上使用返回键类型" next“,这样当用户点击返回键时,我将带他们到下一个字段(密码字段)。为此,当下一个键被击中时,我在该文本字段上退出firstResponder,并在密码字段上调用"becomeFirstResponder“。
这会导致EarlGray出错,因为如果我删除"resignFirstResponder“调用,它就会正确地键入我的文本。问题是:当我没有告诉它的时候,它为什么要按下一个键!?
发布于 2016-03-24 23:35:57
它看起来像是EarlGray源代码中的一个bug。GREYActions.m第182行
// If the view already is the first responder and had autocorrect enabled, it must
// resign and become first responder for the autocorrect type change to take effect.
[firstResponder resignFirstResponder];没有进行检查以确定视图以前是否已启用自动更正。因此,所有文本字段都将调用"resignFirstResponder“。对于像我这样的设置来说,这是有问题的,resigningFirstResponder然后将firstResponder状态传递给另一个textfield。
https://stackoverflow.com/questions/36208917
复制相似问题