0

My question is as follows: How can I locate the device model name, the reason is as follows. I am writing Java code for Appium, and would like to create a certain logic gate that deals with different model types that has test cases suited for each particular device's dimensions.

I tried reading different solutions, some involving Android figuring maybe they could offer some helpful pointers. However, this was not the case. System.getProperties().list(System.out); for example, which I hoped could provide me the solution needed, was not the answer either. Though I have expected as much.

I would use capabilities.getPlatform(); However, this is not valid since capabilities by default are null, and thus getPlatform() would simply return to me the name that I had to pass in manually. At this point, I am suspecting there may not be a way to do this in Java(?) I did find a code that was done in JavaScript, but it was for checking the type of phone that connected to the website (link: http://www.abeautifulsite.net/detecting-mobile-devices-with-javascript/)

Help is much appreciated. Below is my @BeforeTest method:

@BeforeTest
    public void setUp() throws FileNotFoundException, IOException, IllegalMonitorStateException
    {


        //File app = new File("/Users/first.last/Library/Developer/Xcode/DerivedData/iPhone-aowtfpozolcnpigbxzxxxxkyiubq/Build/Products/Debug-iphonesimulator/TheWeather.app");


        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "iOS");

        //8.4
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");
        //Iphone 6-(storytelling)-igor

        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Iphone 6-(storytelling)-name");

        //capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
        capabilities.setCapability("bundleID", "com.weather.TWC");
        //70cb6f4fd5e313b16742c083ccbc1897d82b094d
        capabilities.setCapability("udid", "70cb6f4fd5e313b16742c083ccbc1897d82b094d");

        driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
        driver = (IOSDriver) new Augmenter().augment(driver);
        System.out.println(capabilities.getCapability(MobileCapabilityType.DEVICE_NAME));
        logger.info("Environment: iOS 8.4 and iPhone 6 plus device");

    } 
SomeStudent
  • 2,856
  • 1
  • 22
  • 36

1 Answers1

0

I would use the parameters that get passed to desired capabilities.

But as I understand in your case this is not an option so I would suggest to launch instruments -s devices command from the code and parse its output matching the particular UDID. I know this is a "dirty" approach but I have not came across better options. Good luck!

  • Thank you for the reply, how would I go about incorporating this into the code as this seems to be like a command prompt string. – SomeStudent Jul 30 '15 at 23:19
  • Since you know the OS you can use this solution ["java runtime.getruntime() getting output from executing a command line program"](http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program) and adjust for your usage to parse resulting output. – Kristaps Mežavilks Jul 31 '15 at 09:29