title: Crossplatform appium code for iOS and Android platform
body: <p>I have written Appium code for Android platform and recently my organisation came with similar iOS app too.</p>
  
  <p>I am planning to use same code for both platform.</p>
  
  <p>I am successfully able to run the same code on both platform but organising code is getting difficult with every piece of code.</p>
  
  <p>Guide with an appropriate approach to achieve. </p>
  
  <p>My code on Android is running pretty good and same runs on iOS too.
  I have created two sets of capabilities like:</p>
  
  <p>Capabilities File:</p>
  
  <pre><code>protected static void initCapabilities() {
  getDirectory();
  //Android
  //deviceName = "33009a1eaa0b32a7";
  //DEVICE_NAME = "emulator-5554";
  //AUTOMATION_NAME = "uiautomator2";
  //PLATFORM_NAME = "Android";
  //BUILD = "app-internal-release - 628.apk";
  //app = new File(appDirectory, BUILD);
  //iOS
  PLATFORM_NAME = "iOS";
  PLATFORM_VERSION = "12.1";
  DEVICE_NAME = "iPhone XR";
  AUTOMATION_NAME = "XCUITest";
  BUILD = "Jiffle.app";
  
  app = new File(iOSAppDirectory, BUILD);
  System.out.println("Build picked is: "+app);
  }
  </code></pre>
  
  <p>Launch Code:</p>
  
  <pre><code>import org.openqa.selenium.By;
  import org.openqa.selenium.remote.DesiredCapabilities;
  import org.testng.annotations.AfterTest;
  import org.testng.annotations.BeforeTest;
  import org.testng.annotations.Test;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.concurrent.TimeUnit;
  
  import io.appium.java_client.AppiumDriver;
  import io.appium.java_client.MobileBy;
  import io.appium.java_client.MobileElement;
  import io.appium.java_client.android.AndroidDriver;
  
  import Utils.ValidationUtils;
  import Utils.LogUtils;
  import Global.Constants;
  import Global.SetDataInExcel;
  
  import TestbedDataLibrary.TestCases;
  
  import Access.Login;
  import EventList.EventListing;
  import MeetingList.MLElementRepositoryConstant;
  import BadgeScan.BadgeScan;
  import BookMeeting.RequestMeeting;
  import QuickDemo.QuickDemo;
  import io.appium.java_client.ios.IOSDriver;
  
  public class Launch extends Constants {
      private static AndroidDriver&lt;MobileElement&gt; androidDriver;
      private static IOSDriver&lt;MobileElement&gt; iosDriver;
  
      @BeforeTest
      private void setup() {
          initCapabilities();
          initAppData();
          DesiredCapabilities capabilities = new DesiredCapabilities();
          capabilities.setCapability("platformName", PLATFORM_NAME);
          capabilities.setCapability("platformVersion", PLATFORM_VERSION);
          capabilities.setCapability("deviceName", DEVICE_NAME);
          capabilities.setCapability("automationName", AUTOMATION_NAME);
          capabilities.setCapability("app", app.getAbsolutePath());
          try {
              System.out.println("Connecting to Appium Server...");
              if (PLATFORM_NAME.equals("Android")) {
                  System.out.println("Launching Android Driver...");
                  androidDriver = new AndroidDriver&lt;MobileElement&gt;(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
              }
              else if (PLATFORM_NAME.equals("iOS")) {
                  System.out.println("Launching iOS Driver...");
                  iosDriver = new IOSDriver&lt;MobileElement&gt;(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
              }
          } catch (MalformedURLException mle) {
              System.out.println("Caught exception in connecting to Appium Server!!!");
              mle.printStackTrace();
          }
  //        androidDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          iosDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }
  
      @Test(priority = 1)
      public void Login() throws Exception {
          System.out.println("Login Execution...");
          initTestBedData();
          long startTimeLogin = System.currentTimeMillis();
  
          iosDriver.switchTo().alert().accept();
  
          //Login.initLogin(androidDriver);
          Login.initLogin(iosDriver);
          SetDataInExcel.setTime(Constants.LoginTestBed, Constants.testSuiteSheet, startTimeLogin, "Login", 7);
      }
  </code></pre>
  
  <p>Please let me know if you need any other details.</p>
  
  <p>Issue: My main concern is that while passing driver <code>Login.initLogin(androidDriver);</code> , how should I decide which driver should I pass?
  Also, please suggest me some improvement here.</p>