Skip to content

Commit 82e2526

Browse files
authored
add w3c touch action tests and some supports for w3c (#35)
* add w3c touch action tests * remove new lines * separate w3c bridge and use touch by default * fix rubocop * remove comment outs to confirm w3c * fix command related issues * catch incorrect parameter error * add getting dialect and fix rubocop * Update driver.rb
1 parent 415b908 commit 82e2526

File tree

12 files changed

+191
-26
lines changed

12 files changed

+191
-26
lines changed

.rubocop.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ Metrics/PerceivedComplexity:
1616
Max: 8
1717
Style/Documentation:
1818
Enabled: false
19-
Style/AccessorMethodName:
20-
Enabled: false
2119
Style/CommentedKeyword:
2220
Enabled: false
2321
Style/PercentLiteralDelimiters:
2422
Enabled: false
23+
Style/BracesAroundHashParameters:
24+
Enabled: false
2525
Lint/NestedMethodDefinition:
2626
Enabled: false
27+
Naming/AccessorMethodName:
28+
Enabled: false

appium_lib_core.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_development_dependency 'bundler', '~> 1.14'
2929
spec.add_development_dependency 'rake', '~> 10.0'
30-
spec.add_development_dependency 'yard', '~> 0.9'
30+
spec.add_development_dependency 'yard', '~> 0.9.11'
3131
spec.add_development_dependency 'minitest', '~> 5.0'
3232
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
3333
spec.add_development_dependency 'webmock', '~> 3.1.0'

lib/appium_lib_core/common/base.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# The following files have selenium-webdriver related stuff.
22
require_relative 'base/driver'
33
require_relative 'base/bridge'
4+
require_relative 'base/msjsonwp_bridge'
5+
require_relative 'base/w3c_bridge'
46
require_relative 'base/capabilities'
57
require_relative 'base/http_default'
68
require_relative 'base/search_context'

lib/appium_lib_core/common/base/bridge.rb

-17
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ def merged_capabilities(desired_capabilities)
8383
}
8484
end
8585
end # class Bridge
86-
87-
class CoreBridgeMJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
88-
def commands(command)
89-
::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
90-
end
91-
end # class CoreBridgeMJSONWP
92-
93-
class CoreBridgeW3C < ::Selenium::WebDriver::Remote::W3C::Bridge
94-
def commands(command)
95-
case command
96-
when :status, :is_element_displayed
97-
::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
98-
else
99-
::Appium::Core::Commands::COMMANDS_EXTEND_W3C[command]
100-
end
101-
end
102-
end # class CoreBridgeW3C
10386
end # class Base
10487
end # module Core
10588
end # module Appium

lib/appium_lib_core/common/base/driver.rb

+11
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ def initialize(opts = {})
2020
extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
2121
extend ::Selenium::WebDriver::DriverExtensions::HasLocation
2222
extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
23+
elsif @bridge.dialect == :w3c
24+
# TODO: Only for Appium. Ideally, we'd like to remove the below like selenium-webdriver
25+
extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen
26+
extend ::Selenium::WebDriver::DriverExtensions::HasLocation
27+
extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection
2328
end
2429
super(@bridge, listener: listener)
2530
end
2631

