Skip to content

Commit 67a997c

Browse files
Clean up module syntax
Fix #134
1 parent 8be5b7c commit 67a997c

22 files changed

+1810
-1782
lines changed

lib/appium_lib.rb

+2-14
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,5 @@ def self.method_missing method, *args, &block
2121
end
2222
end
2323

24-
module Appium
25-
# @private
26-
def self.add_to_path file, path=false
27-
path = path ? "../#{path}/" : '..'
28-
path = File.expand_path path, file
29-
30-
$:.unshift path unless $:.include? path
31-
end
32-
33-
add_to_path __FILE__
34-
35-
require_relative 'appium_lib/logger'
36-
require_relative 'appium_lib/driver'
37-
end
24+
require_relative 'appium_lib/logger'
25+
require_relative 'appium_lib/driver'

lib/appium_lib/android/dynamic.rb

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
# encoding: utf-8
2-
32
module Appium
43
class Driver
54
@@map = {
6-
1 => [ 'text(String text)', 'SELECTOR_TEXT', 1],
7-
2 => [ 'textStartsWith(String text)', 'SELECTOR_START_TEXT', 2],
8-
3 => [ 'textContains(String text)', 'SELECTOR_CONTAINS_TEXT', 3],
9-
4 => [ 'className(String className)', 'SELECTOR_CLASS', 4],
10-
5 => [ 'description(String desc)', 'SELECTOR_DESCRIPTION', 5],
11-
6 => [ 'descriptionStartsWith(String desc)', 'SELECTOR_START_DESCRIPTION', 6],
12-
7 => [ 'descriptionContains(String desc)', 'SELECTOR_CONTAINS_DESCRIPTION', 7],
13-
8 => [ 'index(final int index)', 'SELECTOR_INDEX', 8],
14-
9 => [ 'instance(final int instance)', 'SELECTOR_INSTANCE', 9],
15-
10 => [ 'enabled(boolean val)', 'SELECTOR_ENABLED', 10],
16-
11 => [ 'focused(boolean val)', 'SELECTOR_FOCUSED', 11],
17-
12 => [ 'focusable(boolean val)', 'SELECTOR_FOCUSABLE', 12],
18-
13 => [ 'scrollable(boolean val)', 'SELECTOR_SCROLLABLE', 13],
19-
14 => [ 'clickable(boolean val)', 'SELECTOR_CLICKABLE', 14],
20-
15 => [ 'checked(boolean val)', 'SELECTOR_CHECKED', 15],
21-
16 => [ 'selected(boolean val)', 'SELECTOR_SELECTED', 16],
5+
1 => ['text(String text)', 'SELECTOR_TEXT', 1],
6+
2 => ['textStartsWith(String text)', 'SELECTOR_START_TEXT', 2],
7+
3 => ['textContains(String text)', 'SELECTOR_CONTAINS_TEXT', 3],
8+
4 => ['className(String className)', 'SELECTOR_CLASS', 4],
9+
5 => ['description(String desc)', 'SELECTOR_DESCRIPTION', 5],
10+
6 => ['descriptionStartsWith(String desc)', 'SELECTOR_START_DESCRIPTION', 6],
11+
7 => ['descriptionContains(String desc)', 'SELECTOR_CONTAINS_DESCRIPTION', 7],
12+
8 => ['index(final int index)', 'SELECTOR_INDEX', 8],
13+
9 => ['instance(final int instance)', 'SELECTOR_INSTANCE', 9],
14+
10 => ['enabled(boolean val)', 'SELECTOR_ENABLED', 10],
15+
11 => ['focused(boolean val)', 'SELECTOR_FOCUSED', 11],
16+
12 => ['focusable(boolean val)', 'SELECTOR_FOCUSABLE', 12],
17+
13 => ['scrollable(boolean val)', 'SELECTOR_SCROLLABLE', 13],
18+
14 => ['clickable(boolean val)', 'SELECTOR_CLICKABLE', 14],
19+
15 => ['checked(boolean val)', 'SELECTOR_CHECKED', 15],
20+
16 => ['selected(boolean val)', 'SELECTOR_SELECTED', 16],
2221
# // SELECTOR_ID = 17; // nothing.
23-
18 => [ 'packageName(String name)', 'SELECTOR_PACKAGE_NAME', 18],
22+
18 => ['packageName(String name)', 'SELECTOR_PACKAGE_NAME', 18],
2423
# // SELECTOR_CHILD = 19; // childSelector(UiSelector selector)
2524
# // SELECTOR_CONTAINER = 20; // containerSelector(UiSelector selector)
2625
# // SELECTOR_PATTERN = 21; // ! private ! patternSelector(UiSelector selector)
2726
# // SELECTOR_PARENT = 22; // fromParent(UiSelector selector)
2827
# // SELECTOR_COUNT = 23; // nothing.
29-
24 => [ 'longClickable(boolean val)', 'SELECTOR_LONG_CLICKABLE', 24],
30-
25 => [ 'textMatches(String regex)', 'SELECTOR_TEXT_REGEX', 25],
31-
26 => [ 'classNameMatches(String regex)', 'SELECTOR_CLASS_REGEX', 26],
32-
27 => [ 'descriptionMatches(String regex)', 'SELECTOR_DESCRIPTION_REGEX', 27],
33-
28 => [ 'packageNameMatches(String regex)', 'SELECTOR_PACKAGE_NAME_REGEX', 28],
28+
24 => ['longClickable(boolean val)', 'SELECTOR_LONG_CLICKABLE', 24],
29+
25 => ['textMatches(String regex)', 'SELECTOR_TEXT_REGEX', 25],
30+
26 => ['classNameMatches(String regex)', 'SELECTOR_CLASS_REGEX', 26],
31+
27 => ['descriptionMatches(String regex)', 'SELECTOR_DESCRIPTION_REGEX', 27],
32+
28 => ['packageNameMatches(String regex)', 'SELECTOR_PACKAGE_NAME_REGEX', 28],
3433
# // start internal methods at 100
35-
100 => [ 'getStringAttribute("name")', 'GET_NAME', 100]
36-
}
34+
100 => ['getStringAttribute("name")', 'GET_NAME', 100]
35+
}
3736

