After searching these forums, i failed to find an answer so I guess I’ll ask it here.
I am writing test scripts in java using the Android/iOS driver. (maybe I should use AppiumDriver)?
I have a native application on iOS and Android. I would like to implement something along the lines of
Pseudo code
if AndroidTest
return driver.findElementsByName(“blahblah”)
else
driver.findElementByXpath("//xpath[1]")
Is there anyway I can solve this?
I was thinking about using the page factory annotations for @AndroidFindBy and so on, but im not 100% sure on those.
@AndroidFindBy and @iOSFindBy is the correct way. You can combine them together:
@AndroidFindBy(“the relevant locator strategy for Android”) //this strategy will be used when Android is here @iOSFindBy(“relevant locator strategy for iOS”) //this strategy will be used when iOS is here
MobileElement yourElement.
AndroidDriver and iOSDriver both extend AppiumDriver. So you can use parameterized tests:
//it is parameterized test
public class AppiumJUnitTest{
//this is set up by given parameters before test is started
private AppiumDriver driver;
@Test
public void test() throws Exception{
//code which works agains Android and iOS
}
Awesome, this is exactly what I was thinking to use.
I don’t understand though if an elements has 1 strategy for iOS and one for Android, how does it know which one to look? how does it detect when we are on Android and when we are in iOS?
I have this issue where I use 2 widget classes in a PO class, one widget is defined only with @AndroidFindBy location strategy and one is defined only with iOSFindBy strategy. From the server logs (when running on iOS device) I see that the Android widgets are searched also by the name of the variable defined in the PO class, which is weird.
Which client version do you use? There had been bugs which were fixed at 3.0.0, 3.1.0, 3.2.0. Also can you provide client (Java) code samples and server output as gists?
I am using latest java client 3.3.0. The strange thing is that I just noticed it happens when I am in debug mode in my IDE (intelliJ) - does this sound logical in any way ?