32+
# Get the dialect value
33+
# @return [:oss|:w3c]
34+
def dialect
35+
@bridge.dialect
36+
end
37+
2738
# Get the device window's size.
2839
# @return [Selenium::WebDriver::Dimension]
2940
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Appium
2+
module Core
3+
class Base
4+
class CoreBridgeMJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
5+
def commands(command)
6+
::Appium::Core::Commands::COMMANDS_EXTEND_MJSONWP[command]
7+
end
8+
end # class CoreBridgeMJSONWP
9+
end # class Base
10+
end # module Core
11+
end # module Appium
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module Appium
2+
module Core
3+
class Base
4+
class CoreBridgeW3C < ::Selenium::WebDriver::Remote::W3C::Bridge
5+
def commands(command)
6+
::Appium::Core::Commands::COMMANDS_EXTEND_W3C[command]
7+
end
8+
9+
def action(async = false)
10+
::Selenium::WebDriver::W3CActionBuilder.new self,
11+
::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch'),
12+
::Selenium::WebDriver::Interactions.key('keyboard'),
13+
async
14+
end
15+
alias actions action
16+
17+
# override
18+
def find_element_by(how, what, parent = nil)
19+
how, what = convert_locators(how, what)
20+
21+
id = if parent
22+
execute :find_child_element, { id: parent }, { using: how, value: what }
23+
else
24+
execute :find_element, {}, { using: how, value: what }
25+
end
26+
::Selenium::WebDriver::Element.new self, element_id_from(id)
27+
end
28+
29+
# override
30+
def find_elements_by(how, what, parent = nil)
31+
how, what = convert_locators(how, what)
32+
33+
ids = if parent
34+
execute :find_child_elements, { id: parent }, { using: how, value: what }
35+
else
36+
execute :find_elements, {}, { using: how, value: what }
37+
end
38+
39+
ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
40+
end
41+
42+
private
43+
44+
# Don't convert locators for Appium Client
45+
# TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
46+
def convert_locators(how, what)
47+
# case how
48+
# when 'class name'
49+
# how = 'css selector'
50+
# what = ".#{escape_css(what)}"
51+
# when 'id'
52+
# how = 'css selector'
53+
# what = "##{escape_css(what)}"
54+
# when 'name'
55+
# how = 'css selector'
56+
# what = "*[name='#{escape_css(what)}']"
57+
# when 'tag name'
58+
# how = 'css selector'
59+
# end
60+
[how, what]
61+
end
62+
end # class CoreBridgeW3C
63+
end # class Base
64+
end # module Core
65+
end # module Appium

lib/appium_lib_core/common/command.rb

+21-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ module Commands
4343
hide_keyboard: [:post, 'session/:session_id/appium/device/hide_keyboard'.freeze],
4444
press_keycode: [:post, 'session/:session_id/appium/device/press_keycode'.freeze],
4545
long_press_keycode: [:post, 'session/:session_id/appium/device/long_press_keycode'.freeze],
46-
## take_element_screenshot is for MJSONWP. W3C already has.
47-
take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot'.freeze],
4846
# keyevent is only for Selendroid
4947
keyevent: [:post, 'session/:session_id/appium/device/keyevent'.freeze],
5048
set_immediate_value: [:post, 'session/:session_id/appium/element/:id/value'.freeze],
@@ -74,8 +72,27 @@ module Commands
7472
COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS)
7573
.merge(COMMAND_NO_ARG).freeze
7674

77-
COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(::Appium::Core::Base::Commands::OSS).freeze
78-
COMMANDS_EXTEND_W3C = COMMANDS.merge(::Appium::Core::Base::Commands::W3C).freeze
75+
COMMANDS_EXTEND_MJSONWP = COMMANDS.merge(
76+
{
77+
# W3C already has.
78+
take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot'.freeze]
79+
}
80+
).merge(::Appium::Core::Base::Commands::OSS).freeze
81+
COMMANDS_EXTEND_W3C = COMMANDS.merge(
82+
{
83+
# ::Appium::Core::Base::Commands::OSS has the following commands and Appium also use them.
84+
# Delegated to ::Appium::Core::Base::Commands::OSS commands
85+
status: [:get, 'status'.freeze],
86+
is_element_displayed: [:get, 'session/:session_id/element/:id/displayed'.freeze],
87+
88+
# For IME
89+
ime_get_available_engines: [:get, 'session/:session_id/ime/available_engines'.freeze],
90+
ime_get_active_engine: [:get, 'session/:session_id/ime/active_engine'.freeze],
91+
ime_is_activated: [:get, 'session/:session_id/ime/activated'.freeze],
92+
ime_deactivate: [:post, 'session/:session_id/ime/deactivate'.freeze],
93+
ime_activate_engine: [:post, 'session/:session_id/ime/activate'.freeze]
94+
}
95+
).merge(::Appium::Core::Base::Commands::W3C).freeze
7996
end
8097
end
8198
end