38-
# @private
39-
def dynamic_code_to_string code, value=false
40-
result = @@map[code].first
41-
return result unless value
42-
result.split('(').first + "( \"#{value}\" )"
43-
end
37+
# @private
38+
def dynamic_code_to_string code, value=false
39+
result = @@map[code].first
40+
return result unless value
41+
result.split('(').first + "( \"#{value}\" )"
42+
end
4443
end # class Driver
4544
end # module Appium
+33-31
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
# encoding: utf-8
2-
module Appium::Android
3-
# Tap the alert button identified by value.
4-
# @param value [Integer, String] either an integer index of the button or the button's name
5-
# @return [void]
6-
def alert_click value
7-
button(value).click
8-
end
2+
module Appium
3+
module Android
4+
# Tap the alert button identified by value.
5+
# @param value [Integer, String] either an integer index of the button or the button's name
6+
# @return [void]
7+
def alert_click value
8+
button(value).click
9+
end
910

10-
# Accept the alert.
11-
# The last button is considered "accept."
12-
# @return [void]
13-
def alert_accept
14-
last_button.click
15-
end
11+
# Accept the alert.
12+
# The last button is considered "accept."
13+
# @return [void]
14+
def alert_accept
15+
last_button.click
16+
end
1617

17-
# Get the text of the alert's accept button.
18-
# The last button is considered "accept."
19-
# @return [String]
20-
def alert_accept_text
21-
last_button.text
22-
end
18+
# Get the text of the alert's accept button.
19+
# The last button is considered "accept."
20+
# @return [String]
21+
def alert_accept_text
22+
last_button.text
23+
end
2324

24-
# Dismiss the alert.
25-
# The first button is considered "dismiss."
26-
# @return [void]
27-
def alert_dismiss
28-
first_button.click
29-
end
25+
# Dismiss the alert.
26+
# The first button is considered "dismiss."
27+
# @return [void]
28+
def alert_dismiss
29+
first_button.click
30+
end
3031

31-
# Get the text of the alert's dismiss button.
32-
# The first button is considered "dismiss."
33-
# @return [String]
34-
def alert_dismiss_text
35-
first_button.text
32+
# Get the text of the alert's dismiss button.
33+
# The first button is considered "dismiss."
34+
# @return [String]
35+
def alert_dismiss_text
36+
first_button.text
37+
end
3638
end
37-
end # module Appium::Android
39+
end

0 commit comments

Comments
 (0)