I have an Android app where some pages are developed with JetPack Compose.
My dev said that are added (Modifier.semantics { testTagsAsResourceId = true }
I found that I need to add new dependencies:
implementation ‘androidx.compose.ui:ui:1.3.0’
implementation ‘androidx.compose.ui:ui-tooling:1.3.0’
implementation ‘androidx.test.ext:junit:1.1.3’
implementation ‘androidx.test.espresso:espresso-core:3.5.1’
implementation ‘androidx.test.espresso:espresso-contrib:3.5.1’
but I still have a problem with - Cannot resolve symbol 'androidx and with this - import androidx.compose.ui.test.junit5.AndroidComposeTestRule;
But I’m using Appim driver so do I need espresso?
but even after adding everything I cant use ids in this way:
And from the log i can see that i dont see my “pricesDropDownIcon” button - but I can see some numbers like - “ELEMENT”:“00000000-0000-027d-ffff-ffff00000081”. So does it mean that the problem on the dev side?
You wrote about “pricesDropDownIcon” while in logs no such search attempt. Now you switch to “toolbarBackButton”. While in your code you writing wrong syntax that will not execute.
As far as I understood the problem is - I don’t see id - pricesDropDownIcon after System.out.println(AppiumInit.getAppiumDriver().getPageSource());
Am I right? But how is to possible if I can see it in inspector?
I use appium to test an app written in jetpack compose. Like you I had to get my devs to add TestTag and to set testTagsAsResourceId = true.
This worked and I could now see the resource ids in Appium Inspector. However many times I was still unable to get the element by ID using UIAutomator and the .NET appium client. As a workaround I get android elements by XPath using something like
//*[@resource-id="pricesDropDownIcon"]
This works and is reliable and stable. I’m not sure if there are performance implications though.
Since I use .NET my syntax will not be the same as yours, but I found that I can get by ID id I use the following syntax:
Driver.FindElement("id", "my-element")
But it doesn’t work if I use
Driver.FindElement(By.Id("my-element"))
I think there is a bug there. I thought it was in the .NET client but maybe not after seeing your issue. Anyway, for the most part I use the attributes on the Page Object to find my elements like you do. This does not work to get Id so it ends up looking something like this:
[FindsBy(How = How.XPath, Using = "//*[@resource-id='pricesDropDownIcon']")]
private IWebElement dropDownButton;
That’s .Net code but I’m sure you can easily convert to Java
one quick question - can i use System.out.println(AppiumInit.getAppiumDriver().getPageSource()); for checking the native part? cause as far as I found in google - this method only for webview context?