awetestlib 0.1.29pre3-x86-mingw32 → 0.1.29pre4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -519,13 +519,14 @@ module Awetestlib
519
519
  # Compare strings for no match and log results
520
520
  # @param (see #string_equals?)
521
521
  # @param [Boolean] fail_on_format If set to true method will fail if the formats differ
522
+ # even though the dates/times match
522
523
  # @return [Boolean] Returns true if actual does not match expected.
523
524
  def date_string_equals?(actual, expected, desc = '', fail_on_format = true)
524
525
  rtrn = false
525
526
  if actual == expected
526
527
  rtrn = true
527
528
  elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s
528
- msg2 "with different formatting. "
529
+ msg2 = "with different formatting. "
529
530
  unless fail_on_format
530
531
  rtrn = true
531
532
  end
@@ -1,4 +1,4 @@
1
1
  module Awetestlib
2
- VERSION = "0.1.29pre3"
3
- VERSION_DATE = "2013-03-26"
2
+ VERSION = "0.1.29pre4"
3
+ VERSION_DATE = "2013-04-10"
4
4
  end
@@ -4,27 +4,27 @@ Netbeans IDE Setup
4
4
  <br>
5
5
  1. If you ran the `awetestlib netbeans_setup` command, you should now have a folder called "sample_netbeans" in the directory you ran the command in. Open Netbeans and go to Open Project.
6
6
 
