qfunction 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/Rakefile +11 -0
- data/lib/HTMLElement.rb +424 -0
- data/lib/assertions.rb +293 -0
- data/lib/sfunction.rb +127 -0
- data/qfunction.gemspec +30 -0
- metadata +75 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('qfunction', '0.0.1') do |p|
|
6
|
+
p.description = "Funciton"
|
7
|
+
p.author = "QuangMV, Cyworld Vietnam, 5th Floor, 447 Lac Long Quan Street, Tay Ho Dist, Hanoi, Vietnam"
|
8
|
+
p.email = "quangnnt@gmail.com"
|
9
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
10
|
+
p.development_dependencies = []
|
11
|
+
end
|
data/lib/HTMLElement.rb
ADDED
@@ -0,0 +1,424 @@
|
|
1
|
+
#B: HTML
|
2
|
+
|
3
|
+
#Goto url
|
4
|
+
def goto(url)
|
5
|
+
$ff.goto(url)
|
6
|
+
end
|
7
|
+
|
8
|
+
#Refresh
|
9
|
+
def refresh
|
10
|
+
$ff.refresh
|
11
|
+
end
|
12
|
+
|
13
|
+
def xxx
|
14
|
+
$ff.close
|
15
|
+
end
|
16
|
+
|
17
|
+
#Link
|
18
|
+
def clickLinktext(text)
|
19
|
+
waitExists($ff.link(:text,text))
|
20
|
+
$ff.link(:text,text).click
|
21
|
+
end
|
22
|
+
|
23
|
+
def clickLinkid(text)
|
24
|
+
waitExists($ff.link(:id,text))
|
25
|
+
$ff.link(:id,text).click
|
26
|
+
end
|
27
|
+
|
28
|
+
def clickLinkhref(name)
|
29
|
+
waitExists($ff.link(:href,name))
|
30
|
+
$ff.link(:href,name).click
|
31
|
+
end
|
32
|
+
|
33
|
+
def clickLinktitle(text)
|
34
|
+
waitExists($ff.link(:title,text))
|
35
|
+
$ff.link(:title,text).click
|
36
|
+
end
|
37
|
+
|
38
|
+
def clickLinkclass(text)
|
39
|
+
waitExists($ff.link(:class,text))
|
40
|
+
$ff.link(:class,text).click
|
41
|
+
end
|
42
|
+
|
43
|
+
#Button
|
44
|
+
def clickButtonid(text)
|
45
|
+
waitExists($ff.button(:id,text))
|
46
|
+
$ff.button(:id,text).click
|
47
|
+
end
|
48
|
+
|
49
|
+
def clickButtonname(text)
|
50
|
+
waitExists($ff.button(:name,text))
|
51
|
+
$ff.button(:name,text).click
|
52
|
+
end
|
53
|
+
|
54
|
+
#Image
|
55
|
+
def clickImagesrc(text)
|
56
|
+
waitExists($ff.image(:src,text))
|
57
|
+
$ff.image(:src,text).click
|
58
|
+
end
|
59
|
+
|
60
|
+
#Textfield
|
61
|
+
#Set TextField "ID"<br>
|
62
|
+
#type = 1: set(d)<br>
|
63
|
+
#type = 2:value<br>
|
64
|
+
#type = 3:append<br>
|
65
|
+
#type = 4:focus<br>
|
66
|
+
def setTextfieldid(text1,text2,type=1)
|
67
|
+
waitExists($ff.text_field(:id,text1))
|
68
|
+
if type == 1 then
|
69
|
+
$ff.text_field(:id,text1).set(text2)
|
70
|
+
elsif type == 2 then
|
71
|
+
$ff.text_field(:id,text1).value = text2
|
72
|
+
elsif type == 3 then
|
73
|
+
$ff.text_field(:id,text1).append(text2)
|
74
|
+
elsif type == 4 then
|
75
|
+
$ff.text_field(:id,text1).focus
|
76
|
+
end
|
77
|
+
end
|
78
|
+
#Set TextField (Name),<br>
|
79
|
+
#text1 = name,<br>
|
80
|
+
#text2 = String,<br>
|
81
|
+
#type = 1: set(d),<br>
|
82
|
+
#type = 2:value,<br>
|
83
|
+
#type = 3:append<br>
|
84
|
+
def setTextfieldname(text1,text2,type=1)
|
85
|
+
|
86
|
+
waitExists($ff.text_field(:name,text1))
|
87
|
+
if type == 1 then
|
88
|
+
$ff.text_field(:name,text1).set(text2)
|
89
|
+
elsif type == 2 then
|
90
|
+
$ff.text_field(:name,text1).value = text2
|
91
|
+
else $ff.text_field(:name,text1).append(text2)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
#Set TextField (Class),<br>
|
96
|
+
#text1 = name,<br>
|
97
|
+
#text2 = String,<br>
|
98
|
+
#type = 1: set(d),<br>
|
99
|
+
#type = 2:value,<br>
|
100
|
+
#type = 3:append<br>
|
101
|
+
def setTextfieldclass(text1,text2,type=1)
|
102
|
+
|
103
|
+
waitExists($ff.text_field(:class,text1))
|
104
|
+
if type == 1 then
|
105
|
+
$ff.text_field(:class,text1).set(text2)
|
106
|
+
elsif type == 2 then
|
107
|
+
$ff.text_field(:class,text1).value = text2
|
108
|
+
else $ff.text_field(:class,text1).append(text2)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def verifyTextfieldid(text1,text2)
|
113
|
+
waitExists( $ff.text_field(:id,text1) )
|
114
|
+
assert($ff.text_field(:id, text1).verify_contains(text2) )
|
115
|
+
end
|
116
|
+
|
117
|
+
def verifyTextfieldname(text1,text2)
|
118
|
+
waitExists( $ff.text_field(:name,text1) )
|
119
|
+
assert($ff.text_field(:name, text1).verify_contains(text2) )
|
120
|
+
end
|
121
|
+
|
122
|
+
#Filefield
|
123
|
+
def setfilefieldid(text1,text2)
|
124
|
+
waitExists($ff.file_field(:id,text1))
|
125
|
+
$ff.file_field(:id,text1).set(text2)
|
126
|
+
end
|
127
|
+
|
128
|
+
def setfilefieldname(text1,text2)
|
129
|
+
waitExists($ff.file_field(:name,text1))
|
130
|
+
$ff.file_field(:name,text1).set(text2)
|
131
|
+
end
|
132
|
+
|
133
|
+
#Form
|
134
|
+
def submitFormid(text)
|
135
|
+
waitExists($ff.form(:id,text))
|
136
|
+
$ff.form(:id,text).submit
|
137
|
+
end
|
138
|
+
|
139
|
+
def getFormid(text)
|
140
|
+
waitExists($ff.form(:id,text))
|
141
|
+
return $ff.form(:id,text)
|
142
|
+
end
|
143
|
+
|
144
|
+
def getFormaction(text)
|
145
|
+
waitExists($ff.form(:action,text))
|
146
|
+
nwait(1)
|
147
|
+
sleep(1)
|
148
|
+
return $ff.form(:action,text)
|
149
|
+
end
|
150
|
+
|
151
|
+
#Frame
|
152
|
+
def getFrameid(text)
|
153
|
+
waitExists($ff.frame(:id,text))
|
154
|
+
return $ff.frame(:id,text)
|
155
|
+
end
|
156
|
+
|
157
|
+
def getFrameindex(text)
|
158
|
+
waitExists($ff.frame(:index,text))
|
159
|
+
return $ff.frame(:index,text)
|
160
|
+
end
|
161
|
+
|
162
|
+
def getFramesrc(text)
|
163
|
+
waitExists($ff.frame(:src,text))
|
164
|
+
return $ff.frame(:src,text)
|
165
|
+
end
|
166
|
+
|
167
|
+
#Table
|
168
|
+
def getTableid(text)
|
169
|
+
waitExists( $ff.table(:id,text) )
|
170
|
+
sleep(1)
|
171
|
+
return $ff.table(:id,text)
|
172
|
+
end
|
173
|
+
|
174
|
+
#Div
|
175
|
+
def getDivclass(text)
|
176
|
+
waitExists( $ff.div(:class,text) )
|
177
|
+
nwait(1)
|
178
|
+
return $ff.div(:class,text)
|
179
|
+
end
|
180
|
+
|
181
|
+
def getDivid(text)
|
182
|
+
waitExists( $ff.div(:id,text) )
|
183
|
+
nwait(2)
|
184
|
+
return $ff.div(:id,text)
|
185
|
+
end
|
186
|
+
|
187
|
+
def clickDivid(text)
|
188
|
+
i = 0
|
189
|
+
begin
|
190
|
+
$ff.div(:id , text).click
|
191
|
+
rescue Exception => e
|
192
|
+
sleep(1)
|
193
|
+
i = i + 1
|
194
|
+
if i < $timeout then retry
|
195
|
+
else
|
196
|
+
puts e.exception
|
197
|
+
#~ puts e.backtrace
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#Span
|
203
|
+
def clickSpanid(text)
|
204
|
+
i = 0
|
205
|
+
begin
|
206
|
+
$ff.span(:id , text).click
|
207
|
+
rescue Exception => e
|
208
|
+
sleep(1)
|
209
|
+
i = i + 1
|
210
|
+
if i < $timeout then retry
|
211
|
+
else
|
212
|
+
puts e.exception
|
213
|
+
#~ puts e.backtrace
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def clickSpanclass(text)
|
219
|
+
i = 0
|
220
|
+
begin
|
221
|
+
$ff.span(:class , text).click
|
222
|
+
rescue Exception => e
|
223
|
+
sleep(1)
|
224
|
+
i = i + 1
|
225
|
+
if i < $timeout then retry
|
226
|
+
else
|
227
|
+
puts e.exception
|
228
|
+
#~ puts e.backtrace
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def clickSpanxpath(text)
|
234
|
+
i = 0
|
235
|
+
begin
|
236
|
+
$ff.span(:xpath , text).click
|
237
|
+
rescue Exception => e
|
238
|
+
sleep(1)
|
239
|
+
i = i + 1
|
240
|
+
if i < $timeout then retry
|
241
|
+
else
|
242
|
+
puts e.exception
|
243
|
+
#~ puts e.backtrace
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
#Checkbox
|
249
|
+
def setCheckboxid(name)
|
250
|
+
waitExists($ff.checkbox(:id,name))
|
251
|
+
$ff.checkbox(:id,name).set
|
252
|
+
end
|
253
|
+
|
254
|
+
def setCheckboxname(name)
|
255
|
+
waitExists($ff.checkbox(:name,name))
|
256
|
+
$ff.checkbox(:name,name).set
|
257
|
+
end
|
258
|
+
|
259
|
+
def setCheckboxvalue(name)
|
260
|
+
waitExists($ff.checkbox(:value,name))
|
261
|
+
$ff.checkbox(:value,name).set
|
262
|
+
end
|
263
|
+
|
264
|
+
def clearCheckboxid(name)
|
265
|
+
waitExists($ff.checkbox(:id,name))
|
266
|
+
$ff.checkbox(:id,name).clear
|
267
|
+
end
|
268
|
+
|
269
|
+
#Select_list:<br>
|
270
|
+
#type = 1: text(d),<br>
|
271
|
+
#type = 2: value,<br>
|
272
|
+
def setSelectlistid(name,value,type=1)
|
273
|
+
waitExists($ff.select_list(:id,name))
|
274
|
+
if type == 1 then
|
275
|
+
$ff.select_list(:id,name).select(value)
|
276
|
+
elsif type == 2 then
|
277
|
+
$ff.select_list(:id,name).select_value(value)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
def getSelectlistid(text)
|
282
|
+
waitExists($ff.select_list(:id,text))
|
283
|
+
nwait(1)
|
284
|
+
return $ff.select_list(:id,text)
|
285
|
+
end
|
286
|
+
|
287
|
+
#Radio
|
288
|
+
def setRadiovalue(value)
|
289
|
+
waitExists($ff.radio(:value,value))
|
290
|
+
$ff.radio(:value,value).set
|
291
|
+
end
|
292
|
+
|
293
|
+
def setRadioid(id)
|
294
|
+
waitExists($ff.radio(:id,id))
|
295
|
+
$ff.radio(:id,id).set
|
296
|
+
end
|
297
|
+
#Alert
|
298
|
+
def clickalertLinktext(name)
|
299
|
+
waitExists($ff.link(:text,name))
|
300
|
+
$ff.startClicker("OK")
|
301
|
+
$ff.link(:text,name).click
|
302
|
+
end
|
303
|
+
|
304
|
+
def clickalertLinkid(name)
|
305
|
+
waitExists($ff.link(:id,name))
|
306
|
+
$ff.startClicker("OK")
|
307
|
+
$ff.link(:id,name).click
|
308
|
+
end
|
309
|
+
|
310
|
+
def clickalertLinktitle(name)
|
311
|
+
waitExists($ff.link(:title,name))
|
312
|
+
$ff.startClicker("OK")
|
313
|
+
$ff.link(:title,name).click
|
314
|
+
end
|
315
|
+
|
316
|
+
def clickalertLinkclass(name)
|
317
|
+
waitExists($ff.link(:class,name))
|
318
|
+
$ff.startClicker("OK")
|
319
|
+
$ff.link(:class,name).click
|
320
|
+
end
|
321
|
+
|
322
|
+
def clickalertButtonid(name)
|
323
|
+
waitExists($ff.button(:id,name))
|
324
|
+
$ff.startClicker("OK")
|
325
|
+
$ff.button(:id,name).click
|
326
|
+
end
|
327
|
+
|
328
|
+
def clickalertButtonname(name)
|
329
|
+
waitExists($ff.button(:name,name))
|
330
|
+
$ff.startClicker("OK")
|
331
|
+
$ff.button(:name,name).click
|
332
|
+
end
|
333
|
+
|
334
|
+
def clickalertElement(name)
|
335
|
+
waitExists(name)
|
336
|
+
$ff.startClicker("OK")
|
337
|
+
name.click
|
338
|
+
end
|
339
|
+
|
340
|
+
def clickalertImagesrc(text)
|
341
|
+
waitExists( $ff.image(:src,text) )
|
342
|
+
$ff.startClicker("OK")
|
343
|
+
$ff.image(:src,text).click
|
344
|
+
sleep(2)
|
345
|
+
end
|
346
|
+
|
347
|
+
def clickalertImageid(text)
|
348
|
+
waitExists( $ff.image(:id,text) )
|
349
|
+
$ff.startClicker("OK")
|
350
|
+
$ff.image(:id,text).click
|
351
|
+
sleep(2)
|
352
|
+
end
|
353
|
+
|
354
|
+
def click_javascript_button()
|
355
|
+
path = File.join(File.dirname(__FILE__), "javascriptPopup.rb")
|
356
|
+
Thread.new { system("ruby \"#{path}\"") }
|
357
|
+
yield
|
358
|
+
sleep(3)
|
359
|
+
end
|
360
|
+
|
361
|
+
#E: Alert
|
362
|
+
|
363
|
+
def nwait(n=1)
|
364
|
+
for i in 1..n
|
365
|
+
$ff.wait
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
#Attach
|
370
|
+
def getAttachurl(url)
|
371
|
+
i = 0
|
372
|
+
begin
|
373
|
+
ff1 = $ff.attach(:url,url)
|
374
|
+
rescue Exception => e
|
375
|
+
sleep(1)
|
376
|
+
i = i + 1
|
377
|
+
if i <= $timeout then retry
|
378
|
+
else
|
379
|
+
puts e.exception
|
380
|
+
#~ puts e.backtrace
|
381
|
+
end
|
382
|
+
end
|
383
|
+
if i <= $timeout then
|
384
|
+
return ff1
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
def getAttachtitle(title)
|
389
|
+
i = 0
|
390
|
+
begin
|
391
|
+
ff1 = $ff.attach(:title,title)
|
392
|
+
rescue Exception => e
|
393
|
+
sleep(1)
|
394
|
+
i = i + 1
|
395
|
+
if i <= 20 then retry
|
396
|
+
else
|
397
|
+
puts e.exception
|
398
|
+
#~ puts e.backtrace
|
399
|
+
end
|
400
|
+
end
|
401
|
+
if i <= 20 then
|
402
|
+
return ff1
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
#Javascript event:<br>
|
407
|
+
#type = 1: onMouseOver(d)
|
408
|
+
def fire_event(element,type = 1)
|
409
|
+
waitExists(element)
|
410
|
+
if type == 1 then
|
411
|
+
element.fire_event("onMouseOver")
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
#Wait Element show use class Waiter
|
416
|
+
def wait_ut(text)
|
417
|
+
Watir::Waiter.wait_until($timeout) { text }
|
418
|
+
end
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
data/lib/assertions.rb
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
|
2
|
+
#E: Assert
|
3
|
+
#Assertion text in page
|
4
|
+
def assertText(text)
|
5
|
+
i = 0
|
6
|
+
while !$ff.contains_text(text) do
|
7
|
+
sleep(1)
|
8
|
+
if i==$timeout then
|
9
|
+
# assert($ff.contains_text(text))
|
10
|
+
# break;
|
11
|
+
end
|
12
|
+
i=i+1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#Assert False text in page
|
17
|
+
def assertfalseText(text)
|
18
|
+
i = 0
|
19
|
+
while $ff.contains_text(text) do
|
20
|
+
sleep(1)
|
21
|
+
if i>=$timeout then
|
22
|
+
assert_false($ff.contains_text(text))
|
23
|
+
break;
|
24
|
+
end
|
25
|
+
i=i+1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#Assert Equal<br>
|
30
|
+
#type = 1:text(default)<br>
|
31
|
+
#type = 2:title<br>
|
32
|
+
#type = 3:url<br>
|
33
|
+
#type = 4:value<br>
|
34
|
+
#type = 5:maxlength<br>
|
35
|
+
def assertEqual(value1,value2,type=1)
|
36
|
+
i = 0
|
37
|
+
if type == 1 then
|
38
|
+
begin
|
39
|
+
assert_equal(value1, value2.text)
|
40
|
+
rescue Exception => e
|
41
|
+
sleep(1)
|
42
|
+
i += 1
|
43
|
+
if i < $timeout then retry
|
44
|
+
end
|
45
|
+
assert_equal(value1, value2.text)
|
46
|
+
end
|
47
|
+
elsif type == 2 then
|
48
|
+
begin
|
49
|
+
assert_equal(value1, value2.title)
|
50
|
+
rescue
|
51
|
+
sleep(1)
|
52
|
+
i += 1
|
53
|
+
if i <= $timeout+1 then retry
|
54
|
+
end
|
55
|
+
end
|
56
|
+
elsif type == 3 then
|
57
|
+
begin
|
58
|
+
assert_equal(value1, value2.url)
|
59
|
+
rescue
|
60
|
+
sleep(1)
|
61
|
+
i += 1
|
62
|
+
if i <= $timeout+1 then retry
|
63
|
+
end
|
64
|
+
end
|
65
|
+
elsif type == 4 then
|
66
|
+
begin
|
67
|
+
assert_equal(value1, value2.value)
|
68
|
+
rescue
|
69
|
+
sleep(1)
|
70
|
+
i += 1
|
71
|
+
if i <= $timeout+1 then retry
|
72
|
+
end
|
73
|
+
end
|
74
|
+
elsif type == 5 then
|
75
|
+
begin
|
76
|
+
assert_equal(value1, value2.maxlength)
|
77
|
+
rescue
|
78
|
+
sleep(1)
|
79
|
+
i += 1
|
80
|
+
if i <= $timeout+1 then retry
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
puts "assertEqual :#{i}" if i != 0
|
85
|
+
end
|
86
|
+
|
87
|
+
#Assert Equal False,<br>
|
88
|
+
#value1 = "String",<br>
|
89
|
+
#value2 = $ff.text,<br>
|
90
|
+
#type = 1:text(default),<br>
|
91
|
+
#type = 2:title,<br>
|
92
|
+
#type = 3:url<br>
|
93
|
+
#type = 4:value<br>
|
94
|
+
def assertfalseEqual(value1,value2,type=1)
|
95
|
+
i = 0
|
96
|
+
if type == 1 then
|
97
|
+
while value2.text == value1 do
|
98
|
+
sleep(1)
|
99
|
+
if i >= $timeout then
|
100
|
+
assert_equal("Timeout assertfalseEqual", value2.text)
|
101
|
+
break;
|
102
|
+
end
|
103
|
+
i += 1
|
104
|
+
end
|
105
|
+
elsif type == 2 then
|
106
|
+
while value2.title == value1 do
|
107
|
+
sleep(1)
|
108
|
+
if i >= $timeout then
|
109
|
+
assert_equal("Timeout assertfalseEqual", value2.title)
|
110
|
+
break;
|
111
|
+
end
|
112
|
+
i += 1
|
113
|
+
end
|
114
|
+
elsif type == 3 then
|
115
|
+
while value2.url == value1 do
|
116
|
+
sleep(1)
|
117
|
+
if i >= $timeout then
|
118
|
+
assert_equal("Timeout assertfalseEqual", value2.url)
|
119
|
+
break;
|
120
|
+
end
|
121
|
+
i += 1
|
122
|
+
end
|
123
|
+
elsif type == 4 then
|
124
|
+
while value2.value == value1 do
|
125
|
+
sleep(1)
|
126
|
+
if i >= $timeout then
|
127
|
+
assert_equal("Timeout assertfalseEqual", value2.value)
|
128
|
+
break;
|
129
|
+
end
|
130
|
+
i += 1
|
131
|
+
end
|
132
|
+
end
|
133
|
+
puts "assertfalseEqual :#{i}" if i != 0
|
134
|
+
end
|
135
|
+
|
136
|
+
#Wait Element show
|
137
|
+
def waitExists(text,type = 1)
|
138
|
+
i = 0
|
139
|
+
if type == 1 then
|
140
|
+
while !text.exists? do
|
141
|
+
sleep(1)
|
142
|
+
i +=1
|
143
|
+
if i>=$timeout then
|
144
|
+
assert( text.exists? )
|
145
|
+
break;
|
146
|
+
end
|
147
|
+
end
|
148
|
+
puts "WaitExists: #{i}" if i != 0
|
149
|
+
else
|
150
|
+
begin
|
151
|
+
assert( text.click )
|
152
|
+
rescue
|
153
|
+
puts i
|
154
|
+
sleep(1)
|
155
|
+
i += 1
|
156
|
+
retry if i <= $timeout
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
#Wait Element none
|
162
|
+
def waitfalseExists(text)
|
163
|
+
i = 0
|
164
|
+
while text.exists? do
|
165
|
+
sleep(1)
|
166
|
+
if i>=$timeout then
|
167
|
+
assert(text.exists?)
|
168
|
+
break;
|
169
|
+
end
|
170
|
+
i +=1
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
#tags = 1: Link(d)<br>
|
175
|
+
#tags = 2: Button<br>
|
176
|
+
#tags = 3: Table<br>
|
177
|
+
#tags = 4: Textfield<br>
|
178
|
+
#tags = 5: Div<br>
|
179
|
+
def falseExistsid(text,tags=1)
|
180
|
+
if tags == 1 then
|
181
|
+
i = 0
|
182
|
+
while $ff.link(:id,text).exists? do
|
183
|
+
sleep(1)
|
184
|
+
i +=1
|
185
|
+
if i>=10 then
|
186
|
+
assert(!$ff.link(:id,text).exists?)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
puts "falseExistsid :#{i}" if i != 0
|
190
|
+
elsif tags == 2 then
|
191
|
+
i = 0
|
192
|
+
while $ff.button(:id,text).exists? do
|
193
|
+
sleep(1)
|
194
|
+
i +=1
|
195
|
+
if i>=10 then
|
196
|
+
assert(!$ff.button(:id,text).exists?)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
elsif tags == 3 then
|
200
|
+
i = 0
|
201
|
+
while $ff.table(:id,text).exists? do
|
202
|
+
sleep(1)
|
203
|
+
i +=1
|
204
|
+
if i>=10 then
|
205
|
+
assert(!$ff.table(:id,text).exists?)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
elsif tags == 4 then
|
209
|
+
i = 0
|
210
|
+
while $ff.text_field(:id,text).exists? do
|
211
|
+
sleep(1)
|
212
|
+
i +=1
|
213
|
+
if i>=10 then
|
214
|
+
assert(!$ff.text_field(:id,text).exists?)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
#tags = 1: Link(d)
|
222
|
+
def falseExiststext(text,tags=1)
|
223
|
+
if tags == 1 then
|
224
|
+
i = 0
|
225
|
+
while $ff.link(:text,text).exists? do
|
226
|
+
sleep(1)
|
227
|
+
i +=1
|
228
|
+
if i>=10 then
|
229
|
+
assert(!$ff.link(:text,text).exists?)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
puts "falseExiststext :#{i}" if i != 0
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
#tags = 1: Link(d)
|
237
|
+
def falseExistsclass(text,tags=1)
|
238
|
+
if tags == 1 then
|
239
|
+
i = 0
|
240
|
+
while $ff.link(:class,text).exists? do
|
241
|
+
sleep(1)
|
242
|
+
i +=1
|
243
|
+
if i>=10 then
|
244
|
+
assert(!$ff.link(:class,text).exists?)
|
245
|
+
break;
|
246
|
+
end
|
247
|
+
end
|
248
|
+
puts "falseExistsclass :#{i}" if i != 0
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
#tags = 1: Link(d)
|
254
|
+
def falseExistshref(text,tags=1)
|
255
|
+
if tags == 1 then
|
256
|
+
i = 0
|
257
|
+
while $ff.link(:href,text).exists? do
|
258
|
+
sleep(1)
|
259
|
+
i +=1
|
260
|
+
if i>=10 then
|
261
|
+
assert(!$ff.link(:href,text).exists?)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
puts "falseExistshref :#{i}" if i != 0
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
#tags = 1: Link(d)
|
269
|
+
def falseExistsindex(browser,text,tags=1)
|
270
|
+
if tags == 1 then
|
271
|
+
i = 0
|
272
|
+
while browser.link(:index,text).exists? do
|
273
|
+
sleep(1)
|
274
|
+
i +=1
|
275
|
+
if i>=10 then
|
276
|
+
assert(!browser.link(:index,text).exists?)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
puts "falseExistsindex :#{i}" if i != 0
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def returnwaitExists(text)
|
284
|
+
sleep(0.5)
|
285
|
+
nwait(1)
|
286
|
+
if text.exists? then
|
287
|
+
return true
|
288
|
+
else
|
289
|
+
return false
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
#E: Assert
|
data/lib/sfunction.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
def decoder(n)
|
3
|
+
str = [" ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";",
|
4
|
+
"<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
|
5
|
+
"[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
|
6
|
+
"y","z","{","|","}","~" ]
|
7
|
+
for i in 32..126
|
8
|
+
if n == i then return "#{str[i-32]}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#i=1: 0-9,a-z,A-Z<br>
|
14
|
+
#i=2: -_ <br>
|
15
|
+
#i=3: a-z,A-Z<br>
|
16
|
+
#i=4: 0-9<br>
|
17
|
+
#i=41: 0-9 <br>
|
18
|
+
#i=5: @domain<br>
|
19
|
+
#i=10: Ho va Ten<br>
|
20
|
+
def getRandomString(n,i)
|
21
|
+
str = ""
|
22
|
+
|
23
|
+
str1 = ["0","1","2","3","4","5","6","7","8","9",
|
24
|
+
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
|
25
|
+
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
|
26
|
+
"y","z"]
|
27
|
+
|
28
|
+
str2 = ["-","","_",""]
|
29
|
+
|
30
|
+
str3 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
|
31
|
+
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
|
32
|
+
|
33
|
+
str4 = ["0","1","2","3","4","5","6","7","8","9"]
|
34
|
+
str41 = ["0","1","2","3","4","5","6","7","8","9","","","","","","","","","",""]
|
35
|
+
|
36
|
+
str5 = ["@yahoo.com.vn","@gmail.com","@yahoo.com","@msn.com","@hotmail.com","@zing.vn","@google.com.vn","@dantri.com",
|
37
|
+
"@vnexpress.net","@mail.com","@abc.com","@live.com"]
|
38
|
+
|
39
|
+
strHo = ["Nguyen","Dinh","Dang","Huynh","Mai","Tran","Le","Hoang","Pham","Phan","Vu","Bui","Do","Ho","Ngo",
|
40
|
+
"Duong","Ly","Vuong","Trinh","Truong","Dinh","Doan","Lam","Phung"]
|
41
|
+
|
42
|
+
strTenDem = ["Thi","Hong","Van","","Duc","Thuy","Ngoc","Ly","Bac","Hien"]
|
43
|
+
|
44
|
+
strTen = ["Trai","Xi","Truc","Tu","Bat","Thanh","Luong","Khuong","Quyen","Quang",
|
45
|
+
"Hoang","Ky","Thai","Chinh","Trinh","Kien","Hao","Hung","Quynh","Phuong","Hoa","Hop","Dung","Thang","Van","Tu","Ninh","Vinh","Loc","Khanh","Thuy","Ha",
|
46
|
+
"Hang","Lam","Hai","Vu","Na","Duyen","Minh","Tuan","Hien","Anh","An","Be","Binh","Canh"]
|
47
|
+
|
48
|
+
if i == 1 then
|
49
|
+
for i in 1..n
|
50
|
+
str = "#{str}#{str1[rand(str1.length)]}"
|
51
|
+
end
|
52
|
+
return str
|
53
|
+
elsif i == 2 then
|
54
|
+
for i in 1..n
|
55
|
+
str = "#{str}#{str2[rand(str2.length)]}"
|
56
|
+
end
|
57
|
+
return str
|
58
|
+
elsif i == 3 then
|
59
|
+
for i in 1..n
|
60
|
+
str = "#{str}#{str3[rand(str3.length)]}"
|
61
|
+
end
|
62
|
+
return str
|
63
|
+
elsif i == 4 then
|
64
|
+
for i in 1..n
|
65
|
+
str = "#{str}#{str4[rand(10)]}"
|
66
|
+
end
|
67
|
+
return str
|
68
|
+
elsif i == 41 then
|
69
|
+
for i in 1..n
|
70
|
+
str = "#{str}#{str41[rand(str41.length)]}"
|
71
|
+
end
|
72
|
+
return str
|
73
|
+
elsif i == 5 then
|
74
|
+
for i in 1..n
|
75
|
+
str = "#{str}#{str5[rand(str5.length)]}"
|
76
|
+
end
|
77
|
+
return str
|
78
|
+
elsif i == 10 then
|
79
|
+
str = "#{strHo[rand(strHo.length)]} #{strTenDem[rand(strTenDem.length)]} #{strTen[rand(strTen.length)]}"
|
80
|
+
return str
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def randfromto(a,b)
|
85
|
+
x = rand(b)
|
86
|
+
while x < a do
|
87
|
+
x = rand(b)
|
88
|
+
end
|
89
|
+
return x
|
90
|
+
end
|
91
|
+
|
92
|
+
def cutEndline(text)
|
93
|
+
if text[text.length-1] <32 or text[text.length-1] > 126 then
|
94
|
+
for i in 0..text.length-2
|
95
|
+
abc = "#{abc}#{decoder(text[i])}"
|
96
|
+
end
|
97
|
+
return abc
|
98
|
+
else
|
99
|
+
for i in 0..text.length-1
|
100
|
+
abc = "#{abc}#{decoder(text[i])}"
|
101
|
+
end
|
102
|
+
return abc
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def readExcel(dir)
|
107
|
+
$excel = WIN32OLE.new("excel.application")
|
108
|
+
$excel.visible = true
|
109
|
+
$workbook = $excel.workbooks.open("#{$mydir}\\#{dir}")
|
110
|
+
$ws=$workbook.worksheets(1)
|
111
|
+
$workbook = $excel.ActiveWorkbook
|
112
|
+
end
|
113
|
+
|
114
|
+
def saveExcel
|
115
|
+
$workbook.Save
|
116
|
+
$workbook.Close
|
117
|
+
$excel.Quit
|
118
|
+
end
|
119
|
+
|
120
|
+
def getFile(name)
|
121
|
+
begin
|
122
|
+
$f = IO.readlines(name)
|
123
|
+
return true
|
124
|
+
rescue
|
125
|
+
return false
|
126
|
+
end
|
127
|
+
end
|
data/qfunction.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{qfunction}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["QuangMV, Cyworld Vietnam, 5th Floor, 447 Lac Long Quan Street, Tay Ho Dist, Hanoi, Vietnam"]
|
9
|
+
s.date = %q{2010-09-13}
|
10
|
+
s.description = %q{Funciton}
|
11
|
+
s.email = %q{quangnnt@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["lib/HTMLElement.rb", "lib/assertions.rb", "lib/sfunction.rb"]
|
13
|
+
s.files = ["Rakefile", "lib/HTMLElement.rb", "lib/assertions.rb", "lib/sfunction.rb", "Manifest", "qfunction.gemspec"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qfunction"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{qfunction}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Funciton}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qfunction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- QuangMV, Cyworld Vietnam, 5th Floor, 447 Lac Long Quan Street, Tay Ho Dist, Hanoi, Vietnam
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-13 00:00:00 +07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Funciton
|
22
|
+
email: quangnnt@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- lib/HTMLElement.rb
|
29
|
+
- lib/assertions.rb
|
30
|
+
- lib/sfunction.rb
|
31
|
+
files:
|
32
|
+
- Rakefile
|
33
|
+
- lib/HTMLElement.rb
|
34
|
+
- lib/assertions.rb
|
35
|
+
- lib/sfunction.rb
|
36
|
+
- Manifest
|
37
|
+
- qfunction.gemspec
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: ""
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --line-numbers
|
45
|
+
- --inline-source
|
46
|
+
- --title
|
47
|
+
- Qfunction
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 2
|
66
|
+
version: "1.2"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: qfunction
|
70
|
+
rubygems_version: 1.3.7
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Funciton
|
74
|
+
test_files: []
|
75
|
+
|