How to use solo.searchText for searching some text consisting of special characters

牧云@^-^@ 提交于 2019-12-22 17:22:13

问题


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


来源:https://stackoverflow.com/questions/15240700/how-to-use-solo-searchtext-for-searching-some-text-consisting-of-special-charact

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!