如何使用solo.searchText用于搜索一些文字组成的特殊字符如何使用、特殊字符、文字、searchText

由网友(流年╮渲染成伤)分享简介:我使用robotium来测试机器人project.I有一个测试用例,我需要测试包括特殊字符的消息是否正确张贴。因此,我创建包括特殊字符常数:I am using robotium to test an android project.I have a testcase where i need to test a m...

我使用robotium来测试机器人project.I有一个测试用例,我需要测试包括特殊字符的消息是否正确张贴。因此,我创建包括特殊字符常数:

I am using robotium to test an android project.I have a testcase where i need to test a message consisting of special characters is posted correctly. So I created a constant consisting of special characters :

public static final String PostMessageWithSpecialchars = "Hey hi,* Have a good day*.:()[]-=/&!?"'+;@#";

和我使用以下code进行搜索,并断言,发布消息是在不断PostMessageWithSpecialchars

and i am using following code to search it and assert that the posted message is exactly like the message in the constant PostMessageWithSpecialchars

assertTrue(solo.searchText(PostMessageWithSpecialchars));

但assertTrue线测试失败。怎样做才能搜索PostMessageWithSpecialchars文字?我不想使用转义字符,因为这会忽略特殊characters.I要确保在PostMessageWithSpecialchars消息中的特殊字符正确发布。

but the test fails at assertTrue line. What to do to search the PostMessageWithSpecialchars text?I dont want to use escape characters because that will ignore special characters.I want to make sure that the special characters in the PostMessageWithSpecialchars message are posted correctly.

推荐答案

该方法solo.searchText()接受正则表达式。在搜索字符串中使用的是一个用于patters特殊字符。你可以引述他们找到任何文字:

The method solo.searchText() accept regex pattern. In your search string you are using special characters that is used for patters. You can quote them to find any text:

assertTrue(solo.searchText(Pattern.quote(PostMessageWithSpecialchars)));
阅读全文

相关推荐

最新文章