marta 0.28879 → 0.29156
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/marta.rb +3 -0
- data/lib/marta/black_magic.rb +4 -3
- data/lib/marta/data/element.html +4 -0
- data/lib/marta/data/element.js +46 -5
- data/lib/marta/data/for_test.js +1 -1
- data/lib/marta/data/page.html +1 -0
- data/lib/marta/data/style.css +21 -0
- data/lib/marta/dialogs.rb +11 -11
- data/lib/marta/injector.rb +44 -14
- data/lib/marta/public_methods.rb +4 -4
- data/lib/marta/simple_element_finder.rb +23 -4
- data/lib/marta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0d99204224a1b096fe1d9a103ed94c141f33e6
|
4
|
+
data.tar.gz: 92effa54d30743c5718bbcd2fd047143b970e05f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 934ff2dcfa6abf910a4f74be6c95826a36cd5c16b1fb06eb35491c8c02a781672b1bf3804099e04d6d8647bc89bf580f7a53b7d60cf9f7c585bbb71f2d3a46dc
|
7
|
+
data.tar.gz: 4debddeef970b3634ccbd73ddcf29ec0e2d1ea2386f4ed19c7d4ef344c862b0c425510c287bba5b746691373eef345b6375c4f9a75a6fbfe0f34f57f8d27b429
|
data/README.md
CHANGED
@@ -206,7 +206,7 @@ g_page.search "I am in love with selenium."
|
|
206
206
|
|
207
207
|
**Q: What else?**
|
208
208
|
|
209
|
-
*A: Nothing. Marta is under development. Her version is 0.
|
209
|
+
*A: Nothing. Marta is under development. Her version is 0.29156 only. And I am not a professional developer. But I am training her on new tricks.*
|
210
210
|
|
211
211
|
## Internal Design
|
212
212
|
|
data/lib/marta.rb
CHANGED
@@ -25,6 +25,9 @@ module Marta
|
|
25
25
|
include OptionsAndPaths, ReadWrite, Json2Class
|
26
26
|
|
27
27
|
class SmartPage
|
28
|
+
|
29
|
+
attr_accessor :data, :class_name, :edit_mark
|
30
|
+
|
28
31
|
include BlackMagic, XPath, SimpleElementFinder, ClassesCreation,
|
29
32
|
PublicMethods, Dialogs, Injector, Lightning, OptionsAndPaths,
|
30
33
|
Json2Class, ReadWrite, UserValuePrework
|
data/lib/marta/black_magic.rb
CHANGED
@@ -25,9 +25,10 @@ module Marta
|
|
25
25
|
# @note It is believed that no user will use it
|
26
26
|
class MagicFinder < BasicFinder
|
27
27
|
|
28
|
-
def initialize(meth,
|
28
|
+
def initialize(meth, tolerancy, requestor)
|
29
29
|
@tolerancy = tolerancy
|
30
|
-
|
30
|
+
@engine = requestor.engine
|
31
|
+
super(meth, requestor)
|
31
32
|
end
|
32
33
|
|
33
34
|
# We can prefind an element and wait for it.
|
@@ -140,7 +141,7 @@ module Marta
|
|
140
141
|
|
141
142
|
# Marta can find something when data is incorrect (by Black magick)
|
142
143
|
def marta_magic_finder(meth)
|
143
|
-
finder = MagicFinder.new(meth,
|
144
|
+
finder = MagicFinder.new(meth, tolerancy_value, self)
|
144
145
|
finder.find
|
145
146
|
end
|
146
147
|
end
|
data/lib/marta/data/element.html
CHANGED
@@ -21,12 +21,16 @@
|
|
21
21
|
<div martastyle=buttons_holder martaclass=marta_smthing>
|
22
22
|
<input type=button martaclass=marta_smthing id=marta_confirm martastyle=confirm_button onclick=marta_end_loop(); value=Confirm />
|
23
23
|
<input type=button martaclass=marta_smthing id=marta_set_by_hand martastyle=action_button onclick=marta_set_by_hand(); value="Set by hand" />
|
24
|
+
<input type=button martaclass=marta_smthing id=marta_show_html martastyle=action_button onclick=marta_show_html(); value="Find in html" />
|
24
25
|
</div>
|
25
26
|
</div>
|
26
27
|
<div id=marta_s_element_type martaclass=marta_smthing martastyle=options_holder>
|
27
28
|
<div martaclass=marta_smthing class=label id=marta_element_label>What we are looking for (one element or group?)</div>
|
28
29
|
<label martaclass=marta_smthing><input type=checkbox id=marta_array martaclass=marta_smthing>Collection</label>
|
29
30
|
</div>
|
31
|
+
<div martaclass=marta_smthing martastyle=html_content>
|
32
|
+
<div martaclass=marta_smthing id=marta_s_html_holder readonly=true>Enable HTML selector by Find in html button. NOTE: It is highly experimental.</div>
|
33
|
+
</div>
|
30
34
|
<div martastyle=table_headers martaclass=marta_smthing>
|
31
35
|
<input type=text martaclass=marta_smthing martastyle=name_field value=attribute_name disabled=disabled;>
|
32
36
|
<input martaclass=marta_smthing martastyle=value_field type=text value=default_value disabled=disabled;>
|
data/lib/marta/data/element.js
CHANGED
@@ -61,11 +61,7 @@ function marta_change_field(field){
|
|
61
61
|
};
|
62
62
|
|
63
63
|
function marta_clean_up(){
|
64
|
-
var toClear = document.body.querySelectorAll("[martaclass=marta_div]");
|
65
|
-
for (var i = 0; i < toClear.length; i++) {
|
66
|
-
toClear[i].parentNode.removeChild(toClear[i]);
|
67
|
-
};
|
68
|
-
var toClear = document.body.querySelectorAll("[martaclass=marta_script]");
|
64
|
+
var toClear = document.body.querySelectorAll("[martaclass=marta_div],[martaclass=marta_script],[martaclass=marta_style]");
|
69
65
|
for (var i = 0; i < toClear.length; i++) {
|
70
66
|
toClear[i].parentNode.removeChild(toClear[i]);
|
71
67
|
};
|
@@ -119,6 +115,51 @@ function marta_add_data() {
|
|
119
115
|
};
|
120
116
|
};
|
121
117
|
|
118
|
+
function marta_show_html() {
|
119
|
+
var area = document.getElementById("marta_s_html_holder");
|
120
|
+
area.innerHTML = spaninize(document.documentElement.innerHTML);
|
121
|
+
};
|
122
|
+
|
123
|
+
function marta_touch(element) {
|
124
|
+
var control = element.textContent.replace(/</g,"<").replace(/>/g,">");
|
125
|
+
var everything = document.getElementsByTagName("*");
|
126
|
+
for (var i=0, max=everything.length; i < max; i++) {
|
127
|
+
var check = everything[i].outerHTML.replace(/</g,"<").replace(/>/g,">");
|
128
|
+
if (check == control) {
|
129
|
+
everything[i].click();
|
130
|
+
};
|
131
|
+
};
|
132
|
+
};
|
133
|
+
|
134
|
+
function wrap(el, wrapper) {
|
135
|
+
wrapper.appendChild(el.cloneNode(true));
|
136
|
+
el.parentNode.replaceChild(wrapper, el);
|
137
|
+
};
|
138
|
+
|
139
|
+
function spaninize(string) {
|
140
|
+
var dummy = document.createElement( "marta_span" );
|
141
|
+
dummy.innerHTML = string;
|
142
|
+
ignore = dummy.querySelectorAll("[martaclass=marta_div],[martaclass=marta_script],[martaclass=marta_style]");
|
143
|
+
for (var i = 0; i < ignore.length; i++) {
|
144
|
+
ignore[i].parentNode.removeChild(ignore[i]);
|
145
|
+
};
|
146
|
+
dummy.setAttribute("martaclass", "marta_smthng");
|
147
|
+
var counter = {};
|
148
|
+
var everything = dummy.getElementsByTagName("*");
|
149
|
+
for (var i=0, max=everything.length; i < 2*max; i=i+2) {
|
150
|
+
if (counter[everything[i].tagName] == null) {
|
151
|
+
counter[everything[i].tagName] = 0;
|
152
|
+
} else {
|
153
|
+
counter[everything[i].tagName] = counter[everything[i].tagName] + 1;
|
154
|
+
};
|
155
|
+
var wrapper = document.createElement( "marta_span" );
|
156
|
+
wrapper.setAttribute("martaclass","marta_smthing");
|
157
|
+
wrapper.setAttribute("onclick","marta_touch(this);");
|
158
|
+
wrap(everything[i], wrapper);
|
159
|
+
};
|
160
|
+
return dummy.innerHTML.replace(/<(?!.?marta_span)([^>]*)>/g,"<$1>").replace(/marta_span/g,"span");
|
161
|
+
};
|
162
|
+
|
122
163
|
function marta_click_work(e, iframe=false) {
|
123
164
|
if (iframe == false){
|
124
165
|
e = e || window.event;
|
data/lib/marta/data/for_test.js
CHANGED
data/lib/marta/data/page.html
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
<p>So if you have defined <b>something</b> and you wanna use the value of it in the other var you should write <b>#{@something}</b></p>
|
15
15
|
<p>You should set a var with the <b>url</b> name if you are gonna use <b>your_page.open_page</b> method later</p>
|
16
16
|
<p>Your values provided here will be default for your page_object but you can change it like <b>your_page.your_var = newvalue</b></p>
|
17
|
+
<p>NEVER USE AS A VAR NAME:<b>class_name, open_page, data, engine, edit_mark ,method_edit, method_missing</b></p>
|
17
18
|
</div>
|
18
19
|
</div>
|
19
20
|
<div id=marta_s_content martastyle=main_content>
|
data/lib/marta/data/style.css
CHANGED
@@ -212,6 +212,27 @@ div[martastyle=hint] {
|
|
212
212
|
margin: 0 auto;
|
213
213
|
}
|
214
214
|
|
215
|
+
div[martastyle=html_content]{
|
216
|
+
text-align: center;
|
217
|
+
}
|
218
|
+
|
219
|
+
div[martastyle=html_content] div {
|
220
|
+
background-color: #D7F6F5;
|
221
|
+
text-align: center;
|
222
|
+
padding: 5px;
|
223
|
+
border-style: solid;
|
224
|
+
border-width: 1px;
|
225
|
+
width: 90%
|
226
|
+
}
|
227
|
+
|
228
|
+
div[martastyle=html_content] div span {
|
229
|
+
display: block;
|
230
|
+
position: relative;
|
231
|
+
left: 30px;
|
232
|
+
text-align: left;
|
233
|
+
cursor: pointer;
|
234
|
+
}
|
235
|
+
|
215
236
|
div[martaclass=marta_div] b {
|
216
237
|
color: red;
|
217
238
|
}
|
data/lib/marta/dialogs.rb
CHANGED
@@ -21,13 +21,13 @@ module Marta
|
|
21
21
|
# @note It is believed that no user will use it
|
22
22
|
class MethodSpeaker
|
23
23
|
|
24
|
-
include XPath, Lightning, Injector, PublicMethods
|
24
|
+
include XPath, Lightning, Injector, PublicMethods, SimpleElementFinder
|
25
25
|
|
26
|
-
def initialize(
|
27
|
-
@class_name = class_name
|
26
|
+
def initialize(method_name, requestor)
|
27
|
+
@class_name = requestor.class_name
|
28
28
|
@method_name = method_name
|
29
|
-
@data = data
|
30
|
-
@title = class_name+ '.' + method_name.to_s
|
29
|
+
@data = requestor.data
|
30
|
+
@title = @class_name+ '.' + method_name.to_s
|
31
31
|
@requestor = requestor
|
32
32
|
@found = 0
|
33
33
|
@attrs = @data['meths'][@method_name]
|
@@ -35,8 +35,8 @@ module Marta
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Standart question
|
38
|
-
def ask(what, title = 'Some title', data = Hash.new)
|
39
|
-
inject(what, title, data)
|
38
|
+
def ask(what, title = 'Some title', data = Hash.new, vars = Array.new)
|
39
|
+
inject(what, title, data, vars)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Was something stated by user?
|
@@ -69,7 +69,7 @@ module Marta
|
|
69
69
|
xpath_meth_merge
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
# Asking: "What are you looking for?"
|
74
74
|
def ask_for_elements
|
75
75
|
ask 'element', "Found #{@found} elements for #{@title}", @attrs
|
@@ -149,10 +149,10 @@ module Marta
|
|
149
149
|
end
|
150
150
|
|
151
151
|
# Method definition process
|
152
|
-
def user_method_dialogs(
|
153
|
-
dialog_master = MethodSpeaker.new(
|
152
|
+
def user_method_dialogs(method_name)
|
153
|
+
dialog_master = MethodSpeaker.new(method_name, self)
|
154
154
|
data = dialog_master.dialog
|
155
|
-
file_write(
|
155
|
+
file_write(self.class_name.to_s, data)
|
156
156
|
data
|
157
157
|
end
|
158
158
|
end
|
data/lib/marta/injector.rb
CHANGED
@@ -16,12 +16,19 @@ module Marta
|
|
16
16
|
class Syringe
|
17
17
|
|
18
18
|
def initialize(engine, marta_what, title = 'Something important',
|
19
|
-
old_data = Hash.new, folder = gem_libdir
|
19
|
+
old_data = Hash.new, folder = gem_libdir,
|
20
|
+
custom_vars = Array.new, custom_scripts = Array.new)
|
20
21
|
@what = marta_what
|
21
22
|
@title = title
|
22
23
|
@data = old_data
|
24
|
+
@data ||= Hash.new
|
23
25
|
@engine = engine
|
24
26
|
@folder = folder
|
27
|
+
@custom_vars = custom_vars
|
28
|
+
@custom_scripts = custom_scripts
|
29
|
+
@default_vars = [{"marta_what": "\"#{@title}\""},
|
30
|
+
{"old_marta_Data": @data.to_s.gsub('=>',':').gsub('nil','null')}]
|
31
|
+
@default_scripts = ["marta_add_data();"]
|
25
32
|
end
|
26
33
|
|
27
34
|
# "first" or "last".
|
@@ -38,22 +45,22 @@ module Marta
|
|
38
45
|
newMartaObject.innerHTML = '#{inner}';
|
39
46
|
document.body.insertBefore(newMartaObject,document.body.#{where}Child);
|
40
47
|
JS
|
41
|
-
|
48
|
+
@engine.execute_script script.gsub("\n",'')
|
42
49
|
end
|
43
50
|
|
44
51
|
# Taking a correct js file to inject
|
45
52
|
def js
|
46
|
-
File.read(@folder + "/data/#{@what}.js")
|
53
|
+
File.read(@folder + "/data/#{@what}.js")
|
47
54
|
end
|
48
55
|
|
49
56
|
# Taking a correct html file to inject
|
50
57
|
def html
|
51
|
-
File.read(@folder + "/data/#{@what}.html")
|
58
|
+
File.read(@folder + "/data/#{@what}.html")
|
52
59
|
end
|
53
60
|
|
54
61
|
# Taking a correct css file to inject
|
55
62
|
def style
|
56
|
-
File.read(@folder + "/data/style.css")
|
63
|
+
File.read(@folder + "/data/style.css")
|
57
64
|
end
|
58
65
|
|
59
66
|
# Injecting everything to the page
|
@@ -63,17 +70,38 @@ module Marta
|
|
63
70
|
insert_to_page('style', style, false)
|
64
71
|
end
|
65
72
|
|
73
|
+
# Syringe sets javascript variables
|
74
|
+
def set_var(var, value)
|
75
|
+
insert_to_page('script', "var #{var} = #{value};", false)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Syringe runs scripts
|
79
|
+
def run_script(script)
|
80
|
+
@engine.execute_script(script)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Syringe takes array of hashes to set lots of variables
|
84
|
+
def set_vars(vars_array)
|
85
|
+
vars_array.each do |var_hash|
|
86
|
+
var_hash.each_pair do |var_name, var_value|
|
87
|
+
set_var var_name.to_s, var_value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Syringe can run an array of scripts
|
93
|
+
def all_scripts(scripts_array)
|
94
|
+
scripts_array.each do |script|
|
95
|
+
run_script script
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
66
99
|
# It is never used without get_result.
|
67
100
|
# But it can be used to show some message for user
|
68
101
|
def actual_injection
|
69
102
|
files_to_page
|
70
|
-
@
|
71
|
-
|
72
|
-
insert_to_page('script',
|
73
|
-
"var old_marta_Data = #{@data}".gsub('=>',':').
|
74
|
-
gsub('nil','null'),
|
75
|
-
false)
|
76
|
-
@engine.execute_script("marta_add_data();")
|
103
|
+
set_vars(@default_vars + @custom_vars)
|
104
|
+
all_scripts(@default_scripts + @custom_scripts)
|
77
105
|
end
|
78
106
|
|
79
107
|
# Retrieving result if js var = marta_confirm_mark is true
|
@@ -94,8 +122,10 @@ module Marta
|
|
94
122
|
end
|
95
123
|
|
96
124
|
# That's how Marta is injecting and retrieving result
|
97
|
-
def inject(what, title = 'Something important', data = Hash.new
|
98
|
-
|
125
|
+
def inject(what, title = 'Something important', data = Hash.new,
|
126
|
+
custom_vars = Array.new, custom_scripts = Array.new)
|
127
|
+
syringe = Syringe.new(engine, what, title, data, gem_libdir,
|
128
|
+
custom_vars, custom_scripts)
|
99
129
|
syringe.actual_injection
|
100
130
|
syringe.get_result
|
101
131
|
end
|
data/lib/marta/public_methods.rb
CHANGED
@@ -10,12 +10,12 @@ module Marta
|
|
10
10
|
#
|
11
11
|
# User can create pageobject class using SmartPage.new
|
12
12
|
#
|
13
|
-
# SmartPage can be created
|
13
|
+
# SmartPage can be created without all the data. But in that case
|
14
14
|
# it will be pretty useless until values are provided
|
15
15
|
#
|
16
|
-
# The first argument is a class name. It is a constant
|
16
|
+
# The first argument is a class name. It is a constant-like string like
|
17
17
|
# "MyClass". All data provided will be stored in MyClass.json
|
18
|
-
# Once created that way you can call it like MyClass.new.
|
18
|
+
# Once it is created that way you can call it like MyClass.new.
|
19
19
|
# That argument is totally necessary one
|
20
20
|
#
|
21
21
|
# The second argument is a marta's special data hash. By default =
|
@@ -41,7 +41,7 @@ module Marta
|
|
41
41
|
def method_edit(name)
|
42
42
|
method_name = correct_name(name)
|
43
43
|
exact_name = method_name.to_s + "_exact"
|
44
|
-
data = user_method_dialogs(
|
44
|
+
data = user_method_dialogs(method_name)
|
45
45
|
define_singleton_method method_name.to_sym do |meth_content=@data['meths'][method_name]|
|
46
46
|
marta_magic_finder(meth_content)
|
47
47
|
end
|
@@ -18,11 +18,11 @@ module Marta
|
|
18
18
|
|
19
19
|
include XPath
|
20
20
|
|
21
|
-
def initialize(meth,
|
21
|
+
def initialize(meth, requestor)
|
22
22
|
@requestor = requestor
|
23
23
|
@meth = meth
|
24
|
-
@xpath = xpath_by_meth
|
25
|
-
@engine = engine
|
24
|
+
@xpath = xpath_by_meth if !@meth.nil?
|
25
|
+
@engine = requestor.engine
|
26
26
|
end
|
27
27
|
|
28
28
|
# Maybe our element is defined as a collection?
|
@@ -73,11 +73,30 @@ module Marta
|
|
73
73
|
subtype_of prefind
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
# Sometimes we need to find out what is hidden
|
78
|
+
def find_invisibles
|
79
|
+
result = Array.new
|
80
|
+
all = @engine.elements
|
81
|
+
all.each do |element|
|
82
|
+
if element.exists? and !element.visible?
|
83
|
+
result.push element
|
84
|
+
else
|
85
|
+
x, y = element.wd.location.x + 1, element.wd.location.y + 1
|
86
|
+
element_on_point = @engine.
|
87
|
+
execute_script "return document.elementFromPoint(#{x}, #{y})"
|
88
|
+
if element_on_point != element
|
89
|
+
result.push element
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
return result
|
94
|
+
end
|
76
95
|
end
|
77
96
|
|
78
97
|
# We can simply find something
|
79
98
|
def marta_simple_finder(meth)
|
80
|
-
finder = BasicFinder.new(meth,
|
99
|
+
finder = BasicFinder.new(meth, self)
|
81
100
|
finder.find
|
82
101
|
end
|
83
102
|
end
|
data/lib/marta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.29156'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Seleznev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|