7
- ![netbeans1](https://raw.github.com/anthonywoo/awetestlib/develop/images/netbeans1.jpg "netbeans1")
7
+ ![netbeans1](https://raw.github.com/3qilabs/awetestlib/develop/images/netbeans1.jpg "netbeans1")
8
8
 
9
9
  <br>
10
10
  2. Select the "sample_netbeans" folder that was created and click "Open Project". Your project is now loaded into Netbeans.
11
11
  NOTE: Depending on the version of Netbeans you have, you may need to install the Ruby and Rails plugin.
12
12
 
13
- ![netbeans2](https://raw.github.com/anthonywoo/awetestlib/develop/images/netbeans2.jpg "netbeans2")
13
+ ![netbeans2](https://raw.github.com/3qilabs/awetestlib/develop/images/netbeans2.jpg "netbeans2")
14
14
 
15
15
  <br>
16
16
  3. You can view the different configurations from the config dropdown. We have provided a sample "Demo" config which runs the demo.rb script. To create your own, go to "Customize..."
17
17
 
18
- ![netbeans3](https://raw.github.com/anthonywoo/awetestlib/develop/images/netbeans3.jpg "netbeans3")
18
+ ![netbeans3](https://raw.github.com/3qilabs/awetestlib/develop/images/netbeans3.jpg "netbeans3")
19
19
 
20
20
  <br>
21
21
  4. In the configuration window, you can see the arguments for the Demo configuration. To create your own, go to "New". All the arguments (Main Script, Arguments, and Ruby Options) would be the same as the Demo configuration, the only difference would be the path to the script you want to run.
22
22
 
23
- ![netbeans5](https://raw.github.com/anthonywoo/awetestlib/develop/images/netbeans5.jpg "netbeans5")
23
+ ![netbeans5](https://raw.github.com/3qilabs/awetestlib/develop/images/netbeans5.jpg "netbeans5")
24
24
 
25
25
  <br>
26
26
  5. Once you have the script configurations set, you can select the config you want to run from the dropdown and hit the Play button. The script will now start to run within the IDE.
27
27
 
28
- ![netbeans4](https://raw.github.com/anthonywoo/awetestlib/develop/images/netbeans4.jpg "netbeans4")
28
+ ![netbeans4](https://raw.github.com/3qilabs/awetestlib/develop/images/netbeans4.jpg "netbeans4")
29
29
 
30
- <br>
30
+ <br>
@@ -4,21 +4,21 @@ Rubymine IDE Setup
4
4
  <br>
5
5
  1. If you ran the `awetestlib rubymine_setup` command, you should now have a folder called "sample_rubymine" in the directory you ran the command in. Open Rubymine and go to Open Directory...
6
6
 
7
- ![rubymine1](https://raw.github.com/anthonywoo/awetestlib/develop/images/rubymine1.jpg "rubymine1")
7
+ ![rubymine1](https://raw.github.com/3qilabs/awetestlib/develop/images/rubymine1.jpg "rubymine1")
8
8
 
9
9
  <br>
10
10
  2. You can view the different configurations from the config dropdown. We have provided a sample "Demo" config which runs the demo.rb script. To create new configurations, go to Edit Configurations...
11
11
 
12
- ![rubymine2](https://raw.github.com/anthonywoo/awetestlib/develop/images/rubymine2.jpg "rubymine2")
12
+ ![rubymine2](https://raw.github.com/3qilabs/awetestlib/develop/images/rubymine2.jpg "rubymine2")
13
13
 
14
14
  <br>
15
15
  3. In the configuration window, you can see the arguments for the Demo configuration. To create a new configuration for a new script, simply copy the Demo configuration and change the path to the script you want to run in the "Script arguments:" section.
16
16
 
17
- ![rubymine3](https://raw.github.com/anthonywoo/awetestlib/develop/images/rubymine3.jpg "rubymine3")
17
+ ![rubymine3](https://raw.github.com/3qilabs/awetestlib/develop/images/rubymine3.jpg "rubymine3")
18
18
 
19
19
  <br>
20
20
  4. Once you have the script configurations set, you can select the config you want to run from the dropdown and hit the Play button. The script will now start to run within the IDE.
21
21
 
22
- ![rubymine4](https://raw.github.com/anthonywoo/awetestlib/develop/images/rubymine4.jpg "rubymine4")
22
+ ![rubymine4](https://raw.github.com/3qilabs/awetestlib/develop/images/rubymine4.jpg "rubymine4")
23
23
 
24
- <br>
24
+ <br>
@@ -1,29 +1,97 @@
1
- When /^I open a new browser$/ do
1
+ require 'pry'
2
+
3
+ def awetestlib?
4
+ not Awetestlib::Runner.nil?
5
+ rescue
6
+ return false
7
+ end
8
+
9
+ Given /^I run with Watir$/ do
10
+ require 'watir'
11
+ require 'win32ole'
12
+ $ai = ::WIN32OLE.new('AutoItX3.Control')
13
+ $first_index = 1
14
+ $timestamp = Time.now.strftime("%Y%m%d%H%M%S")
15
+ $watir_script = true
16
+ Watir::IE.close_all
17
+ Watir::IE.visible = true
18
+ end
19
+
20
+ Given /^I run with Classic Watir$/ do
21
+ step "I run with Watir$"
22
+ end
23
+
24
+ Given /^I run with Watir-webdriver$/i do
25
+ require 'watir-webdriver'
26
+ $first_index = 0
27
+ $timestamp = Time.now.strftime("%Y%m%d%H%M%S")
28
+ $watir_script = false
29
+ end
30
+
31
+
32
+ When /^I open a new browser$/i do
2
33
  if @params
34
+ puts "@params: #{@params}"
3
35
  case @params["browser"]
4
- when "FF"; @browser = Watir::Browser.new :firefox
5
- when "IE"; @browser = Watir::Browser.new :ie
6
- when "C", "GC"; @browser = Watir::Browser.new :chrome
36
+ when "FF"
37
+ step "I open Firefox"
38
+ when "IE"
39
+ step "I open Internet Explorer"
40
+ when "C", "GC"
41
+ step "I open Chrome"
7
42
  end
8
43
  else
9
- @browser = Watir::Browser.new
44
+ step "I open Firefox"
45
+ end
10
46
  end
47
+
48
+ Given /^I open a F?f?irefox B?b?rowser$/i do
49
+ step "I open Firefox"
11
50
  end
12
51
 
13
- Given /^I open a firefox browser$/ do
52
+ Given /^I open Firefox$/ do
53
+ step "I run with Watir-webdriver"
14
54
  @browser = Watir::Browser.new :firefox
15
55
  end
16
56
 
17
- Given /^I open a chrome browser$/ do
57
+ Given /^I open a C?c?hrome B?b?rowser$/i do
58
+ step "I open Chrome"
59
+ end
60
+
61
+ Given /^I open Chrome$/ do
62
+ step "I run with Watir-webdriver"
18
63
  @browser = Watir::Browser.new :chrome
19
64
  end
20
65
 
21
- Given /^I open an internet explorer browser$/ do
22
- @browser = Watir::Browser.new :ie
66
+ When /^I open an IE B?b?rowser$/i do
67
+ step "I open Internet Explorer"
68
+ end
69
+
70
+ Given /^I open an I?i?nternet E?e?xplorer B?b?rowser$/i do
71
+ step "I open Internet Explorer"
72
+ end
73
+
74
+ Given /^I open Internet Explorer$/i do
75
+ if $watir_script
76
+ step "I run with Watir"
77
+ @browser = Watir::IE.new
78
+ @browser.speed = :fast
79
+ else
80
+ step "I run with Watir-webdriver"
81
+ client = Selenium::WebDriver::Remote::Http::Default.new
82
+ client.timeout = 300 # seconds – default is 60
83
+ @browser = Watir::Browser.new :ie, :http_client => client
84
+ end
23
85
  end
24
86
 
25
87
  Then /^I navigate to the environment url$/ do
88
+ if @params and @params['environment'] and @params['environment']['url']
26
89
  url = @params['environment']['url']
90
+ elsif @login and @login['url']
91
+ url = @login['url']
92
+ elsif @role and @login[@role] and @login[@role]['url']
93
+ url = @login[@role]['url']
94
+ end
27
95
  @browser.goto url
28
96
  end
29
97
 
@@ -31,46 +99,256 @@ Then /^I go to the url "(.*?)"$/ do |url|
31
99
  @browser.goto url
32
100
  end
33
101
 
102
+ Then /^I go to the (URL|url)$/ do |dummy|
103
+ step "I navigate to the environment url"
104
+ end
105
+
34
106
  Then /^I click "(.*?)"$/ do |element_text|
35
- sleep 1
36
- @browser.element(:text, element_text).click
107
+ step "I click the element with \"text\" \"#{element_text}\""
37
108
  end
38
109
 
39
110
  Then /^I click the button "(.*?)"$/ do |element_text|
40
- sleep 1
41
- @browser.button(:text, element_text).click
111
+ step "I click the button with \"text\" \"#{element_text}\""
112
+ end
113
+
114
+ Then /^I click the "?(.*?)"? with "(.*?)" "(.*?)"$/ do |element, how, what|
115
+ step "I wait until #{element} with #{how} \"#{what}\" is ready"
116
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
117
+ case element
118
+ when 'link'
119
+ target = @browser.link(how.to_sym, what)
120
+ when 'button'
121
+ target = @browser.button(how.to_sym, what)
122
+ else
123
+ target = @browser.element(how.to_sym, what)
124
+ end
125
+ if target.respond_to?("click")
126
+ if $watir_script
127
+ target.click
128
+ else
129
+ target.fire_event('onclick')
130
+ end
131
+ else
132
+ fail("#{element} with #{how} '#{what}' does not respond to 'click'")
133
+ end
42
134
  end
43
135
 
44
- Then /^I click the element with "(.*?)" "(.*?)"$/ do |arg1, arg2|
45
- @browser.element(arg1.to_sym, arg2)
136
+ And /^I enter "(.*?)" in text field with "?(.*?)"? "(.*?)"$/ do |value, how, what|
137
+ what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
138
+ #step "I wait until text field with #{how} \"#{what}\" is ready"
139
+ @browser.text_field(how.to_sym, /#{what}/).set(value)
46
140
  end
47
141
 
48
- Then /^I should see "(.*?)"$/ do |text|
49
- sleep 1
50
- stm = @browser.text.include? text
51
- if stm
52
- true
142
+ And /^I enter the value for "(.*?)" in text field with "?(.*?)"? "(.*?)"$/ do |index, how, what|
143
+ if index =~ /zipcode/
144
+ value = @var[index].to_i.to_s
145
+ else
146
+ value = @var[index]
147
+ end
148
+ step "I enter \"#{value}\" in text field with #{how} \"#{what}\""
149
+ end
150
+
151
+ And /^I select the value "(.*?)" in select list with "?(.*?)"? "(.*?)"$/ do |value, how, what|
152
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
153
+ @browser.select_list(how.to_sym, what).select_value(/#{value}/)
154
+ end
155
+
156
+ And /^I select the option "(.*?)" in select list with "?(.*?)"? "(.*?)"$/ do |option, how, what|
157
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
158
+ @browser.select_list(how.to_sym, what).select(/#{option}/)
159
+ end
160
+
161
+ And /^I select the value for "(.*?)" in select list with "?(.*?)"? "(.*?)"$/ do |index, how, what|
162
+ value = @var[index]
163
+ step "I select the value \"#{value}\" in select list with #{how} \"#{what}\""
164
+ end
165
+
166
+ Then /^I check that the "?(.*?)"? with "?(.*?)"? "(.*?)" contains "(.*?)"$/ do |element, how, what, target|
167
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
168
+ step "I wait until #{element} with #{how} \"#{what}\" is ready"
169
+ unless @browser.element(how.to_sym, what).text.include?(target)
170
+ fail ("#{element} with #{how} '#{what}' does not contain '#{target}'")
171
+ end
172
+
173
+ end
174
+
175
+ Then /^I check that the text field with "?(.*?)"? "(.*?)" contains the value for "(.*?)"$/ do |how, what, index|
176
+ if index =~ /zipcode/
177
+ value = @var[index].to_i.to_s
53
178
  else
179
+ value = @var[index]
180
+ end
181
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
182
+ unless @browser.text_field(how.to_sym, what).value.include?(value)
183
+ fail("The text field with #{how} '#{what}' does not contain the value for '${index}' ('#{value}'")
184
+ end
185
+ end
186
+
187
+ Then /^I should see "(.*?)"$/ do |text|
188
+ step "I wait 1 second"
189
+ unless @browser.text.include? text
54
190
  fail("Did not find text #{text}")
55
191
  end
56
192
  end
57
193
 
58
194
  Then /^I should not see "(.*?)"$/ do |text|
59
- stm = @browser.text.include? text
60
- if stm
195
+ if @browser.text.include? text
61
196
  fail("Found text #{text}")
62
- else
63
- true
64
197
  end
65
198
  end
66
199
 
67
- Then /^I fill in "(.*?)" with "(.*?)"$/ do |field, value| #assumes u have label
200
+ Then /^I fill in "(.*?)" with "(.*?)"$/ do |field, value| # assumes a label element and its associated element has id
68
201
  associated_label = @browser.label(:text, field).attribute_value("for")
69
202
  #associated_label = @browser.element(:xpath, '//label[contains(text(),"#{arg1}")]').attribute_value("for"))
70
203
  @browser.text_field(:id, associated_label).set value
71
204
  end
72
205
 
206
+ Then /^let me debug$|^pry$|^execute binding.pry$/ do
207
+ binding.pry
208
+ end
73
209
 
74
210
  When /^I wait (\d+) seconds?$/ do |seconds|
75
211
  sleep seconds.to_i
76
212
  end
213
+
214
+ When /^I wait until "?(.*?)"? with "?(.*?)"? "(.*?)" is ready$/ do |element, how, what|
215
+ #what = Regexp.new(Regexp.escape(what)) unless how =~ /index|text/i or what.is_a?(Regexp)
216
+ ok = false
217
+ if $watir_script
218
+ if Watir::Wait.until {@browser.element(how, what).exists?}
219
+ if Watir::Wait.until {@browser.element(how, what).visible?}
220
+ if Watir::Wait.until {@browser.element(how, what).enabled?}
221
+ ok = true
222
+ end
223
+ end
224
+ end
225
+ else
226
+ case element
227
+ when 'button'
228
+ if @browser.button(how.to_sym, what).wait_until_present
229
+ ok = true
230
+ end
231
+ when 'text field'
232
+ sleep 2
233
+ #if @browser.text_field(how.to_sym, what).wait_until_present
234
+ ok = true
235
+ #end
236
+ else
237
+ if @browser.element(how.to_sym, what).wait_until_present
238
+ ok = true
239
+ end
240
+ end
241
+ end
242
+ unless ok
243
+ fail("#{element} with #{how} '#{what}' is not ready")
244
+ end
245
+ end
246
+
247
+ And /^I click "(.*?)" in the browser alert$/ do |button|
248
+ if $watir_script
249
+ $ai.WinWait("Message from webpage")
250
+ sleep(1)
251
+ $ai.ControlClick("Message from webpage", "", button)
252
+ else
253
+ @browser.alert.wait_until_present
254
+ case button
255
+ when /ok/i, /yes/i, /submit/i
256
+ @browser.alert.ok
257
+ when /cancel/i, /close/i
258
+ @browser.alert.close
259
+ else
260
+ fail("'#{button} for alert not recognized.")
261
+ end
262
+ end
263
+ end
264
+
265
+ And /^I close the browser$/ do
266
+ @browser.close
267
+ end
268
+
269
+ Given /^I load data spreadsheet "(.*?)" for "(.*?)"$/ do |file, feature|
270
+ require 'roo'
271
+ @workbook = Excel.new(file)
272
+ @feature_name = feature #File.basename(feature, ".feature")
273
+ step "I load @login from spreadsheet"
274
+ step "I load @var from spreadsheet"
275
+ end
276
+
277
+ Then /^I load @login from spreadsheet$/ do
278
+ @login = Hash.new
279
+ @workbook.default_sheet = @workbook.sheets[0]
280
+
281
+ script_col = 0
282
+ role_col = 0
283
+ userid_col = 0
284
+ password_col = 0
285
+ url_col = 0
286
+ name_col = 0
287
+
288
+ 1.upto(@workbook.last_column) do |col|
289
+ header = @workbook.cell(1, col)
290
+ case header
291
+ when @feature_name
292
+ script_col = col
293
+ when 'role'
294
+ role_col = col
295
+ when 'userid'
296
+ userid_col = col
297
+ when 'password'
298
+ password_col = col
299
+ when 'url'
300
+ url_col = col
301
+ when 'name'
302
+ name_col = col
303
+ end
304
+ end
305
+
306
+ 2.upto(@workbook.last_row) do |line|
307
+ role = @workbook.cell(line, role_col)
308
+ userid = @workbook.cell(line, userid_col)
309
+ password = @workbook.cell(line, password_col)
310
+ url = @workbook.cell(line, url_col)
311
+ username = @workbook.cell(line, name_col)
312
+ enabled = @workbook.cell(line, script_col).to_s
313
+
314
+ if enabled == 'Y'
315
+ @login['role'] = role
316
+ @login['userid'] = userid
317
+ @login['password'] = password
318
+ @login['url'] = url
319
+ @login['name'] = username
320
+ @login['enabled'] = enabled
321
+ break
322
+ end
323
+ end
324
+ end
325
+
326
+ Then /^I load @var from spreadsheet$/ do
327
+ @var = Hash.new
328
+ @workbook.default_sheet = @workbook.sheets[1]
329
+ script_col = 0
330
+ name_col = 0
331
+
332
+ 1.upto(@workbook.last_column) do |col|
333
+ header = @workbook.cell(1, col)
334
+ case header
335
+ when @feature_name
336
+ script_col = col
337
+ when 'Variable'
338
+ name_col = col
339
+ end
340
+ end
341
+
342
+ 2.upto(@workbook.last_row) do |line|
343
+ name = @workbook.cell(line, name_col)
344
+ value = @workbook.cell(line, script_col).to_s.strip
345
+ @var[name] = value
346
+ end
347
+ end
348
+
349
+ #Before do
350
+ # unless awetestlib?
351
+ # manifest_file = File.join(File.dirname(__FILE__), '..', 'manifest.json')
352
+ # @params = JSON.parse(File.open(manifest_file).read)['params'] #Have access to all params in manifest file
353
+ # end
354
+ #end