Skip to content

Commit 297bf22

Browse files
authored
add some oss commands to w3c module(#38)
* add some oss commands to w3c * fix rubocop * update changelog * fix unit tests
1 parent 321bd64 commit 297bf22

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
### Enhancements
66

77
### Bug fixes
8+
- Fix some w3c methods to work with Appium part 2 [#38](https://github.com/appium/ruby_lib_core/pull/38)
9+
10+
### Deprecations
11+
12+
## [1.2.3]
13+
### Enhancements
14+
15+
### Bug fixes
16+
- Fix some w3c methods to work with Appium part 2 [#38](https://github.com/appium/ruby_lib_core/pull/38)
817

918
### Deprecations
1019

lib/appium_lib_core/common/base/w3c_bridge.rb

+31
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def commands(command)
1616
# - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
1717
#
1818
# @private
19+
# For Appium
1920
# override
2021
#
2122
# @example
@@ -31,6 +32,7 @@ def action(async = false)
3132
end
3233
alias actions action
3334

35+
# For Appium
3436
# override
3537
def page_source
3638
# For W3C
@@ -40,13 +42,15 @@ def page_source
4042
execute :get_page_source
4143
end
4244

45+
# For Appium
4346
# override
4447
def element_attribute(element, name)
4548
# For W3C
4649
# execute_atom :getAttribute, element, name
4750
execute :get_element_attribute, id: element.ref, name: name
4851
end
4952

53+
# For Appium
5054
# override
5155
def find_element_by(how, what, parent = nil)
5256
how, what = convert_locators(how, what)
@@ -59,6 +63,7 @@ def find_element_by(how, what, parent = nil)
5963
::Selenium::WebDriver::Element.new self, element_id_from(id)
6064
end
6165

66+
# For Appium
6267
# override
6368
def find_elements_by(how, what, parent = nil)
6469
how, what = convert_locators(how, what)
@@ -72,6 +77,32 @@ def find_elements_by(how, what, parent = nil)
7277
ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
7378
end
7479

80+
# For Appium
81+
# override
82+
def location
83+
obj = execute(:get_location) || {}
84+
Location.new obj['latitude'], obj['longitude'], obj['altitude']
85+
end
86+
87+
# For Appium
88+
# override
89+
def set_location(lat, lon, alt)
90+
loc = { latitude: lat, longitude: lon, altitude: alt }
91+
execute :set_location, {}, { location: loc }
92+
end
93+
94+
# For Appium
95+
# override
96+
def network_connection
97+
execute :get_network_connection
98+
end
99+
100+
# For Appium
101+
# override
102+
def network_connection=(type)
103+
execute :set_network_connection, {}, { parameters: { type: type } }
104+
end
105+
75106
private
76107

77108
# Don't convert locators for Appium Client

lib/appium_lib_core/common/command.rb

+11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ module Commands
8989
# The fix will be included in selenium-3.8.2
9090
get_page_source: [:get, 'session/:session_id/source'.freeze],
9191

92+
## Add to W3C commands
93+
# rotatable
94+
get_screen_orientation: [:get, 'session/:session_id/orientation'.freeze],
95+
set_screen_orientation: [:post, 'session/:session_id/orientation'.freeze],
96+
97+
get_location: [:get, 'session/:session_id/location'.freeze],
98+
set_location: [:post, 'session/:session_id/location'.freeze],
99+
100+
get_network_connection: [:get, 'session/:session_id/network_connection'.freeze],
101+
set_network_connection: [:post, 'session/:session_id/network_connection'.freeze],
102+
92103
# For IME
93104
ime_get_available_engines: [:get, 'session/:session_id/ime/available_engines'.freeze],
94105
ime_get_active_engine: [:get, 'session/:session_id/ime/active_engine'.freeze],

test/functional/android/android/device_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ def test_context_related
7171
@@core.wait { scroll_to('Views') }.click
7272
@@core.wait { scroll_to('WebView') }.click
7373

74-
assert_equal 'NATIVE_APP', @@driver.current_context
74+
@@core.wait { assert_equal 'NATIVE_APP', @@driver.current_context }
7575

7676
contexts = @@driver.available_contexts
7777
webview_context = contexts.detect { |e| e.start_with?('WEBVIEW') }
7878

7979
@@driver.set_context webview_context
80-
assert @@driver.current_context.start_with? 'WEBVIEW'
80+
@@core.wait { assert @@driver.current_context.start_with? 'WEBVIEW' }
8181

8282
@@driver.switch_to_default_context
83-
assert_equal 'NATIVE_APP', @@driver.current_context
83+
@@core.wait { assert_equal 'NATIVE_APP', @@driver.current_context }
8484
end
8585

8686
def test_app_string

test/functional/android/android/search_context_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# $ rake test:func:android TEST=test/functional/android/android/search_context_test.rb
44
# rubocop:disable Style/ClassVars
55
class AppiumLibCoreTest
6-
module Ios
6+
module Android
77
class SearchContextTest < AppiumLibCoreTest::Function::TestCase
88
def setup
99
@@core ||= ::Appium::Core.for(self, Caps::ANDROID_OPS)

test/functional/android/webdriver/device_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_accept_alert
6767
# 'Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - ""'
6868
# assert @@driver.switch_to.alert.text.start_with?('Lorem ipsum dolor sit aie consectetur')
6969
# assert @@driver.switch_to.alert.dismiss
70-
assert_equal 'OK', @@driver.find_element(:id, 'android:id/button1').name
70+
@@core.wait { assert_equal 'OK', @@driver.find_element(:id, 'android:id/button1').name.upcase }
7171
assert @@driver.find_element(:id, 'android:id/button1').click
7272
end
7373

@@ -82,7 +82,7 @@ def test_dismiss_alert
8282
# assert @@driver.switch_to.alert.dismiss
8383

8484
# Because the results depends on OS version.
85-
assert_equal 'CANCEL', @@driver.find_element(:id, 'android:id/button2').name.upcase
85+
@@core.wait { assert_equal 'CANCEL', @@driver.find_element(:id, 'android:id/button2').name.upcase }
8686
assert @@driver.find_element(:id, 'android:id/button2').click
8787
end
8888

test/unit/script/commands_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_implemented_mjsonwp_commands
3030
end
3131

3232
def test_implemented_w3c_commands
33-
assert_equal 96, @c.implemented_w3c_commands.length
33+
assert_equal 98, @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

0 commit comments

Comments
 (0)