locatine 0.01084 → 0.01100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locatine/app/background.js +2 -2
- data/lib/locatine/app/content.js +14 -5
- data/lib/locatine/app/manifest.json +1 -1
- data/lib/locatine/data_generate.rb +91 -0
- data/lib/locatine/dialog_actions.rb +71 -0
- data/lib/locatine/dialog_logic.rb +94 -0
- data/lib/locatine/file_work.rb +54 -0
- data/lib/locatine/find_by_guess.rb +62 -0
- data/lib/locatine/find_by_locator.rb +98 -0
- data/lib/locatine/find_by_magic.rb +43 -0
- data/lib/locatine/find_logic.rb +61 -0
- data/lib/locatine/helpers.rb +43 -0
- data/lib/locatine/highlight.rb +41 -0
- data/lib/locatine/merge.rb +36 -0
- data/lib/locatine/public.rb +103 -0
- data/lib/locatine/search.rb +40 -587
- data/lib/locatine/version.rb +8 -3
- data/lib/locatine/xpath_generator.rb +47 -0
- data/lib/locatine.rb +2 -2
- metadata +15 -2
@@ -0,0 +1,43 @@
|
|
1
|
+
module Locatine
|
2
|
+
##
|
3
|
+
# Different methods to make life easier
|
4
|
+
module Helpers
|
5
|
+
private
|
6
|
+
|
7
|
+
def enforce(what, value, *args)
|
8
|
+
if args.last.class == Hash
|
9
|
+
args.last[what] = value
|
10
|
+
else
|
11
|
+
temp = {}
|
12
|
+
temp[what] = value
|
13
|
+
args.push(temp)
|
14
|
+
end
|
15
|
+
find(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def engine
|
19
|
+
(@iframe || @browser)
|
20
|
+
end
|
21
|
+
|
22
|
+
def not_magic_div
|
23
|
+
"[not(@id = 'locatine_magic_div')]"
|
24
|
+
end
|
25
|
+
|
26
|
+
def right_browser
|
27
|
+
Watir::Browser.new(:chrome, switches: ["--load-extension=#{HOME}/app"])
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_string(str, vars)
|
31
|
+
str = str.to_s
|
32
|
+
thevar = str.match(/\#{([^\#{]*)}/)[1] unless str.match(/\#{(.*)}/).nil?
|
33
|
+
return str unless thevar
|
34
|
+
|
35
|
+
value = vars[thevar.to_sym] || vars[thevar]
|
36
|
+
unless value
|
37
|
+
raise ArgumentError, ":#{thevar} must be "\
|
38
|
+
'provided in vars since element was defined with it'
|
39
|
+
end
|
40
|
+
process_string(str.gsub('#{' + thevar + '}', value.to_s), vars)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Locatine
|
2
|
+
##
|
3
|
+
# Locatine can highlight elements
|
4
|
+
module Highlight
|
5
|
+
private
|
6
|
+
|
7
|
+
##
|
8
|
+
# We can highlight an element
|
9
|
+
def highlight(element)
|
10
|
+
script = "arguments[0].setAttribute('locatineclass','foundbylocatine')"
|
11
|
+
ok = !element.stale? && element.exists?
|
12
|
+
engine.execute_script(script, element) if ok
|
13
|
+
rescue StandardError
|
14
|
+
warn " something was found as #{element.selector} but we cannot "\
|
15
|
+
'highlight it'
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# We can unhighlight an element
|
20
|
+
def unhighlight(element)
|
21
|
+
script = "arguments[0].removeAttribute('locatineclass')"
|
22
|
+
ok = !element.stale? && element.exists?
|
23
|
+
engine.execute_script(script, element) if ok
|
24
|
+
rescue StandardError
|
25
|
+
false
|
26
|
+
# watir is not allowing to play with attributes of some elements
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# We can highlight\unhighlight tons of elements at once
|
31
|
+
def mass_highlight_turn(mass, turn_on = true)
|
32
|
+
mass.each do |element|
|
33
|
+
if turn_on
|
34
|
+
highlight element
|
35
|
+
else
|
36
|
+
unhighlight element
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Locatine
|
2
|
+
##
|
3
|
+
# Getting commons of two piles of elements data. To find all similar to them
|
4
|
+
module Merge
|
5
|
+
private
|
6
|
+
|
7
|
+
def select_same(where, hash)
|
8
|
+
where.select do |item|
|
9
|
+
(item['name'] == hash['name']) &&
|
10
|
+
(item['value'] == hash['value']) &&
|
11
|
+
(item['type'] == hash['type'])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def same_entries(array, second, depth, stability_up = false)
|
16
|
+
result = []
|
17
|
+
array.each do |hash|
|
18
|
+
to_add = select_same(second[depth], hash)
|
19
|
+
to_add = stability_bump(to_add, hash) if stability_up
|
20
|
+
result += to_add
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Merging data of two elements (new data is to find both)
|
27
|
+
def get_commons(first, second)
|
28
|
+
second = first if second == {}
|
29
|
+
final = Hash.new { |hash, key| hash[key] = [] }
|
30
|
+
first.each_pair do |depth, array|
|
31
|
+
final[depth] = same_entries(array, second, depth)
|
32
|
+
end
|
33
|
+
final
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Locatine
|
2
|
+
##
|
3
|
+
# Public methods of the Search class
|
4
|
+
module Public
|
5
|
+
##
|
6
|
+
# Creates a new instance of Search
|
7
|
+
#
|
8
|
+
# Params:
|
9
|
+
# +json+ is the name of file to store//read data. Default =>
|
10
|
+
# "./Locatine_files/default.json"
|
11
|
+
#
|
12
|
+
# +depth+ is the value that shows how many data will be stored for element.
|
13
|
+
#
|
14
|
+
# +browser+ is the instance of Watir::Browser. Unless provided it gonna
|
15
|
+
# be created with locatine-app onboard.
|
16
|
+
#
|
17
|
+
# +learn+ shows will locatine ask for assistance from user or will fail
|
18
|
+
# on error. learn is true when LEARN parameter is set in environment.
|
19
|
+
#
|
20
|
+
# +stability_limit+ shows max times attribute should be present to
|
21
|
+
# consider it trusted.
|
22
|
+
#
|
23
|
+
# +scope+ will be used in search (if not provided) defaulkt is "Default"
|
24
|
+
def initialize(json: './Locatine_files/default.json',
|
25
|
+
depth: 3,
|
26
|
+
browser: nil,
|
27
|
+
learn: ENV['LEARN'].nil? ? false : true,
|
28
|
+
stability_limit: 10,
|
29
|
+
scope: 'Default')
|
30
|
+
browser ||= right_browser
|
31
|
+
@browser = browser
|
32
|
+
@json = json
|
33
|
+
@folder = File.dirname(@json)
|
34
|
+
@name = File.basename(@json)
|
35
|
+
@depth = depth
|
36
|
+
@data = read_create
|
37
|
+
@learn = learn
|
38
|
+
@stability_limit = stability_limit
|
39
|
+
@scope = scope
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Looking for the element
|
44
|
+
#
|
45
|
+
# Params:
|
46
|
+
#
|
47
|
+
# +scope+ is a parameter that is used to get information about the
|
48
|
+
# element from @data. Default is "Default"
|
49
|
+
#
|
50
|
+
# +name+ is a parameter that is used to get information about the
|
51
|
+
# element from @data. Must not be nil.
|
52
|
+
#
|
53
|
+
# +exact+ if true locatine will be forced to use only basic search.
|
54
|
+
# Default is false
|
55
|
+
#
|
56
|
+
# +locator+ if not empty it is used for the first attempt to find the
|
57
|
+
# element. Default is {}
|
58
|
+
#
|
59
|
+
# +vars+ hash of variables that will be used for dynamic attributes.
|
60
|
+
# See readme for example
|
61
|
+
#
|
62
|
+
# +look_in+ only elements of that kind will be used. Use Watir::Browser
|
63
|
+
# methods returning collections (:text_fields, :links, :divs, etc.)
|
64
|
+
#
|
65
|
+
# +iframe+ if provided locatine will look for elements inside of it
|
66
|
+
#
|
67
|
+
# +return_locator+ is to return a valid locator of the result
|
68
|
+
#
|
69
|
+
# +collection+ when true an array will be returned. When false - a
|
70
|
+
# single element
|
71
|
+
def find(simple_name = nil,
|
72
|
+
name: nil,
|
73
|
+
scope: nil,
|
74
|
+
exact: false,
|
75
|
+
locator: {},
|
76
|
+
vars: {},
|
77
|
+
look_in: nil,
|
78
|
+
iframe: nil,
|
79
|
+
return_locator: false,
|
80
|
+
collection: false)
|
81
|
+
name = set_name(simple_name, name)
|
82
|
+
@type = look_in
|
83
|
+
@iframe = iframe
|
84
|
+
scope ||= @scope.nil? ? 'Default' : @scope
|
85
|
+
result, attributes = full_search(name, scope, vars, locator, exact)
|
86
|
+
return { xpath: generate_xpath(attributes, vars) } if result &&
|
87
|
+
return_locator
|
88
|
+
return to_subtype(result, collection) if result && !return_locator
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Find alias with return_locator option enforced
|
93
|
+
def lctr(*args)
|
94
|
+
enforce(:return_locator, true, *args)
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Find alias with collection option enforced
|
99
|
+
def collect(*args)
|
100
|
+
enforce(:collection, true, *args)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|