How to use solo.searchText for searching some text

2019-05-25 02:18发布

问题:

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*.:()[]-=/&!?"'+;@#";

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));

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.

回答1:

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)));