mosil / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

soloSearchText() doesn't work correctly. #489

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm having a problem with searchText() function used with Robotium.

I'm searching for this string:

<string name="provisioning_wizard_title_2">Service Activation Wizard (Step 
2)</string>

I defined it in string xml, and I'm searching it this way:

Activity act=solo.getCurrentActivity(); 
String string = solo.getString(act.getResources().getIdentifier(stringId, 
"string", act.getPackageName()));

It fails when I call

assertTrue(solo.searchText(provisioning_wizard_title_2));

and it fails also if i call:

assertTrue(solo.searchText("Service Activation Wizard (Step 2)"));
even if that is the string I'm seeing in the focused screen activity.

The strange thing is that it works if I use the same string without last 
character:

assertTrue(solo.searchText("Service Activation Wizard (Step 2"));

and it works if I use

assertTrue(solo.searchText(string.substring(0, string.length()-1)));

I hope someone could help me.

Sorry for my english!

Thank you.

Original issue reported on code.google.com by flavioca...@gmail.com on 19 Jul 2013 at 8:59

GoogleCodeExporter commented 9 years ago
Due to regex support in searchText() some characters will trigger it. Use 
Pattern.quote(string) example: Pattern.qoute("provisioning_wizard_title_2")

Original comment by renasr...@gmail.com on 19 Jul 2013 at 10:59

GoogleCodeExporter commented 9 years ago
Thanks! It works!!! :)

Original comment by flavioca...@gmail.com on 19 Jul 2013 at 12:16

GoogleCodeExporter commented 9 years ago
I'm having the same problem with this string:
<string name="terms_and_conditions_title">Terms & Conditions</string>

Original comment by flavioca...@gmail.com on 22 Jul 2013 at 3:47

GoogleCodeExporter commented 9 years ago
Does searchText("Terms") work?

Original comment by renasr...@gmail.com on 23 Jul 2013 at 8:54

GoogleCodeExporter commented 9 years ago
Thank for answering.
Yes It works with that string but now it's not working with another string:

<string name="end_wizard_text">
    Service activation wizard is almost complete. Press \'Done\' button to
activate MDP Client.
</string>

I'm calling it from Robium test class as follow:

Activity act=solo.getCurrentActivity();
String s =
solo.getString(act.getResources().getIdentifier("end_wizard_text",
"string", act.getPackageName()));
return Pattern.quote(s);
assertTrue("End activation screen expected.",
solo.searchText(Pattern.quote(s)));

But it never fails; If i test this on a different layout it
solo.searchText() keeps on returning true even if I don't have that text on
the screen.

Thank you!

Flavio Capaccio - (+39) 3928925046

Original comment by flavioca...@gmail.com on 23 Jul 2013 at 8:59

GoogleCodeExporter commented 9 years ago
Then you need to use public boolean searchText(String text, boolean 
onlyVisible) as the view is still there but hidden. Setting onlyVisible to true 
will only search for visible views. Please see the javadoc for more 
information. 

https://code.google.com/p/robotium/wiki/RobotiumAPIDocumentation

Original comment by renasr...@gmail.com on 23 Jul 2013 at 9:02