I'm currently trying to get Espresso to match a UIElement by it's class and its text since it currently does not have a resource ID (I know, I know...). I'm not sure what the proper syntax for this is since the Espresso documentation is fuzzy (I'm VERY new to this and programming in general so I'm sure I'm missing something). Here's what I have so far:
onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
I've tried typing just "Textbox" but in both cases I get an "Expression Expected" error. As of now this is the only way to identify this element so any pointers will help. Thanks!
Here' s my example:
onView(allOf(instanceOf(Toolbar.class), withChild(withText(R.string.action_settings))))
.check(matches(isDisplayed()));
so I guess that in your test would be
onView(allOf(instanceOf(android.widget.CheckBox.class)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
Hope it will help
Related
enter image description here
When I try to create a new class in the library of flutter, inside the class the constructor shows error
The problem is that you have your parameters as optionally named, which means the caller can decide not to pass q or a, but you also marked them as non-nullable. Add the required keyword before your parameters to make sure they're passed in and are non-null, or add a default.
Also, in the future:
Please copy-paste your code instead of using an image. This lets us quickly copy-paste it into our IDEs and find any errors.
Please post the error you're getting. Errors are your friends, they tell you what's wrong, and they'll help us figure out how to help you.
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 have this simple Espresso interaction:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())))
.perform(typeText("1"));
The check(matches(allOf(isDisplayed(), isEnabled()))) passes as expected, but the following perform(typeText("1")) does not. I cannot figure out why, for the life of me.
So, I can't believe I'm asking this, but how in the name of Android do I use Espresso to type text into my EditText whose ID is R.id.editTextTextWidget?
I fixed the problem by splitting the check(...) call and perform(...) call:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())));
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.perform(typeText("1"));
For some reason this works, and the original doesn't. #GooglePlz
I'm new to automatization, Android, Selenium, Appium and xpath, too. I know it's suck a great beggining.
I write tests for Android devices, but the application I have to test have a lot of costum views. I found out the best way to interact with these custom items is to put an "android:contentDescription" field in the Views. My only question is how to get access to the element with have a specified contentDescription? This is az android specific question, I'm not even sure that the content-desc is the field I'm looking for.
I have the hierarchy provided by Android UI Animator Viewer:
http://i.imgur.com/NUGc56o.png
The ways i've tried:
xpath: //*[contains(#android:contentDescription,'example text')]
I was able to get access by finding them as an ImageView, but as I mentioned I need to work with custom Views
My code looks like somtihng like this:
driver.findElementByXPath("//*[constains(#content-desc,'Login')]").click();
Thanks for the help!
You could also try using Accessibility labels or the UIAutomator locator strategy.
Here's Appium's documentation on those.
Your xpath is incorrect. It should be: "//android.widget.ImageView[#content-desc='Login']"
Here's some pseudocode of what you should do:
login_image = driver.findElementByXPath("//android.widget.ImageView[#content-desc='Login']"); // Gets you the WebElement
print login_image.getClass(); // Just for debugging, make sure it's not nil/null
login_image.click(); // Click on it!
I'm attempting to create an Activity and unfortunately every time I want to grab one of my XML components it gives me a RunTimeException (NullPointer).
Anytime I use code such as:
TextView tv = (TextView) findViewById(R.id.myView); //I get the exception
The same happens for any components I attempt to find with that method. I can't quite figure out why. I know it isn't due to the Activity not being in the Manifest because it's the only Activity in the test app I made. (The one set up by default).
Oddly I can still use setContentView(R.id.myView). It just doesn't seem to want to find anything when using the findViewById method.
Info that might be of use:
I am currently using NetBeans as my IDE.
I have done multiple 'clean and builds' as was suggested in another question. Android -findViewById question
Has anyone run into this issue before? If so, what was the solution?
If need be, I can provide sample code of when this is happening.
Don't pass in a view ID to setContentView, pass in a layout resource ID:
setContentView(R.layout.layout_name);
If you still have problems, post your layout file.
It is very sure that you R.java is not properly generated.
Delete R.Java in netbeans IDE and Re-build the project.
Hope it resolves your query.