Skip to content

Commit cb9450d

Browse files
authored
refactor: divide dependencies (#649)
* separate dependencies for xcuitest * arrange android modules
1 parent 0673ad7 commit cb9450d

File tree

11 files changed

+111
-46
lines changed

11 files changed

+111
-46
lines changed

android_tests/lib/android/specs/android/helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def id_value
6464
wait { find('accessibility').click }
6565
wait { find('accessibility node provider').click }
6666

67-
if !automation_name_is_uiautomator2?
67+
if automation_name_is_uiautomator2?
6868
wait { text 'Accessibility/Accessibility Node Provider' }
6969
else
7070
# With string.xml

android_tests/lib/android/specs/common/device_touchaction.rb

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# rake android[common/device_touchaction]
22
describe 'common/device_touchaction' do
3+
def before_first
4+
wait { text('Accessibility') }
5+
end
6+
7+
t 'before test' do
8+
before_first
9+
end
10+
311
t 'action_chain_press_release' do
412
wait do
513
e = text('Accessibility')

android_tests/lib/run.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ruby run.rb ios view_album
1212

1313
def start_driver(caps)
14-
driver = Appium::Driver.new(caps)
14+
driver = Appium::Driver.new(caps, true)
1515
# Tests expect methods defined on the minispec object
1616
Appium.promote_appium_methods ::Minitest::Spec
1717
driver.start_driver

ios_tests/lib/ios/specs/common/web_context.rb

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Tests specifically for areas where the web_context differs in behaviour
2+
# rake ios[common/web_context]
23
describe 'the web context' do
4+
def before_first
5+
screen.must_equal catalog
6+
end
7+
8+
t 'before_first' do
9+
before_first
10+
end
311
t 'get_android_inspect' do
412
text('Web').click
513

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require_relative 'uiautomator2/helper'
2+
require_relative 'uiautomator2/element'
3+
4+
module Appium
5+
module Ios
6+
module Xcuitest
7+
# parent
8+
end # module Xcuitest
9+
end # module Ios
10+
end # module Appium
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require_relative 'element/button'
2+
3+
module Appium
4+
module Android
5+
module Uiautomator2
6+
module Element
7+
end # module Element
8+
end # module Uiautomator2
9+
end # module Android
10+
end # module Appium

lib/appium_lib/capabilities.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Appium
2+
class Driver
3+
module Capabilities
4+
# @param [Hash] opts_caps Capabilities for Appium server. All capability keys are converted to lowerCamelCase when
5+
# this client sends capabilities to Appium server as JSON format.
6+
# @return [::Selenium::WebDriver::Remote::W3C::Capabilities] Return instance of Appium::Driver::Capabilities
7+
# inherited ::Selenium::WebDriver::Remote::W3C::Capabilities
8+
def self.init_caps_for_appium(opts_caps = {})
9+
::Selenium::WebDriver::Remote::W3C::Capabilities.new(opts_caps)
10+
end
11+
end
12+
end
13+
end

lib/appium_lib/driver.rb

+13-27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
require 'selenium-webdriver'
44
require 'nokogiri'
55

6+
# base
7+
require_relative 'capabilities'
8+
69
# common
710
require_relative 'common/helper'
811
require_relative 'common/wait'
@@ -25,17 +28,7 @@
2528
require_relative 'ios/element/text'
2629
require_relative 'ios/mobile_methods'
2730

28-
# ios - xcuitest
29-
require_relative 'ios/xcuitest/search_context'
30-
require_relative 'ios/xcuitest/element'
31-
require_relative 'ios/xcuitest/gestures'
32-
require_relative 'ios/xcuitest/command/pasteboard'
33-
require_relative 'ios/xcuitest/device'
34-
require_relative 'ios/xcuitest/helper'
35-
require_relative 'ios/xcuitest/element/text'
36-
require_relative 'ios/xcuitest/element/textfield'
37-
require_relative 'ios/xcuitest/element/generic'
38-
require_relative 'ios/xcuitest/element/button'
31+
require_relative 'ios/xcuitest'
3932

4033
# android
4134
require_relative 'android/helper'
@@ -51,7 +44,7 @@
5144
require_relative 'android/device'
5245

5346
# android - uiautomator2
54-
require_relative 'android/uiautomator2/helper.rb'
47+
require_relative 'android/uiautomator2'
5548

5649
# device methods
5750
require_relative 'device/device'
@@ -269,18 +262,6 @@ def self.selenium_webdriver_version_more?(version)
269262
Gem.loaded_specs['selenium-webdriver'].version >= Gem::Version.new(version)
270263
end
271264

272-
class Driver
273-
module Capabilities
274-
# @param [Hash] opts_caps Capabilities for Appium server. All capability keys are converted to lowerCamelCase when
275-
# this client sends capabilities to Appium server as JSON format.
276-
# @return [::Selenium::WebDriver::Remote::W3C::Capabilities] Return instance of Appium::Driver::Capabilities
277-
# inherited ::Selenium::WebDriver::Remote::W3C::Capabilities
278-
def self.init_caps_for_appium(opts_caps = {})
279-
::Selenium::WebDriver::Remote::W3C::Capabilities.new(opts_caps)
280-
end
281-
end
282-
end
283-
284265
class Driver
285266
# attr readers are promoted to global scope. To avoid clobbering, they're
286267
# made available via the driver_attributes method
@@ -388,11 +369,15 @@ class Driver
388369
# @param opts [Object] A hash containing various options.
389370
# @param global_driver [Bool] A bool require global driver before initialize.
390371
# @return [Driver]
391-
def initialize(opts = {}, global_driver = true)
392-
if global_driver
372+
def initialize(opts = {}, global_driver = nil)
373+
if global_driver.nil?
393374
warn '[DEPRECATION] Appium::Driver.new(opts) will not generate global driver by default.' \
394375
'If you would like to generate the global driver dy default, ' \
395376
'please initialise driver with Appium::Driver.new(opts, true)'
377+
global_driver = true # if global_driver is nil, then global_driver must be default value.
378+
end
379+
380+
if global_driver
396381
$driver.driver_quit if $driver
397382
end
398383
raise 'opts must be a hash' unless opts.is_a? Hash
@@ -427,12 +412,13 @@ def initialize(opts = {}, global_driver = true)
427412
extend Appium::Android
428413
extend Appium::Android::Device
429414
if automation_name_is_uiautomator2?
415+
extend Appium::Android::Uiautomator2
430416
extend Appium::Android::Uiautomator2::Helper
417+
extend Appium::Android::Uiautomator2::Element
431418
end
432419
else
433420
extend Appium::Ios
434421
if automation_name_is_xcuitest?
435-
# Override touch actions and patch_webdriver_element
436422
extend Appium::Ios::Xcuitest
437423
extend Appium::Ios::Xcuitest::SearchContext
438424
extend Appium::Ios::Xcuitest::Command

lib/appium_lib/ios/xcuitest.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative 'xcuitest/search_context'
2+
require_relative 'xcuitest/element'
3+
require_relative 'xcuitest/gestures'
4+
require_relative 'xcuitest/command'
5+
require_relative 'xcuitest/device'
6+
require_relative 'xcuitest/helper'
7+
require_relative 'xcuitest/element'
8+
9+
module Appium
10+
module Ios
11+
module Xcuitest
12+
# parent
13+
end # module Xcuitest
14+
end # module Ios
15+
end # module Appium
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require_relative 'command/pasteboard'
2+
3+
module Appium
4+
module Ios
5+
module Command
6+
end
7+
end
8+
end
+24-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1+
require_relative 'element/text'
2+
require_relative 'element/textfield'
3+
require_relative 'element/generic'
4+
require_relative 'element/button'
5+
16
module Appium
27
module Ios
38
module Xcuitest
4-
# @private
5-
# class_eval inside a method because class Selenium::WebDriver::Element
6-
# will trigger as soon as the file is required. in contrast a method
7-
# will trigger only when invoked.
8-
def patch_webdriver_element
9-
Selenium::WebDriver::Element.class_eval do
10-
# Enable access to iOS accessibility label
11-
# accessibility identifier is supported as 'name'
12-
def label
13-
attribute('label')
14-
end
9+
module Element
10+
# @private
11+
# class_eval inside a method because class Selenium::WebDriver::Element
12+
# will trigger as soon as the file is required. in contrast a method
13+
# will trigger only when invoked.
14+
def patch_webdriver_element
15+
Selenium::WebDriver::Element.class_eval do
16+
# Enable access to iOS accessibility label
17+
# accessibility identifier is supported as 'name'
18+
def label
19+
attribute('label')
20+
end
1521

16-
# Cross platform way of entering text into a textfield
17-
def type(text)
18-
send_keys text
19-
end # def type
20-
end # Selenium::WebDriver::Element.class_eval
21-
end # def patch_webdriver_element
22+
# Cross platform way of entering text into a textfield
23+
def type(text)
24+
send_keys text
25+
end # def type
26+
end # Selenium::WebDriver::Element.class_eval
27+
end # def patch_webdriver_element
28+
end # module Element
2229
end # module Xcuitest
2330
end # module Ios
2431
end # module Appium

0 commit comments

Comments
 (0)