英文:
How to avoid sendKeys method in selenium to clear previously filled text?
问题
以下是翻译好的内容:
我正在使用Appium和Java测试的Android应用程序具有标记/提及用户功能。现在我想要测试这个功能。我想发送多个提及,并验证这些提及是否已发送。我正在测试的应用程序类似于Slack/消息应用程序。
测试用例步骤:
- 打开聊天室
- 点击发送消息字段以激活键盘
- 输入@,等待用户列表以进行标记/提及
- 点击用户1
- 在标记/提及用户1后发送一个空格
- 再次输入@并等待用户列表以进行标记/提及
- 点击用户2
- 点击消息发送按钮
我正在使用页面对象模型。因此,为了执行上述步骤,我在页面类中创建了一个名为sendMultiMention的方法,如下所示:
@Override
public ChatroomPage sendMultiMention(int index0, int index1){
sendKeyToElement(SENDMESSAGEFIELD, "@");
List<MobileElement> mentionPersonNamesList =
waitAndReturnElementListIfDisplayed(MENTIONPERSONNAME);
MobileElement mentionPersonNameSelect0 = mentionPersonNamesList.get(index0);
tapOnElement(mentionPersonNameSelect0);
sendKeyToElement(SENDMESSAGEFIELD, "@");
MobileElement mentionPersonNameSelect1 = mentionPersonNamesList.get(index1);
tapOnElement(mentionPersonNameSelect1);
tapOnElement(SENDMESSAGEBUTTON);
return this;
}
上面代码的问题在于第二个sendKeytoElement会覆盖(即清除)之前填写的发送消息文本字段中的文本。
所以它的操作如下:
输入@ -> 选择用户1 -> 清除@用户1 -> 再次输入@ -> 选择@用户2。
但我想要的操作是:
输入@ -> 选择用户1 -> 输入一个空格 -> 再次输入@ -> 选择@用户2
(即不要从发送消息文本字段中清除@用户1)
非常感谢您的帮助!
英文:
The android application that I'm testing using Appium with Java has the tag/mention users feature. Now I want to test this feature. I'd like to send multiple mentions and verify that the mentions are sent or not. The application that I'm testing is similar to slack/messaging application.
Test case steps:
- Open chatroom
- Tap on send message field to activate the keyboard
- Type @ and wait for list of users to tag/mention appear
- Tap user 1
- Send a space after the user1 is tagged/mentioned
- Type @ again and wait for list of users to tag/mention appear
- Tap user 2
- Tap message send button
I'm using page object model. So to perform the above steps I created a method named sendMultiMention in the page class as follows:
@Override
public ChatroomPage sendMultiMention(int index0, int index1){
sendKeyToElement(SENDMESSAGEFIELD, "@");
List<MobileElement> mentionPersonNamesList =
waitAndReturnElementListIfDisplayed(MENTIONPERSONNAME);
MobileElement mentionPersonNameSelect0 = mentionPersonNamesList.get(index0);
tapOnElement(mentionPersonNameSelect0);
sendKeyToElement(SENDMESSAGEFIELD, "@");
MobileElement mentionPersonNameSelect1 = mentionPersonNamesList.get(index1);
tapOnElement(mentionPersonNameSelect1);
tapOnElement(SENDMESSAGEBUTTON);
return this;
}
So the problem with the above code is the 2nd sendKeytoElement overwrites (i.e. clears) the previously filled text in the send message text field.
So what it does is the following:
types @ -> selects user1 -> clears @user1 ->types @ again -> selects @user2.
But what I want is to do the following:
types @ -> selects user1 -> give a space ->types @ again -> selects @user2
(i.e. DO NOT CLEAR @user1 FROM THE SEND MESSAGE TEXT FIELD)
Any help will be highly appreciated!
专注分享java语言的经验与见解,让所有开发者获益!
评论