简体   繁体   English

EarlGrey失败-“键盘在退出第一响应者状态后没有消失”

[英]EarlGrey Failure - “Keyboard did not disappear after resigning first responder status”

I am attempting to write UI tests for my login page. 我正在尝试为我的登录页面编写UI测试。 The page has some intro animations, a search field (for finding the right server to connect to), and then once they select the right server, a username and password field appears. 该页面上有一些介绍性动画,一个搜索字段(用于查找要连接的正确服务器),然后一旦他们选择了正确的服务器,就会出现一个用户名和密码字段。

Here's my test so far: 到目前为止,这是我的测试:

[[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?"]];

This test fails. 该测试失败。

EarlGrey correctly selects, and types into the first text field (searchTextField). EarlGrey正确选择并键入第一个文本字段(searchTextField)。

EarlGrey correctly selects the tableview cell! EarlGrey正确选择了表格视图单元!

EarlGrey then correctly selects the usernameTextField, but then fails to type text, giving the following error after a timeout: 然后,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>>}

"Keyboard did not disappear after resigning first responder status of " “退出第一响应者状态后,键盘没有消失”

Anyone know what's going on here? 有人知道这是怎么回事吗? Strangely, btw, it looks like EarlGrey selects the next field (Password field) right before it errors out. 顺便说一句,顺便说一句,EarlGrey似乎在出错之前就选择了下一个字段(密码字段)。 I have no UI code in there to select the password field at all. 我根本没有UI代码可以选择密码字段。

UPDATE: I am using return key type "Next" on this text field, so that when a user taps the return key, I will take them to the next field (the password field). 更新:我在此文本字段上使用返回键类型“ Next”,以便当用户点击返回键时,我会将它们带到下一个字段(密码字段)。 To do this, when the Next key is hit, I resign firstResponder on that text field, and call "becomeFirstResponder" on the password field. 为此,当按下Next键时,我在该文本字段上退出firstResponder,然后在密码字段上调用“ becomeFirstResponder”。

This is causing EarlGray to error out, because if I remove the "resignFirstResponder" call, then it correctly types my text. 这导致EarlGray出错,因为如果我删除“ resignFirstResponder”调用,那么它将正确键入我的文本。 The question is: WHY IS IT HITTING THE "Next" key when I am not telling it to!? 问题是:为什么我不告诉它时按下“ Next”键!

It looks like a bug in the EarlGray source. 看起来像EarlGray源中的错误。 Line 182 in GREYActions.m 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];

There is no check in place to determine if the view previously had autocorrect enabled. 没有适当的检查来确定视图之前是否已启用自动更正。 So, ALL textfields will call "resignFirstResponder". 因此,所有文本字段都将称为“ resignFirstResponder”。 This is problematic for setups like mine, where resigningFirstResponder then passes firstResponder status to another textfield. 这对于像我的设置是有问题的,其中resigningFirstResponder然后将firstResponder状态传递到另一个文本字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM