Skip to content

Commit 6603750

Browse files
authored
add mobile permission commands (#160)
* add mobile permission commands * update scenarios * fix mobile command tests * add skip if no opencv4nodejs * add skip
1 parent baf4dab commit 6603750

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

lib/appium_lib_core/driver.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ def quit_driver
273273
# @core.appium_server_version
274274
# {
275275
# "build" => {
276-
# "version" => "0.18.1",
277-
# "revision" => "d242ebcfd92046a974347ccc3a28f0e898595198"
276+
# "version" => "1.9.2",
277+
# "git-sha" => "fd7c7fd19d3896719616cd970229d73e63b5271a",
278+
# "built" => "2018-11-08 12:24:02 +0900"
278279
# }
279280
# }
280281
#

test/functional/ios/ios/image_comparison_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
# rubocop:disable Style/ClassVars
66
class AppiumLibCoreTest
77
module Ios
8+
# @since Appium 1.9.0
9+
# Need `npm install -g appium opencv4nodejs`
810
class ImageComparisionTest < AppiumLibCoreTest::Function::TestCase
911
def setup
1012
@@core ||= ::Appium::Core.for(Caps.ios)
1113
@@driver ||= @@core.start_driver
1214
end
1315

1416
def test_image_comparison_match_result
17+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
18+
1519
image1 = File.read './test/functional/data/test_normal.png'
1620
image2 = File.read './test/functional/data/test_has_blue.png'
1721

@@ -27,6 +31,8 @@ def test_image_comparison_match_result
2731
end
2832

2933
def test_image_comparison_find_result
34+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
35+
3036
image1 = File.read './test/functional/data/test_normal.png'
3137
image2 = File.read './test/functional/data/test_has_blue.png'
3238

@@ -42,6 +48,8 @@ def test_image_comparison_find_result
4248
end
4349

4450
def test_image_comparison_get_images_result
51+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
52+
4553
image1 = File.read './test/functional/data/test_normal.png'
4654
image2 = File.read './test/functional/data/test_has_blue.png'
4755

test/functional/ios/ios/mjpeg_server_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def teardown
1616

1717
# Can view via http://localhost:9100 by default
1818
def test_config
19+
skip 'It requires Appium 1.9.2' unless AppiumLibCoreTest.required_appium_version?(@@core, '1.9.2')
20+
1921
@@driver.update_settings({ mjpegServerScreenshotQuality: 10, mjpegServerFramerate: 1 })
2022
@@driver.update_settings({ mjpegServerScreenshotQuality: 0, mjpegServerFramerate: -100 })
2123
@@driver.update_settings({ mjpegServerScreenshotQuality: -10, mjpegServerFramerate: 60 })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'test_helper'
2+
3+
# $ rake test:func:ios TEST=test/functional/ios/ios/mobile_commands_test.rb
4+
class AppiumLibCoreTest
5+
class DriverTest < AppiumLibCoreTest::Function::TestCase
6+
def teardown
7+
save_reports(@driver)
8+
end
9+
10+
# @since Appium 1.9.2
11+
# Requires simulator
12+
def test_permission
13+
caps = Caps.ios.dup
14+
caps[:caps][:permissions] = '{"com.example.apple-samplecode.UICatalog": { "calendar": "YES", "photos": "no" }}'
15+
core = ::Appium::Core.for(caps)
16+
@driver = core.start_driver
17+
18+
assert @driver.execute_script('mobile: getPermission',
19+
{ service: 'calendar', bundleId: 'com.example.apple-samplecode.UICatalog' }) == 'yes'
20+
assert @driver.execute_script('mobile: getPermission',
21+
{ service: 'photos', bundleId: 'com.example.apple-samplecode.UICatalog' }) == 'no'
22+
23+
@driver.activate_app('com.apple.Preferences')
24+
@driver.find_element(:accessibility_id, 'Privacy').click
25+
26+
@driver.find_element(:accessibility_id, 'Calendars').click
27+
el = @driver.find_element(:accessibility_id, 'UICatalog')
28+
assert_equal '1', el.value
29+
30+
@driver.back
31+
32+
@driver.find_element(:accessibility_id, 'Photos').click
33+
el = @driver.find_element(:accessibility_id, 'Never')
34+
assert_equal 'Never', el.value
35+
end
36+
end
37+
end

test/test_helper.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def save_reports(driver)
3737
end
3838

3939
class AppiumLibCoreTest
40+
def self.required_appium_version?(core_driver, required)
41+
version = core_driver.appium_server_version
42+
43+
return false if version.empty?
44+
45+
v = version['build']['version'].split('-') # 1.9.2-beta.2
46+
v >= required.to_s
47+
end
48+
4049
class Caps
4150
def self.ios
4251
new.ios
@@ -67,7 +76,9 @@ def ios
6776
someCapability: 'some_capability',
6877
newCommandTimeout: 120,
6978
wdaLocalPort: wda_local_port,
70-
waitForQuiescence: false
79+
# `true`, which is the default value, is faster to finishing launching part in many cases
80+
# But sometimes `false` is necessary. It leads regressions sometimes though.
81+
waitForQuiescence: true
7182
},
7283
appium_lib: {
7384
export_session: true,

0 commit comments

Comments
 (0)