To automate mobile applications I use the Factory design pattern. The set of methods for iOS and Android is the same, but the elements are declared differently. How to avoid duplicate code?
Here is a simplified example:
public interface FormHelper { void close(); } public class AndroidForm implements FormHelper { private Button btnClose = new Button("//a[text()='Close']"); @Override public void close() { btnClose.click(); } } public class IOSForm implements FormHelper { private Button btnClose = new Button("//div[@id='close']"); @Override public void close() { btnClose.click(); } } public class FormFactory { public static FormHelper getForm(){ if (x > 0) { return new AndroidForm(); } else { return new IOSForm(); } }