I'm writing automated tests for my company's app. The tests use a combination of Espresso and Robotium. Several of those tests are supposed to check whether certain ReactImageView elements are displaying a specific image.
I first tried using hasBackground() as follows:
onView(...).check(matches(hasBackground(R.drawable...)));
However, this returns a NoMatchingViewException.
I then tried Daniele Bottillo's matcher as described here: https://medium.com/#dbottillo/android-ui-test-espresso-matcher-for-imageview-1a28c832626f
onView(allOf(..., new DrawableMatcher(R.drawable....), isDisplayed())).check(matches(isDisplayed()));
But this didn't work either:
java.lang.ClassCastException: com.facebook.drawee.generic.RootDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
Lastly, I tried Frankie Sardo's solution: Android Espresso match BitmapDrawables with different tint
onView(allOf(..., withImageDrawable(R.drawable...), isDisplayed())).check(matches(isDisplayed()));
However, this again throws a NoMatchingViewException. I'm running out of ideas. Is it even possible to check what resource is attached to an image view?
The easiest way would be to use Barista library and its assertHasDrawable(R.id.<imageview_id>, R.drawable.<drawable_id>) assertion function.
I am trying to develop an application that requires the ability to capture screen content. I'm targeting lollipop to avoid the requirement for root. When trying to get an instance of the MediaProjectionManager via a call to getSystemService() I am getting the following error reported in Android Studio:
Must be one of: Context.POWER_SERVICE, Context.WINDOW_SERVICE, Context.LAYOUT_INFLATER_SERVICE, Context.ACCOUNT_SERVICE, Context.ACTIVITY_SERVICE, Context.ALARM_SERVICE, Context.NOTIFICATION_SERVICE, Context.ACCESSIBILITY_SERVICE, Context.CAPTIONING_SERVICE, Context.KEYGUARD_SERVICE, Context.LOCATION_SERVICE, Context.SEARCH_SERVICE, Context.SENSOR_SERVICE, Context.STORAGE_SERVICE, Context.WALLPAPER_SERVICE, Context.VIBRATOR_SERVICE, Context.CONNECTIVITY_SERVICE, Context.WIFI_SERVICE, Context.WIFI_P2P_SERVICE, Context.NSD_SERVICE, Context.AUDIO_SERVICE, Context.MEDIA_ROUTER_SERVICE, Context.TELEPHONY_SERVICE, Context.CLIPBOARD_SERVICE, Context.INPUT_METHOD_SERVICE, Context.TEXT_SERVICES_MANAGER_SERVICE, Context.DROPBOX_SERVICE, Context.DEVICE_POLICY_SERVICE, Context.UI_MODE_SERVICE, Context.DOWNLOAD_SERVICE, Context.NFC_SERVICE, Context.BLUETOOTH_SERVICE, Context.USB_SERVICE, Context.INPUT_SERVICE, Context.DISPLAY_SERVICE, Context.USER_SERVICE, Context.PRINT_SERVICE less... (Ctrl+F1)
Reports two types of problems:
* Supplying the wrong type of resource identifier. For example, when calling Resources.getString(int id), you should be passing R.string.something, not R.drawable.something.
* Passing the wrong constant to a method which expects one of a specific set of constants. For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.
I am currently at a loss as to why this constant is not considered valid, it's there as an autocomplete option, so it's present, and it's shown in all sample code I have seen for screen capture in lollipop. I have verified that the project setup specifies Android SDK 21 as min and target. Is there something else obvious/stupid I might be missing that would cause this error?
UPDATE: Took the exact same code to Eclipse and it works without issue. So this is related to something in Android Studio specifically it seems.
I get this error while getting Context.BLUETOOTH_SERVICEand the error doc (Must be one of..) contains Context.BLUETOOTH_SERVICE though.
This is not the way Android Studio "1.2" should work. :#
Anyway, its an Inspection bug, Constant and Resource Type mismatch (How in the hell Bluetooth is a resource in android context).
You can suppress this for Class/Method/Statement, for statement, add #SuppressWarnings("ResourceType") above or before the statement.
Another approach:
Goto Settings>>Editor>>Inspection>>Android>>Constant and Resource Type Mismatches and make the severity to anything but Error, probably Warning or Weak Warning.
(Though it fixes the error issue, but I want this mismatch to be an error when it really happens.)
Run into the same problem, it is so strange, there are no any other threads talking about this problem.
Well, actually you can just ignore this error and still run the program, even with
the red marks on it
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'm trying to use my method from java backend in android app (the problem might be that the backend is using JAVA 1.7, and the android app JAVA 1.6). The method is:
public static boolean isAlphabetCharacter(String letter) {
String pattern = "\\A\\pL+\\z";
return letter.matches(pattern);
}
It crashes with: Incorrect Unicode property near index ...
You should try \p{L} instead of \pL :)
It is Weird. When developing Android app, i encounter this problem.
Unit test is passed when i use Regex("[\\pP\\pZ]"), but Android app encounter java.util.regex.PatternSyntaxException: Incorrect Unicode property
then i change to Regex("[\\p{P}\\p{Z}]"), both unit test and android app is ok.
I dont know why....
In my Android app I'm creating new WebViews from Java code; however after I create these WebViews my previously working id's get overwritten.
Example snippet:
for (int i=0;i<mywebviewarray.length;i++){
mywebviewarray[i]=new WebView();
}
((Button)findViewById(R.id.mybutton).settext("ok");
If I run this code, I get an exception on the last line:
java.lang.ClassCastException: android.webkit.WebView
It seems to me as if the tables backing the findViewById get overwritten. I tried calling setId in the loop. but it does not help.
How can I resolve this problem?
What is in mywebviewarray. It seems to me like you have something in there that isnt a WebView and you are trying to instantiate it as a WebView.
I ended up not solving this problem, and instead of using a dynamic array of WebViews, I ended up using fixed 3 WebViews. I'm changing their content like a 3-length window over an array of URLs, thus simulating the original concept. (Albeit in a slower way)