I have a script to monitor the Notifications screen page.
I can open it via "Culebra" option "UiDevice" -> "Open Notifications".
The notifications error message from some apps have starting characters which are changing, only a constant pattern like "error for" is common but located at different position of the TextView error messages.
Therefore I can't use a regex with the method findViewWithText(regex) as it seems to use a regex match() instead of regex search(). Another solution for my problem is to use traverse() method with my own transform method which can do a regex search() of the view attribute text, but I can't figure out how to pass a parameter like a regex to my own transform method!?
This works for me to touch on a notification with text USB debugging connected:
vc.findViewWithTextOrRaise(re.compile('.*USB.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()
vc.sleep(_s)
notice this is a modified culebra script, that's why findViewWithTextOrRaise() is using the root argument to limit the search to the subtree which may not be needed in all cases, but it's safer to use.
It's worth to mention, that this works too
vc.findViewWithTextOrRaise(re.compile('.*debugging.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()
Related
I am trying to write UI tests for RTL language. Here is a scenario. I have an AutoCompleteTextView, on which when I try to tag a user ("#user"), it shows dropdown of suggested users. This works for RTL & LTR languages when I manually type the strings.
However, if I try to test using espresso the functionality it doesn't work as expected.
Here is how I am trying to write UI test :
Whenever I tell edit text to type “#u” using onView(withId(R.id.message_input_field)).perform(typeText("#u")), Espresso generates key events to inject the characters into edit text. Something like, KEY_DOWN_SHIFT, KEY_DOWN_2, KEY_UP_SHIFT, KEY_UP_2, this types “#” and so on. Everything works fine for English language.
Problem occurs when we try to tag using RTL characters, using something like onView(withId(R.id.message_input_field)).perform(typeText("#פ")). Espresso fails to recognize the RTL characters & can not generate key events, eventually throws java.lang.RuntimeException: Failed to get key events for string פ (i.e. current IME does not understand how to translate the string into key events)
I tried to do replaceText(…) instead of typeText(…) but replaceText in turn does editText.setText(…). but it doesn’t show the drop down. Weird.
How do I write UI test for this scenario?
P.S. It doesn’t matter what is your device language or what is you currently selected keyboard is.
All the questions are related to the demo project in android for pocketsphinx, given on the official site of CMUSphinx.
I don't understand what the method switchSearch() really does. The method is using KWS_SEARCH="wakeup" attribute, what is the use of this attribute? It doesn't appear in the grammar files (.gram). What is the purpose of this attribute? The method compares the searchName with KWS_SEARCH, I don't know why. The KWS_SEARCH it's also passed as a parameter to startListening() method on the recognizer object. Why?
I dont' understand how working with a timeout of 10000ms improves the result.
This is the switchSearch() method:
private void switchSearch(String searchName) {
recognizer.stop();
// If we are not spotting, start listening with timeout (10000 ms or 10 seconds).
if (searchName.equals(KWS_SEARCH))
recognizer.startListening(searchName);
else
recognizer.startListening(searchName, 10000);
String caption = getResources().getString(captions.get(searchName));
((TextView) findViewById(R.id.caption_text)).setText(caption);
}
From Pocketsphinx tutorial:
Developer can configure several “search” objects with different
grammars and language models and switch them in runtime to provide
interactive experience for the user.
There are different possible search modes:
keyword - efficiently looks for keyphrase and ignores other speech. allows to configure detection threshold.
grammar - recognizes speech according to JSGF grammar. Unlike keyphrase grammar search doesn't ignore words which are not in grammar
but tries to recognize them.
ngram/lm - recognizes natural speech with a language model.
allphone - recognizes phonemes with a phonetic language model. Each search has a name and can be referenced by a name, names are
application-specific. The function ps_set_search allows to activate
the search previously added by a name.
To add the search one needs to point to the grammar/language model
describing the search. The location of the grammar is specific to the
application. If only a simple recognition is required it is sufficient
to add a single search or just configure the required mode with
configuration options.
The exact design of a searches depends on your application. For
example, you might want to listen for activation keyword first and
once keyword is recognized switch to ngram search to recognize actual
command. Once you recognized the command you can switch to grammar
search to recognize the confirmation and then switch back to keyword
listening mode to wait for another command.
I don't understand what the method switchSearch() really does. The method is using KWS_SEARCH="wakeup" attribute, what is the use of this attribute?
"wakeup" is the search name of the keyword spotting search. It was added when recognizer was initialized. Name can be arbitrary, it just identifies the search.
The KWS_SEARCH it's also passed as a parameter to startListening() method on the recognizer object. Why?
startListening starts listening with the named search.
I dont' understand how working with a timeout of 10000ms improves the result.
It has nothing about result, it is just a user experience. When we spot for a word continuously, we do not need a timeout. When we recognize a command we wait for 10 seconds and then return back to spotting mode.
When running calabash-android and outputting to HTML format, I am getting intermittent exceptions as per the below (typically within the first step of the app). I am using Xamarin and MVVMCross libraries.
Timeout waiting for elements: * marked:'Terms of Use'
(Calabash::Android::WaitHelpers::WaitError)
./features/step_definitions/calabash_steps.rb:4:in `/^User has accepted the Terms of Use$/'
features\registration.feature:8:in `Given User has accepted the Terms of Use'
2
3Given /^User has accepted the Terms of Use$/ do
4 #current_page=page(TermsOfUse).await
5 #current_page.tap_accept_button
6end
7# gem install syntax to get syntax highlighting
The screenshots generated show the UI element is present on the screen, and the same errors never occur when I exclude the html format option and simply write the detail out to the console. Does anybody else have any experience of this?
Most likely the view's text has some formatting information in it.
It's a good practice to use id instead of text for identifying elements. If you have an id, use that:
query("* id:'terms_of_use_id'")
If you don't have an id try to add one.
If that is not possible try to query the whole UI with:
query("*")
Find the element and see what's in it's text property.
I am using MonkeyTalk to automate some user test cases for my Android app. Everything is working fine except for when I try and detect a button containing this string:
"Connect\n(Code Required)"
I get this error:
FAILURE: Unable to find Button(Connect\n(Code required))
If I change the button to "Connect" and perform a tap on that value MonkeyTalk has no trouble, but something about the line break must be throwing it off.
After some searching I found this thread that confirmed my suspicious about the line break. There was one suggested fix here, to set the default encoding to UTF-8 (Select the Project > File > Properties > Resources)
However this did not work for me.
I have also tried to find the button using a wildcard like so:
"*(Code Required)"
But this does not seem to be supported either.
Maybe there is an alternative line break character I could use?
Thanks in advance for the help!
Maybe there's a carriage return in there? I know in most text editors a new line actually consists of (carriage return)+(newline).
Also take a look at this:
TextView carriage return not working
Also, depending on how flexible your requirements are, you could use the #N MonkeyId replacement to get the Nth button.
IN javascript you can use below command
app.button("buttonname").tap(x, y);
Use android:contentDesxription="your_component_id" in your view xml file definition or view.setContentDescription("your_component_id"); directly on view in code to make it easy to access in MonkeyTalk.
Clicked on create filter could not figure out from docs how to create a filter for say two or more tags. If I have two tags com.test.TestClassA and com.test.TestClassB how do I create a filter that shows log for both of these classes? I saw how you can start ADB for only certain tags, but how can this be done in eclipse? Please provide details thanks. What exactly do I need to enter on the tag line when creating a new filter in eclipse?
As pointed by Brain Reinhold you can combine tag filters with vertical bar | (which obviously means logical "OR"). You can also use that (as well as other Regex) syntax in the logcat search box (by preceding tags with tag: prefix):
tag:com.test.TestClassA|com.test.TestClassB
More complex filtering is also possible. For example here is the search filter that displays messages from either android.process.media or com.android.camera apps, which have at least one digit (\d) in the message text and are tagged with either dalvikvm or AndroidRuntime tags:
app:android.process.media|com.android.camera tag:dalvikvm|AndroidRuntime text:\d
One short and useful filter is tag:^(?!dalvikvm) which removes all those noisy Dalvik logs.
It's also worth mentioning that you can quickly disable any part of the filter by placing vertical bar at the end of the part you wish to disable (e.g. placing | right after app:android.process.media|com.android.camera in the example above effectively disables filtering by application name while still preserving filtering by tags and text).
In the latest version of the SDK for Eclipse which now shows two versions for logcat (one deprecated); in the undeprecated version one can combine filters using OR bars: |.
For example when clicking on the + and bringing up a dialog to create a new filter, give your filter a name and then in one of the fields (for example TAG) enter com.lampreynetworks|Bluetooth and you will see output for all tags containing com.lampreynetworks and Bluetooth. The '*' is implicit here as if any part of the TAG contains any of that text it will be displayed. Also note, there must be no spaces between the OR bars!
I have not tried combining the 'by TAG' and 'by (some other option)' but somehow I have a feeling that will not work.
On Feb 12, 2:58 am, AndroidDevTime wrote:
If I have two tags
com.test.TestClassA and com.test.TestClassB how do I create a filter
that shows log for both of these classes?
The "Log tag" field accepts Java regular expressions, so do this:
^com.test.TestClassA$|^com.test.TestClassB$
which matches exactly those tags you specified. You could be more economical/efficient/whatever with the regular expression, depending on how much you want to muck around with that.
It is not possible right now.
#see http://groups.google.com/group/android-developers/browse_thread/thread/17356ef7bdf1550f?pli=1
I also wish it were...
I just do it from the command line. Having a different terminal for each adb filter. Then if you line them up side by side you can get a good idea of what is happening.
The only way I have seen is Create a Filter using PID so that evey log message of your application will be displayed in that Filter. I wonder if this is possible through tag names in the current version of the ADT for eclipse.
Use proclogcat: http://devtcg.blogspot.com/2010/04/logcat-improved.html
It lets you filter by your package name instead.