Robotium for Android - solo.searchText () not working - android

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("provisioning_wizard_title_2", "string", act.getPackageName()));
It fails when I call
assertTrue(solo.searchText(string));
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.
PROBLEM SOLVED
I solved problem thanks to Renas Reda (Founder and maintainer of Robotium).
The problem is due to regex support in searchText(); some characters will trigger it.
Use Pattern.quote(string)
Example: Pattern.qoute("provisioning_wizard_title_2") and eveything works good!

I usually use Solo#waitForText(...) so I make sure I'm not losing some race condition.
Try this:
assertTrue(solo.waitForText( solo.getString(R.string. provisioning_wizard_title_2) );
Make sure you are importing the correct R.java file from your production project (not the test project).

I'm not sure, what string you are fetching. Try to log it:
Log.d("Debug", "String is: " + string);
you should rather call, here may be another issue related to package as activity may be in another package than main package of application:
String string = solo.getString(act.getResources().getIdentifier(act.getPackageName()+":string/provisioning_wizard_title_2"), null, null));
You can also get all visible texts, to make sure, what is on the screen:
for(TextView textView : solo.getCurrentViews(TextView.class)) {
Log.d("DEBUG", "Text on the screen: " + textView.getText().toString());
}

Related

BubblePopupHelper filling Android Debug Log

So I noticed when I was debugging that there seems to be a tag that's repeating through my app entitled "BubblePopupHelper" with text: "isShowingBubblePopup : false"
Screenshot of the log
To my knowledge, I'm not using or causing it. Does anyone have an idea of what's going on? The application is the one I'm writing.
Upon further inspection, I did notice that every time I'm updating text (via a TextView) it displays onscreen. If there's a better way of doing so, please let me know.
Thanks!
The message seems to be logged by some SDK libraries whenever setText is called in a TextView. I get it in Android Studio developing with min API 14.
One interim solution till Google removes it would be using the filtering feature of Android Studio by writing a RegEx that only includes your log messages. For example if I have all my tags start with 'Braim' then 'Braim.*' can be used
If you want to filter this annoying logs away you can use the following regex:
by Log Tag: (?!^BubblePopupHelper)(^.*$)
Have you added "OnGlobalLayoutListener"?
I've encountered same problem and finally I found that getViewTreeObserver().addOnGlobalLayoutListener caused the problem.
Here is my solution:
textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
...
textCategory.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});

Robotium ---> Instead of webview button, it clicks on edittext box

I'm pretty new with Appium. I tried robotium blackbox way with .apk file to fill up a small web-view form which is auto injected by other rails server and every thing is working fine for me but
When i tried to click on Save & Next button it clicks on the edit-text box in which my previous entry filed through script.
I used all the way
solo.waitForText("SaveAndNext");
solo.clickOnWebElement(By.id("SaveAndNext"));
solo.clickOnWebElement(By.name("Save & Next"));
solo.clickOnWebElement(By.textContent("Save & Next"));
But it click on the edittext box.
Here is my code :-
solo.waitForActivity("ViewQuestions");
getInstrumentation().waitForIdleSync();
solo.clickOnText("(?i).*?Yes.*");
solo.enterTextInWebElement(By.className("text_answer"), "2");
solo.hideSoftKeyboard();
solo.waitForText("SaveAndNext");
//solo.clickOnWebElement(By.id("SaveAndNext"));
//solo.clickOnWebElement(By.name("Save & Next"));
//solo.clickOnWebElement(By.textContent("Save & Next"));
for (WebElement webElement : solo.getCurrentWebElements()) {
Log.d("Robotium", "id: " + webElement.getId() + " textContent: "
+ webElement.getTagName());
if (webElement.getId() == "SaveAndNext") {
solo.clickOnWebElement(By.id("SaveAndNext"));
}
}
I have checked that if (webElement.getId() == "SaveAndNext") is found passed.
And in logcat
**Robotium id: SaveAndNext textContent: INPUT**
is shown.
Any help will be appreciate.
Remove this for loop and use just:
solo.clickOnWebElement(By.id("SaveAndNext"));
Btw you cannot compare Strings like:
webElement.getId() == "SaveAndNext"
You should rather use equals:
"SaveAndNext".equals(webElement.getId())
I had a similar problem with view clicks were not proper. Got this solution from robotium.org
Why do text and button clicks get wrong?
If this problem happens on one of the supported versions then try to add this tag to the test project's AndroidManifest.xml
uses-sdk android:targetSdkVersion="YOUR_VERSION"
Where YOUR_VERSION is 6 for Android 2.0, 7 for Android 2.1 and 8 for Android 2.2.
If that does not solve the problem then try to add this tag to the AndroidManifest.xml of the application you want to test:
supports-screens android:anyDensity="true"

jQuery change event not firing on mobile when inside a function

Specifically, I'm seeing this issue on an Android tablet, but I'm told it's with ALL mobile devices -- iPhones, Nexus tablets, etc.
But I have the common problem of change events not firing. Here's the function code that has the click events assigned:
function do_this(with_this_data)
{
var that = this;
this.with_this_data = with_this_data;
this.period = 900;
this.updateHours();
$('#date').change(function() {
that.updateHours();
});
$('#time_hour').change(function() {
that.updateMinutes();
});
// extra irrelevant data trimmed out
}
Now...one fix that should work is to move those .change() statements into a $(document).ready block -- but the problem is, if I do, then i get all sorts of undefined variable issues and stuff....all of the "update" functions are within said $(document).ready block and defined by names like "FutureStuff.prototype.updateMinutes."
What are my options???
Mifeet, again, I appreciate your feedback; I know you weren't able to fully get me up and running, but I'm still thankful.
But anyway, I solved the issue...it meant that basically I had to rewrite a new version of the JS code and stick it in an "if this chap is using a mobile browser" block. So yeah, one huge block of code for desktop users, another for mobile...but it works. :) And it was a pain in the hiney.

Spaces being converted to %20 in Android output

We have this Android code that is sending text to a collector:
public void sendHello() {
s.link = "None";
s.track("App Home Page - Hello all");
}
The output, though, contains %20 instead of spaces so we are ending up with something like this:
App%20Home%20Page%20-%20Helloall
Does anyone know how to prevent the spaces being converted or what is causing it?
As others have said, it'd be nice to know the type of s. But, as a shot in the dark, you could use URLDecoder's decode method.

Observe very long String content in Eclipse

Since LogCat truncates long strings, I work around this using FileOutputStream to inspect the contents of very long strings.
It works but it forces me to 'adb pull' that file, which is not very convenient, compare to watching it on LogCat.
Is there any other way in Eclipse to watch very long strings?
For the record, the answer was found here.
when you stop in debug on the variable
do the following and past it to a text file
I think it will be easier to use the eclipse debugging view.
Set a break point at the line where you call Log.* and run your app in debug mode.
When execution reaches the break point the app will ... yes, it will halt.
In the Variables window you may now browse your data and display whatever you need. Copy and paste it at a safe place as well and don't forget to smile :)
What I do, is in "Variables->Change value".
That will show you a Windows with the full text. Then just Copy&paste to notepad.
try this:
public void logLargeString(String str) {
if(str.length() > 3000) {
Log.i(TAG, str.substring(0, 3000));
logLargeString(str.substring(3000));
} else
Log.i(TAG, str);
}
}

Categories

Resources