Skip to content

Commit 6400a8d

Browse files
authored
increase w3c functional tests for android (#157)
* increase w3c functional tests * make sure the test in w3c * fix rubocop * add double tap and many actions * fix rubocop * add click_and_hold and tweak test cases * define espresso name as environment variable
1 parent d8d165b commit 6400a8d

File tree

6 files changed

+87
-14
lines changed

6 files changed

+87
-14
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ $ appium --relaxed-security # To run all tests in local
3434
- Conduct tests
3535
```bash
3636
$ bundle install
37-
$ rake test:func:android # Andorid
37+
$ rake test:func:android # Andorid, uiautomator2
38+
$ AUTOMATION_NAME=espresso rake test:func:android # Andorid, uiautomator2
3839
$ rake test:func:ios # iOS
3940
```
4041

Rakefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ namespace :test do
5757
end
5858

5959
namespace :android do
60+
desc('uninstall all of test apks from a test device')
61+
task :uninstall_test_apks do |_t, _args|
62+
`adb uninstall io.appium.uiautomator2.server.test`
63+
`adb uninstall io.appium.uiautomator2.server`
64+
`adb uninstall io.appium.settings`
65+
`adb uninstall io.appium.android.ime`
66+
`adb uninstall io.appium.espressoserver.test`
67+
end
68+
69+
6070
desc('Generate and launch android emulators')
61-
task :gen_device do |_t, _args|
71+
task :gen_device do |_t, _args|
6272
SWARMER_VERSION = '0.2.4'
6373
CPU_ARCHITECTURE = 'x86'
6474
IMAGE = 'google_apis'

test/functional/android/webdriver/device_test.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ class DeviceTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(Caps.android)
1010
@driver = @@core.start_driver
11-
12-
require 'pry'
13-
binding.pry
1411
end
1512

1613
def teardown
@@ -71,7 +68,7 @@ def test_page_source
7168
xml = REXML::Document.new s_source
7269

7370
assert s_source.include?('io.appium.android.apis')
74-
assert_equal expected, xml[1].elements.each('//*'){ |v| v }.map(&:name)
71+
assert_equal expected, xml[1].elements.each('//*') { |v| v }.map(&:name)
7572
end
7673

7774
# def test_location

test/functional/android/webdriver/w3c_actions_test.rb

+69-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ def teardown
1515
@@core.quit_driver
1616
end
1717

18-
def test_tap
18+
def test_tap_scroll
1919
skip if @driver.dialect == :oss
2020

2121
el = @@core.wait { @driver.find_element(:accessibility_id, 'Views') }
2222
@driver.action.click(el).perform
2323

2424
el = @@core.wait { @driver.find_element(:accessibility_id, 'Custom') }
25-
# same as @driver.action.click_and_hold(el).move_to_location(0, 700).release.perform
2625

2726
rect1 = el.rect.dup
2827
@driver
@@ -39,15 +38,81 @@ def test_tap
3938
.action
4039
.move_to_location(rect2.x, rect2.y)
4140
.pointer_down(:left)
42-
.move_to_location(0, rect2.y - rect2.height * 2)
41+
.move_to_location(0, rect2.y - rect2.height * 3) # gone the element
4342
.release
4443
.perform
45-
assert rect2.y > el.rect.y
44+
45+
@driver.manage.timeouts.implicit_wait = 3
46+
assert_raises ::Selenium::WebDriver::Error::NoSuchElementError do
47+
@driver.find_element(:accessibility_id, 'Custom')
48+
end
49+
@driver.manage.timeouts.implicit_wait = @@core.default_wait
4650

4751
el = @@core.wait { @driver.find_element(:accessibility_id, 'ImageButton') }
4852
assert_equal 'ImageButton', el.text
4953
end
5054

55+
def test_double_tap
56+
skip if @driver.dialect == :oss
57+
58+
el = @@core.wait { @driver.find_element(:accessibility_id, 'Views') }
59+
@driver.action.click(el).perform
60+
61+
el = @@core.wait { @driver.find_element(:accessibility_id, 'Buttons') }
62+
@driver.action.click(el).perform
63+
64+
el = @driver.find_element(:id, 'io.appium.android.apis:id/button_toggle')
65+
assert_equal 'OFF', el.text
66+
@driver.action.click(el).perform
67+
68+
assert_equal 'ON', el.text
69+
70+
# double tap action with pause
71+
action_builder = @driver.action
72+
input = action_builder.pointer_inputs[0]
73+
action_builder
74+
.move_to(el)
75+
.pointer_down(:left)
76+
.pause(input, 0.05) # seconds
77+
.pointer_up(:left)
78+
.pause(input, 0.05) # seconds
79+
.pointer_down(:left)
80+
.pause(input, 0.05) # seconds
81+
.pointer_up(:left)
82+
.perform
83+
assert_equal 'ON', el.text
84+
85+
error = assert_raises ::Selenium::WebDriver::Error::UnknownError do
86+
@driver.action.double_click(el).perform
87+
end
88+
assert error.message.include?('You cannot perform')
89+
end
90+
91+
def test_actions_with_many_down_up
92+
skip if @driver.dialect == :oss
93+
94+
el = @@core.wait { @driver.find_element(:accessibility_id, 'Views') }
95+
@driver.action.click_and_hold(el).release.perform
96+
97+
el = @@core.wait { @driver.find_element(:accessibility_id, 'Custom') }
98+
99+
rect1 = el.rect.dup
100+
101+
error = assert_raises ::Selenium::WebDriver::Error::UnknownError do
102+
@driver
103+
.action
104+
.move_to(el)
105+
.pointer_down(:left) # should insert pause
106+
.pointer_down(:left)
107+
.pointer_down(:left)
108+
.move_to_location(0, rect1.y - rect1.height)
109+
.release
110+
.release
111+
.perform
112+
end
113+
assert error.message.include?('You cannot perform')
114+
end
115+
51116
# Note: Works with Espresso Driver
52117
def test_multiple_actions
53118
f1 = @driver.action.add_pointer_input(:touch, 'finger1')

test/functional/ios/webdriver/device_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ def test_page_source
5656

5757
assert !source.include?('AppiumAUT')
5858
assert source.include?('XCUIElementTypeApplication type')
59-
assert xml[2].elements.each('//*'){ |v| v }.map(&:name) == 77
59+
assert xml[2].elements.each('//*') { |v| v }.map(&:name) == 77
6060

6161
s_source = @@driver.page_source
6262
s_xml = REXML::Document.new s_source
6363

6464
assert s_source.include?('AppiumAUT')
6565
assert s_source.include?('XCUIElementTypeApplication type')
66-
assert s_xml[2].elements.each('//*'){ |v| v }.map(&:name) == 81
66+
assert s_xml[2].elements.each('//*') { |v| v }.map(&:name) == 81
6767
end
6868

6969
def test_location

test/test_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def android
8080
{
8181
caps: {
8282
platformName: :android,
83-
automationName: 'uiautomator2',
83+
automationName: ENV['AUTOMATION_NAME'] || 'uiautomator2',
8484
app: 'test/functional/app/api.apk.zip',
8585
udid: get_udid_name,
8686
deviceName: 'Android Emulator',
@@ -109,7 +109,7 @@ def android_web
109109
caps: {
110110
browserName: :chrome,
111111
platformName: :android,
112-
automationName: 'uiautomator2',
112+
automationName: ENV['AUTOMATION_NAME'] || 'uiautomator2',
113113
chromeOptions: { androidPackage: 'com.android.chrome', args: ['--disable-popup-blocking'] },
114114
# refer: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md
115115
# chromedriverExecutable: "#{Dir.pwd}/test/functional/app/chromedriver",

0 commit comments

Comments
 (0)