Skip to main content

Ruby

Continuous Testing Cloud lets you execute Appium tests written in Ruby on remotely located devices. These include existing Appium tests written in Ruby that you have been running locally.

Use our sample tests in our git repository by cloning them, or use the sample tests below. 

info

Replace <server> with the appropriate URL.

Android App Test with Ruby Expand source

require 'test/unit'
require 'appium_lib'

class TestYourAndroidApp < Test::Unit::TestCase
def setup
desired_caps = {
caps: {
accessKey: ENV['SEETEST_IO_ACCESS_KEY'],
platformName: 'android',
testName: 'Android App test with Ruby',
app: 'http://d242m5chux1g9j.cloudfront.net/eribank.apk',
appPackage: 'com.experitest.ExperiBank',
appActivity: '.LoginActivity'
},
appium_lib: {
server_url: '<server>',
}
}
@driver = Appium::Driver.new(desired_caps).start_driver
end

def test_android_app
@driver.find_element(:xpath, "//*[@id='usernameTextField']").send_keys 'company'
@driver.find_element(:xpath, "//*[@id='passwordTextField']").send_keys 'company'
@driver.find_element(:xpath, "//*[@id='loginButton']").click
@driver.find_element(:xpath, "//*[@id='makePaymentButton']").click
@driver.find_element(:xpath, "//*[@id='phoneTextField']").send_keys '123456'
@driver.find_element(:xpath, "//*[@id='nameTextField']").send_keys 'Test'
@driver.find_element(:xpath, "//*[@id='amountTextField']").send_keys '5'
@driver.find_element(:xpath, "//*[@id='countryTextField']").send_keys 'US'
@driver.find_element(:xpath, "//*[@id='sendPaymentButton']").click
@driver.find_element(:xpath, "//*[@id='button1']").click
end

def teardown
puts @driver.capabilities['reportUrl']
@driver.quit
end
end

IOS App Test with Ruby Expand source

require 'test/unit'
require 'appium_lib'

class TestYouriOSApp < Test::Unit::TestCase
def setup
desired_caps = {
caps: {
accessKey: ENV['SEETEST_IO_ACCESS_KEY'],
platformName: 'ios',
testName: 'iOS App Test with Ruby',
app: 'http://d242m5chux1g9j.cloudfront.net/EriBank.ipa',
autoDismissAlerts: true,
bundleId: 'com.experitest.ExperiBank',
},
appium_lib: {
server_url: '<server>',
}
}
@driver = Appium::Driver.new(desired_caps, true).start_driver

end

def test_ios_app
@driver.find_element(:xpath, "//*[@text='Username']").send_keys 'company'
@driver.find_element(:xpath, "//*[@text='Password']").send_keys 'company'
@driver.find_element(:xpath, "//*[@text='loginButton']").click
@driver.find_element(:xpath, "//*[@text='makePaymentButton']").click
@driver.find_element(:xpath, "//*[@text='Phone']").send_keys '123456'
@driver.find_element(:xpath, "//*[@text='Name']").send_keys 'Test'
@driver.find_element(:xpath, "//*[@text='Amount']").send_keys '5'
@driver.find_element(:xpath, "//*[@text='Country']").send_keys 'US'
@driver.find_element(:xpath, "//*[@text='sendPaymentButton']").click
@driver.find_element(:xpath, "//*[@text='Yes']").click
end

def teardown
puts @driver.capabilities['reportUrl']
@driver.quit
end
end

Chrome on Android Test with Ruby Expand source

require 'test/unit'
require 'appium_lib'

class TestYourWebAppAndroid < Test::Unit::TestCase
def setup
desired_caps = {
caps: {
accessKey: ENV['SEETEST_IO_ACCESS_KEY'],
platformName: 'android',
testName: 'Android Web Test with Ruby',
browserName: 'chrome',

},
appium_lib: {
server_url: '<server>',
}
}
@driver = Appium::Driver.new(desired_caps, true).start_driver
end

def test_android_web
@driver.get('https://amazon.com')
if @driver.capabilities['device.category'].eql? 'TABLET'
@driver.find_element(:xpath, "//*[@name='field-keywords']").send_keys 'mobile autoamtion testing'
search_btn = @driver.find_element(:xpath, "//*[@text='Go']")
else
@driver.find_element(:xpath, "//*[@name='k']").send_keys 'mobile autoamtion testing'
search_btn = @driver.find_element(:xpath, "//*[@value='Go']")
end

search_btn.click
end

def teardown
puts @driver.capabilities['reportUrl']
@driver.quit
end
end

Safari on IOS Test with Ruby Expand source

ios_web_test.rb (source from Ruby Sample)require 'test/unit'
require 'appium_lib'

class TestYourWebAppiOS < Test::Unit::TestCase
def setup
desired_caps = {
caps: {
accessKey: ENV['SEETEST_IO_ACCESS_KEY'],
platformName: 'ios',
testName: 'iOS Web Test with Ruby',
autoDismissAlerts: true,
browserName: 'safari',

},
appium_lib: {
server_url: '<server>',
}
}
@driver = Appium::Driver.new(desired_caps, true).start_driver
end

def test_ios_web
@driver.get('https://amazon.com')
if @driver.capabilities['device.category'].eql? 'TABLET'
@driver.find_element(:xpath, "//*[@name='field-keywords']").send_keys 'mobile autoamtion testing'
search_btn = @driver.find_element(:xpath, "//*[@text='Go']")
else
@driver.find_element(:xpath, "//*[@name='k']").send_keys 'mobile autoamtion testing'
search_btn = @driver.find_element(:xpath, "//*[@value='Go']")
end
end

def teardown
puts @driver.capabilities['reportUrl']
@driver.quit
end
end






Prerequisites

  • Ruby

  • Appium for Ruby

    gem install appium_lib
  • Ruby IDE, or other code editor (atom is recommended) and then run your tests from the command line. 

Getting Started

To get started, clone the sample tests from thegit repository and start testing. 

If you use a general purpose code editor, then to run the tests:

  1. Open a command prompt or shell.
  2. Navigate to the folder where the project is located.
  3. Run this command:
ruby testfile.rb