Skip to content

Commit

Permalink
Add parallel android tests (#156)
Browse files Browse the repository at this point in the history
* separate test cases which depends on other libraries

* remove comments

* add android parallel tests

* add generating android emulators to make paralell running easy

* add comments
  • Loading branch information
KazuCocoa authored Oct 29, 2018
1 parent 72a1827 commit 10558f2
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 9 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ $ rake test:func:ios # iOS
```

#### Run parallel tests with parallel_tests gem
#### Android

```
# Generate 3 emulators. Running 3 emulators require much machine power.
# It requires an image which is for Google Play and x86 CPU architecture's image.
$ bundle exec rake android:gen_device
$ PARALLEL=1 bundle exec parallel_test test/functional/android -n 3
```

##### iOS
- Create iPhone simulators named `iPhone 8 - 8100` and `iPhone 8 - 8101`
- Run iOS functional tests with below command

```
PARALLEL=1 bundle exec parallel_test test/functional/ios -n 2
$ PARALLEL=1 bundle exec parallel_test test/functional/ios -n 2
```

## Run a test case
Expand Down
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ namespace :test do
end
end

namespace :android do
desc('Generate and launch android emulators')
task :gen_device do |_t, _args|
SWARMER_VERSION = '0.2.4'
CPU_ARCHITECTURE = 'x86'
IMAGE = 'google_apis'
ANDROID_API = 27
system %W(
curl
--fail
--location https://jcenter.bintray.com/com/gojuno/swarmer/swarmer/#{SWARMER_VERSION}/swarmer-#{SWARMER_VERSION}.jar
--output /tmp/swarmer.jar
).join(' ')
cmds = (1..3).reduce([]) do |acc, number|
acc << %W(
--emulator-name test#{number}
--package "system-images;android-#{ANDROID_API};#{IMAGE};#{CPU_ARCHITECTURE}"
--android-abi #{IMAGE}/#{CPU_ARCHITECTURE}
--path-to-config-ini test/functional/android/emulator_config.ini
--emulator-start-options -netdelay none -netspeed full -screen touch -prop persist.sys.language=en -prop persist.sys.country=US
).join(' ')
end

system %W(java -jar /tmp/swarmer.jar start).concat(cmds).flatten.join(' ')
end
end

desc('Generate yardoc')
YARD::Rake::YardocTask.new do |t|
t.files = %w(lib/**/*.rb)
Expand Down
3 changes: 2 additions & 1 deletion test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_window_size
Expand Down Expand Up @@ -64,7 +65,7 @@ def test_background_reset

@driver.reset

e = @@core.wait { @driver.find_element :accessibility_id, 'App' }
e = @@core.wait(timeout: 60) { @driver.find_element :accessibility_id, 'App' }
assert_equal 'App', e.text
end

Expand Down
1 change: 1 addition & 0 deletions test/functional/android/android/image_comparison_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_image_comparison_match_result
Expand Down
1 change: 1 addition & 0 deletions test/functional/android/android/search_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_uiautomation
Expand Down
1 change: 1 addition & 0 deletions test/functional/android/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_appium_server_version
Expand Down
42 changes: 42 additions & 0 deletions test/functional/android/emulator_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
AvdId=test
PlayStore.enabled=false
abi.type=x86
avd.ini.displayname=test
avd.ini.encoding=UTF-8
disk.dataPartition.size=3G
fastboot.forceColdBoot=no
hw.accelerometer=yes
hw.arc=false
hw.audioInput=yes
hw.battery=yes
hw.camera.back=virtualscene
hw.camera.front=emulated
hw.cpu.arch=x86
hw.cpu.ncore=2
hw.dPad=no
hw.device.hash2=MD5:bc5032b2a871da511332401af3ac6bb0
hw.device.manufacturer=Google
hw.device.name=Nexus 5X
hw.gps=yes
hw.gpu.enabled=yes
hw.gpu.mode=auto
hw.initialOrientation=Portrait
hw.keyboard=yes
hw.lcd.density=420
hw.lcd.height=1920
hw.lcd.width=1080
hw.mainKeys=no
hw.ramSize=2048
hw.sdCard=yes
hw.sensors.orientation=yes
hw.sensors.proximity=yes
hw.trackBall=no
image.sysdir.1=system-images/android-27/google_apis/x86/
runtime.network.latency=none
runtime.network.speed=full
sdcard.size=100M
showDeviceFrame=no
skin.dynamic=yes
tag.display=Google APIs
tag.id=google_apis
vm.heapSize=1024
6 changes: 6 additions & 0 deletions test/functional/android/webdriver/create_session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def test_mjsonwp
assert_equal :oss, driver.dialect
assert driver.capabilities[:forceMjsonwp].nil?
assert driver.capabilities['forceMjsonwp'].nil?

core.quit_driver
end

# Require Appium 1.7.2+
Expand All @@ -27,6 +29,8 @@ def test_w3c
assert_equal :w3c, driver.dialect
assert driver.capabilities[:forceMjsonwp].nil?
assert driver.capabilities['forceMjsonwp'].nil?

core.quit_driver
end

# Require Appium 1.7.2+
Expand All @@ -39,6 +43,8 @@ def test_w3c_default
assert_equal :w3c, driver.dialect
assert driver.capabilities[:forceMjsonwp].nil?
assert driver.capabilities['forceMjsonwp'].nil?

core.quit_driver
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions test/functional/android/webdriver/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_capabilities
Expand All @@ -20,9 +21,7 @@ def test_capabilities

def test_remote_status
status = @driver.remote_status

assert !status['build']['version'].nil?
assert !status['build']['revision'].nil?
end

# TODO: replace_value
Expand Down Expand Up @@ -115,7 +114,7 @@ def test_network_connection
end

def test_session_capability
assert @driver.session_capabilities['deviceUDID'] == 'emulator-5554'
assert @driver.session_capabilities['deviceUDID'].start_with? 'emulator-'
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/functional/android/webdriver/w3c_actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup

def teardown
save_reports(@driver)
@@core.quit_driver
end

def test_tap
Expand Down
22 changes: 18 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def android
platformName: :android,
automationName: 'uiautomator2',
app: 'test/functional/app/api.apk.zip',
platformVersion: '8.1',
udid: get_udid_name,
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis',
appActivity: 'io.appium.android.apis.ApiDemos',
Expand All @@ -91,7 +91,7 @@ def android
resetKeyboard: true,
disableWindowAnimation: true,
newCommandTimeout: 300,
systemPort: 8200,
systemPort: get_system_port,
language: 'en',
locale: 'US'
},
Expand All @@ -115,14 +115,14 @@ def android_web
# chromedriverExecutable: "#{Dir.pwd}/test/functional/app/chromedriver",
# autoWebviewTimeout: 10000,
chromedriverUseSystemExecutable: true,
platformVersion: '8.1',
udid: get_udid_name,
deviceName: 'Android Emulator',
someCapability: 'some_capability',
unicodeKeyboard: true,
resetKeyboard: true,
disableWindowAnimation: true,
newCommandTimeout: 300,
systemPort: 8200,
systemPort: get_system_port,
language: 'en',
locale: 'US'
},
Expand All @@ -139,13 +139,27 @@ def parallel?
ENV['PARALLEL']
end

private

def get_wda_local_port
# TEST_ENV_NUMBER is provided by parallel_tests gem
# The number is '', '2', '3',...
number = ENV['TEST_ENV_NUMBER'] || ''
core_number = number.empty? ? 0 : number.to_i - 1
[8100, 8101][core_number]
end

def get_system_port
number = ENV['TEST_ENV_NUMBER'] || ''
core_number = number.empty? ? 0 : number.to_i - 1
[8200, 8201, 8202][core_number]
end

def get_udid_name
number = ENV['TEST_ENV_NUMBER'] || ''
core_number = number.empty? ? 0 : number.to_i - 1
%w(emulator-5554 emulator-5556 emulator-5558)[core_number]
end
end

module Mock
Expand Down

0 comments on commit 10558f2

Please sign in to comment.