appium

Set parameters to launch app

To create a script to run iOS test using Ruby, we need to create a script first. Let's call it "ios.rb".

In the file, we need to import the libraries at beginning:

require 'rubygems'
require 'appium_lib'

As we are going to test the app "UICatalog.app.zip" under folder "~/Documents/appium-master/sample-code/examples/ruby", so we need to define the parameters for appium to launch it.

APP_PATH = '~/Documents/appium-master/sample-code/examples/ruby/UICatalog.app.zip'

desired_caps = {
  caps:       {
    platformName:  'iOS',
    versionNumber: '7.1',
    app:           APP_PATH,
  },
  appium_lib: {
    sauce_username:   nil, # don't run on Sauce
    sauce_access_key: nil
  }
}

Next, we need to initial a driver with the parameters we just set, in the Selenium-WebDriver way.

Appium::Driver.new(desired_caps).start_driver

And we also need to load the appium own methods:

Appium.promote_appium_methods self.class

After this, the script should looks like following:

require 'rubygems'
require 'appium_lib'

APP_PATH = '~/Documents/appium-master/sample-code/examples/ruby/UICatalog.app.zip'

desired_caps = {
  caps:       {
    platformName:  'iOS',
    versionNumber: '7.1',
    app:           APP_PATH,
  },
  appium_lib: {
    sauce_username:   nil, # don't run on Sauce
    sauce_access_key: nil
  }
}

Appium::Driver.new(desired_caps).start_driver
Appium.promote_appium_methods self.class

Alt text

Now, we can run ruby ios.rb successfully; the script will launch the app.

Alt text