Programatically pass Device Platform version and OS version to appium

Currently, I am maintaining two different test suites for both iOS and Android.

Currently,
If I want to run the tests in android with different device versions, I go manually to appium and select/change device version and start the server
If I want to run a test in iOS instead of android, I go to appium and change it to iOS and start running the iOS tests. So we have two different branches in Jenkins that runs iOS and Android tests respectively.

I wanted to know, if

  1. I can pass device version to appium programatically? That is, if 6.0 is connected, appium should recognize the version and if 7.0 is connected, it should be recognized too, than me going and manually changing it in the appium. I am currently using

    deviceInfo_Hash = {
    “PLATFORM” => “Android”,
    “DEVICE_VERSION” => system(‘adb shell getprop | grep build.version.release’),
    “DEVICE_MODEL” => system(‘adb devices -l’),
    “APP_VERSION” => system(‘adb shell dumpsys package my.package | grep versionName’),
    }

to get the details of the device and store it in a file. Is there a way to pass these information to the appium?

  1. Is there a way, to tell appium, whether the connected device is android or iOS? i.e. if android is connected, run the android steps and if iOS then run the iOS test steps, instead of manually going and changing the values in the appium? Currently, I am using,

     Before do
       if  $driver.device_is_android?
         puts "Device connected is Android"
       end
     end
    

to see if the connected device is android? Now, is there a way to tell appium, in the else command, that if it is iOS then how do I start the iOS server in the appium? Do we need to have two different env.rb for both iOS and Android?

Kindly let me know if any details are further needed.

I have updated the env.rb to this, and currently it seems to recognize whats my device version and proceeds, but I get the installation error in the NOUGAT version of android.

def caps
  {
      caps:{ deviceName: "Samsung",
             platformName: "Android",
             Fullreset: "false",
             Noreset: "true",
             Platformversion: system('adb shell getprop | grep build.version.release'),
             app: (File.join(File.dirname(__FILE__), "app-fs-debug.apk")),
             Packagename: "br.com.fs.ensinabyfs",
             newCommandTimeout: "3600",
             autoGrantPermissions: "true",
             appium_lib: { wait: 20,
                           debug: false,
             }
      }
  }

end