How to run one script against both platforms android/IOS

im able to run test against each platform separately, but wanted to utilize the script so i can write one script in page object model that can be executed from both platform android/ios
whatever what device is connected appium will recognize it and execute the relative driver instance

how i will set desired cap to work for both platforms

how i will set page element factory

how will write the element for both platforms
or if anyone has a ready code sample

here is sample of my code

public class BaseSetup {

public static AppiumDriver driver = null;
private Logger logger;

@BeforeSuite(alwaysRun = true)
public void setUp () throws MalformedURLException {
    System.out.println("Driver Is Initiated");
    DesiredCapabilities dc = new DesiredCapabilities();

    //Mobile Config Setup
    dc.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");

// dc.setCapability(MobileCapabilityType.AUTO_WEBVIEW,true);

    //Application Config Setup
            new File("src/main/resources/Safe.apk").getAbsolutePath());

    driver = new AppiumDriver<MobileElement> (new URL("http://localhost:4723/wd/hub"),dc);


public class AndroidDecorator extends BaseSetup {

protected WebDriverWait wait;
public AndroidDecorator(AppiumDriver<MobileElement> driver) {
    this.driver = driver;
    wait = new WebDriverWait(driver, 15);
    PageFactory.initElements(new AppiumFieldDecorator(driver),this);


public class LoginPage extends AndroidDecorator {

public LoginPage() {

private void context(String native_app) {

@AndroidFindBy(xpath = "//android.view.View[@text='Welcome to SAFE!']")
private MobileElement welcomeHeader;

   public void welcome_header_is_visible() {

public class LoginTest extends BaseSetup {

@Test(priority = 1)
public void Verify_login_page_is_loaded_properly () {
    LoginPage page = new LoginPage();

do you have any code sample maybe

it is not clear what problem you have. e.g. Page element working for both:

    @AndroidFindBys(value = {
            @AndroidBy(id = "tv_first_name"),
            @AndroidBy(className = "android.widget.EditText")
    @iOSXCUITFindBys(value = {
            @iOSXCUITBy(id = "firstName"),
            @iOSXCUITBy(className = "XCUIElementTypeTextField")
    private MobileElement firstNameInput;

what about the desired capability how i will make appium select the relative driver based on the connected device (android or IOS)

Well e.g. i use testNG and there i use parameters for setting phones to test. In code i am getting them and open either iOSdriver or AndroidDriver.

so you are passing the parameters to your capabilities, using two testNg xml files

Yes. Also this parameter can be sent via command line like -DparameterName=value

awesome thanks i will try this.