Skip to content

Commit 90c57cd

Browse files
authored
Add w3c common actions scroll (#197)
* add w3c actions for both android and ios * add a new line * update readme
1 parent f95a17d commit 90c57cd

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ $ PARALLEL=1 bundle exec parallel_test test/functional/ios -n 2
9797
# shell 2
9898
$ ruby test.rb
9999
```
100-
100+
101+
More examples are in [test/functional](test/functional)
102+
101103
### Capabilities
102104

103105
Read [Appium/Core/Driver](https://www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Driver) to catch up with available capabilities.

test/functional/android/webdriver/w3c_actions_test.rb

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
113
require 'test_helper'
14+
require 'functional/common_w3c_actions'
215

316
# $ rake test:func:android TEST=test/functional/android/webdriver/w3c_actions_test.rb
417
# rubocop:disable Style/ClassVars
@@ -33,14 +46,7 @@ def test_tap_scroll
3346
.perform
3447
assert rect1.y > el.rect.y
3548

36-
rect2 = el.rect.dup
37-
@driver
38-
.action
39-
.move_to_location(rect2.x, rect2.y)
40-
.pointer_down(:left)
41-
.move_to_location(0, rect2.y - rect2.height * 3) # gone the element
42-
.release
43-
.perform
49+
w3c_scroll @driver
4450

4551
@driver.manage.timeouts.implicit_wait = 3
4652

@@ -53,8 +59,8 @@ def test_tap_scroll
5359
end
5460
@driver.manage.timeouts.implicit_wait = @@core.default_wait
5561

56-
el = @@core.wait { @driver.find_element(:accessibility_id, 'ImageButton') }
57-
assert_equal 'ImageButton', el.text
62+
el = @@core.wait { @driver.find_element(:accessibility_id, 'Lists') }
63+
assert_equal 'Lists', el.text
5864
end
5965

6066
def test_double_tap

test/functional/common_w3c_actions.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
# Scroll action for Android and iOS following W3C spec
14+
def w3c_scroll(driver)
15+
window = driver.window_rect
16+
17+
action_builder = driver.action
18+
input = action_builder.pointer_inputs[0]
19+
action_builder
20+
.move_to_location(window.width / 2, window.width * 8 / 10)
21+
.pointer_down(:left)
22+
.pause(input, 1)
23+
.move_to_location(window.width / 2, window.width / 10)
24+
.pause(input, 1)
25+
.release
26+
.perform
27+
end

test/functional/ios/webdriver/w3c_actions_test.rb

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
113
require 'test_helper'
14+
require 'functional/common_w3c_actions'
215

316
# $ rake test:func:ios TEST=test/functional/ios/webdriver/w3c_actions_test.rb
417
# rubocop:disable Style/ClassVars
@@ -26,6 +39,8 @@ def test_tap
2639
end
2740

2841
def test_scroll
42+
skip if @@driver.dialect == :oss
43+
2944
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Controls') }
3045
@@driver.action.click(el).perform
3146

@@ -39,6 +54,21 @@ def test_scroll
3954
@@driver.execute_script('mobile: scroll', direction: 'down')
4055
end
4156
end
57+
58+
def test_scroll2
59+
skip if @@driver.dialect == :oss
60+
61+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Controls') }
62+
@@driver.action.click(el).perform
63+
64+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Style Gray') }
65+
assert el.visible == 'false'
66+
67+
w3c_scroll @@driver
68+
69+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Style Gray') }
70+
assert el.visible == 'true'
71+
end
4272
end
4373
end
4474
end

0 commit comments

Comments
 (0)