2

I have an Automation framework running on a Mac which has Appium and Xcode installed. I want to run my test cases in multiple simulators at a time. How can I open more than one simulator on the same machine?

nc.
  • 7,179
  • 5
  • 28
  • 38
Sandra
  • 105
  • 1
  • 11

2 Answers2

1

According to Appium documentation, it is not possible for one machine (http://appium.io/slate/en/master/?csharp#appium-platform-support). Most likely because Apple Instruments only allows one device to be controlled at a time.

However, if you have a Selenium Grid, it is possible. You can find those instructions here: http://appium.readthedocs.org/en/stable/en/advanced-concepts/grid/ This requires using multiple OS X machines as nodes.

econoMichael
  • 657
  • 3
  • 13
0

Since Xcode 9 and Appium 1.7, this is now possible. The key is the wdaLocalPort capability. Each simulator needs its own port.

Here's an example, I use ruby, but it will be similar in other languages as well:

require 'appium_lib'

opts = {
  caps: {
    automationName: 'XCUITest',
    platformName: 'iOS',
    deviceName: 'iPhone 7',
    wdaLocalPort: 8001,
    app: 'Example.app',
  },
}

10.times do
  driver = Appium::Driver.new(opts, true)
  driver.start_driver.manage.timeouts.implicit_wait = 10
  driver.find_element(:name, 'Button').click
  driver.driver_quit
end

I couldn't be bothered to implement the concurrency, so you'll have to manually execute the next script at the same time as the first one.

require 'appium_lib'

opts = {
  caps: {
    automationName: 'XCUITest',
    platformName: 'iOS',
    deviceName: 'iPhone 8',
    wdaLocalPort: 8002,
    app: 'Example.app',
  },
}

10.times do
  driver = Appium::Driver.new(opts, true)
  driver.start_driver.manage.timeouts.implicit_wait = 10
  driver.find_element(:name, 'Button').click
  driver.driver_quit
end

I haven't played with this too much, but when I used two simulators, I ran twice the amount of tests in the same time. Would be interesting to see how well it scales.


EDIT: Turns out that I could be bothered to implement the concurrency:

require 'appium_lib'

device_names = [
  'iPhone 6',
  'iPhone 6s',
  'iPhone 7',
  'iPhone 8',
]

def test(device_name, port)
  opts = {
    caps: {
      automationName: 'XCUITest',
      platformName: 'iOS',
      deviceName: device_name,
      wdaLocalPort: port,
      app: 'Example.app',
    },
  }
  driver = Appium::Driver.new(opts, true)
  driver.start_driver.manage.timeouts.implicit_wait = 10
  driver.find_element(:name, 'Button').click
  driver.driver_quit
end

device_names.each_with_index do |device_name, i|
  fork {
    10.times do
      test(device_name, 8000+i)
    end
  }
end

Process.waitall

The above will launch as many simulators as you specify in the device_names array and run 10 tests on each of them. I also wrote a more complicated script for benchmarking. Between 3 and 4 simulators I had less than a 10% increase in performance, so running more than 4 doesn't seem worth while, but I suppose that depends on your system.

As you launch more and more simulators, you will likely run out of system resources. Here's how you deal with that: https://stackoverflow.com/a/46819409/310121

Erik B
  • 40,889
  • 25
  • 119
  • 135