如何避免在Selenium中使用sendKeys方法来清除先前填写的文本?

huangapple 未分类评论44阅读模式
英文:

How to avoid sendKeys method in selenium to clear previously filled text?

问题

以下是翻译好的内容:

我正在使用Appium和Java测试的Android应用程序具有标记/提及用户功能。现在我想要测试这个功能。我想发送多个提及,并验证这些提及是否已发送。我正在测试的应用程序类似于Slack/消息应用程序。

测试用例步骤

  1. 打开聊天室
  2. 点击发送消息字段以激活键盘
  3. 输入@,等待用户列表以进行标记/提及
  4. 点击用户1
  5. 在标记/提及用户1后发送一个空格
  6. 再次输入@并等待用户列表以进行标记/提及
  7. 点击用户2
  8. 点击消息发送按钮

我正在使用页面对象模型。因此,为了执行上述步骤,我在页面类中创建了一个名为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:

  1. Open chatroom
  2. Tap on send message field to activate the keyboard
  3. Type @ and wait for list of users to tag/mention appear
  4. Tap user 1
  5. Send a space after the user1 is tagged/mentioned
  6. Type @ again and wait for list of users to tag/mention appear
  7. Tap user 2
  8. 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, &quot;@&quot;);
    List&lt;MobileElement&gt; mentionPersonNamesList = 
    waitAndReturnElementListIfDisplayed(MENTIONPERSONNAME);
    MobileElement mentionPersonNameSelect0 = mentionPersonNamesList.get(index0);
    tapOnElement(mentionPersonNameSelect0);
    sendKeyToElement(SENDMESSAGEFIELD, &quot;@&quot;);
    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!

huangapple
  • 本文由 发表于 2020年4月10日 15:09:33
  • 转载请务必保留本文链接:https://java.coder-hub.com/61135554.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定