lib/appium_lib_core/driver.rb

+9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ def set_implicit_wait_by_default(wait)
194194
raise e.message, ::Appium::Core::Error::ServerError
195195
end
196196

197+
Appium::Logger.debug(e.message)
198+
{}
199+
rescue Selenium::WebDriver::Error::WebDriverError => e
200+
# FIXME: Temporary rescue until Appium support W3C's implicit wait
201+
# https://github.com/jlipps/simple-wd-spec#set-timeouts
202+
unless e.message.include?('Parameters were incorrect. We wanted {"required":["type","ms"]} and you sent ["implicit"]')
203+
raise e.message, ::Appium::Core::Error::ServerError
204+
end
205+
197206
Appium::Logger.debug(e.message)
198207
{}
199208
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'test_helper'
2+
3+
# $ rake test:func:android TEST=test/functional/android/webdriver/w3c_actions_test.rb
4+
# rubocop:disable Style/ClassVars
5+
class AppiumLibCoreTest
6+
module WebDriver
7+
class W3CActionsTest < AppiumLibCoreTest::Function::TestCase
8+
def setup
9+
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)
10+
@@driver ||= @@core.start_driver
11+
12+
@@driver.start_activity app_package: 'io.appium.android.apis',
13+
app_activity: '.ApiDemos'
14+
end
15+
16+
def teardown
17+
save_reports(@@driver)
18+
end
19+
20+
def test_tap
21+
skip if @@driver.dialect
22+
23+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Views') }
24+
@@driver.action.click(el).perform
25+
26+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Custom') }
27+
@@driver.action.click_and_hold(el).move_to_location(0, 700).release.perform
28+
29+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'ImageButton') }
30+
assert_equal 'ImageButton', el.name
31+
end
32+
end
33+
end
34+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'test_helper'
2+
3+
# $ rake test:func:ios TEST=test/functional/ios/webdriver/w3c_actions_test.rb
4+
# rubocop:disable Style/ClassVars
5+
class AppiumLibCoreTest
6+
module WebDriver
7+
class W3CActionsTest < AppiumLibCoreTest::Function::TestCase
8+
def setup
9+
@@core ||= ::Appium::Core.for(self, Caps::IOS_OPS)
10+
@@driver ||= @@core.start_driver
11+
end
12+
13+
def teardown
14+
save_reports(@@driver)
15+
end
16+
17+
def test_tap
18+
skip if @@driver.dialect
19+
20+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'Buttons') }
21+
@@driver.action.click(el).perform
22+
23+
el = @@core.wait { @@driver.find_element(:name, 'Button with Image') }
24+
@@driver.action.click_and_hold(el).move_to_location(0, 700).release.perform
25+
26+
el = @@core.wait { @@driver.find_element(:accessibility_id, 'ImageButton') }
27+
assert_equal 'ImageButton', el.name
28+
end
29+
end
30+
end
31+
end

test/unit/script/commands_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def test_implemented_mjsonwp_commands
3030
end
3131

3232
def test_implemented_w3c_commands
33-
assert_equal 89, @c.implemented_w3c_commands.length
33+
assert_equal 96, @c.implemented_w3c_commands.length
3434
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_w3c_commands.first
3535

3636
# pick up an arbitrary command
3737
assert_equal %i(get post), @c.implemented_w3c_commands['session/:session_id/alert/text']
3838
end
3939

4040
def test_implemented_core_commands
41-
assert_equal 44, @c.implemented_core_commands.length
41+
assert_equal 43, @c.implemented_core_commands.length
4242
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_core_commands.first
4343

4444
# pick up an arbitrary command

0 commit comments

Comments
 (0)