I have 2 native apps(not hybrid or react native), they share same design, one is for Android(JAVA) and the other is for IOS(OC). Now I need to make some test for these 2 apps. I am trying to do this with Appium.
Appium provide lots of methods to find a element. To write a test case for both app, it seems I can use AccessibilityId
. If I ask developer to add same AccessibilityId
to both android and ios project, then I can make the same test code work with both apps. Does this the best practice? This may bring lots of effort to both android and ios develop team to add AccessibilityId
s
Yes, the use of accessibility IDs is the preferred method. It is not necessary for the IDs to match across platforms.
You can define these elements with FindBy tags in your class definition as follows:
@iOSFindBy(id = "send_button")
@AndroidFindBy(id = "SEND")
private MobileElement sendButton;
Your action code would then be:
sendButton.click()
More information on these tags and related ones can be found at the PageFactory library docs.
If your IDs did match you could perform your action inline (example below), but I generally prefer to define my elements outside my methods.
driver.findElementById("send_button");
Everything above can be performed with xpaths as well as other attributes mentioned in the docs.