Skip to content

Commit e3f5b0d

Browse files
authored
refactor: define bridge in core (#676)
* define bridge in core * define patch module * remove require uiautomation
1 parent eb7680f commit e3f5b0d

File tree

12 files changed

+108
-32
lines changed

12 files changed

+108
-32
lines changed

lib/appium_lib/core/android.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# loaded in common/driver.rb
22
require_relative 'android/search_context'
33
require_relative 'android/device'
4+
require_relative 'android/uiautomator1/bridge'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative '../../android'
2+
3+
module Appium
4+
module Core
5+
module Android
6+
module Uiautomator1
7+
module Bridge
8+
def self.for(target)
9+
target.extend Appium::Android::Device
10+
::Appium::Core::Android::SearchContext.extend
11+
end
12+
end
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative '../../android_uiautomator2'
2+
3+
module Appium
4+
module Core
5+
module Android
6+
module Uiautomator2
7+
module Bridge
8+
def self.for(target)
9+
target.extend Appium::Android::Device
10+
::Appium::Core::Android::SearchContext.extend
11+
end
12+
end
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# loaded in common/driver.rb
2+
require_relative 'android/search_context'
3+
require_relative 'android/device'
4+
require_relative 'android/uiautomator2/bridge'

lib/appium_lib/core/core.rb

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
require_relative 'element/window'
88

9+
require_relative 'android'
10+
require_relative 'android_uiautomator2'
11+
12+
require_relative 'ios'
13+
require_relative 'ios_xcuitest'
14+
915
module Appium
1016
# convert all keys (including nested) to symbols
1117
#

lib/appium_lib/core/driver.rb

+4-15
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,16 @@ def extend_for(device:, automation_name:, target:)
6565
when :android
6666
case automation_name
6767
when :uiautomator2
68-
require_relative 'android'
69-
require_relative 'android_uiautomator2'
68+
::Appium::Core::Android::Uiautomator2::Bridge.for(self)
7069
else # default and UiAutomator
71-
require_relative 'android'
70+
::Appium::Core::Android::Uiautomator1::Bridge.for(self)
7271
end
73-
Core::Android::SearchContext.extend
74-
target.extend Appium::Android::Device
7572
when :ios
7673
case automation_name
7774
when :xcuitest
78-
require_relative 'ios'
79-
require_relative 'ios_xcuitest'
80-
Core::Ios::SearchContext.extend
81-
Core::Ios::Xcuitest::SearchContext.extend
82-
target.extend Appium::Ios::Device
83-
target.extend Appium::Ios::Xcuitest::Device
75+
::Appium::Core::Ios::Xcuitest::Bridge.for(self)
8476
else # default and UIAutomation
85-
require_relative 'ios'
86-
Core::Ios::SearchContext.extend
87-
target.extend Appium::Ios::Device
88-
patch_webdriver_element
77+
::Appium::Core::Ios::Uiautomation::Bridge.for(self)
8978
end
9079
when :mac
9180
# no Mac specific extentions

lib/appium_lib/core/ios.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# loaded in common/driver.rb
22
require_relative 'ios/search_context'
33
require_relative 'ios/device'
4-
require_relative 'ios/patch'
4+
5+
require_relative 'ios/uiautomation/patch'
6+
require_relative 'ios/uiautomation/bridge'

lib/appium_lib/core/ios/patch.rb

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative '../../ios'
2+
3+
module Appium
4+
module Core
5+
module Ios
6+
module Uiautomation
7+
module Bridge
8+
def self.for(target)
9+
Core::Ios::SearchContext.extend
10+
target.extend Appium::Ios::Device
11+
patch_webdriver_element
12+
end
13+
end
14+
end
15+
end
16+
end
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Appium
2+
module Core
3+
module Ios
4+
module Uiautomation
5+
# @private
6+
# class_eval inside a method because class Selenium::WebDriver::Element
7+
# will trigger as soon as the file is required. in contrast a method
8+
# will trigger only when invoked.
9+
def patch_webdriver_element
10+
Selenium::WebDriver::Element.class_eval do
11+
# Cross platform way of entering text into a textfield
12+
def type(text, driver = $driver)
13+
driver.execute_script %(au.getElement('#{ref}').setValue('#{text}');)
14+
end # def type
15+
end # Selenium::WebDriver::Element.class_eval
16+
end # def patch_webdriver_element
17+
end # module Uiautomation
18+
end # module Ios
19+
end # module Core
20+
end # module Appium
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require_relative '../../ios_xcuitest'
2+
3+
module Appium
4+
module Core
5+
module Ios
6+
module Xcuitest
7+
module Bridge
8+
def self.for(target)
9+
Core::Ios::SearchContext.extend
10+
Core::Ios::Xcuitest::SearchContext.extend
11+
target.extend Appium::Ios::Device
12+
target.extend Appium::Ios::Xcuitest::Device
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end

lib/appium_lib/core/ios_xcuitest.rb

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# loaded in common/driver.rb
2+
require_relative 'ios/search_context'
3+
require_relative 'ios/device'
4+
25
require_relative 'ios/xcuitest/search_context'
36
require_relative 'ios/xcuitest/device'
7+
require_relative 'ios/xcuitest/bridge'

0 commit comments

Comments
 (0)