web4cucumber 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f346adcd86c3ad7eff394c03156b59692c8e8db
4
- data.tar.gz: 71c9a0b050b23567d2b07a8af0d741aeb9cd7b0a
3
+ metadata.gz: 73cd68b1548d1653412dac11675eff0e1f47c50c
4
+ data.tar.gz: 3be0f48e3462862711fa4d473ea9fe6d1141d47e
5
5
  SHA512:
6
- metadata.gz: dcc2c2fead7f9badf5355eeab310adfc0e37c36f0a00dfe208296f85fc327ab90229bfbe29a92e0f6460094e44c0accff676c74a5c4587d15434b0d3844f0e7d
7
- data.tar.gz: b2f14a77b67113cc65e4abd1d14bea8deb4195bf1d307c8f306c7f78800114ac68ec94684e51c30aa02b2b0396b514091d19cb33c13db96c26b10e6ff47a7083
6
+ metadata.gz: bdf0b758d5dfc32be4d32c44104b7f5ddea281cfdf06cdc01234ad3d5b82b4c8306676f2be907cea3f93d2e2c6e5d78ef0f4041b30b57c3eee71f15f640fcf1c
7
+ data.tar.gz: 032a4a7c1bd560fdd6da51d61abebbb9d035a4cf1f9949ff3c7603df23b4126e58e776c7f89590b29d2df3c5b4099629c48ec1399fa544b60df6cde51c1d6ed9
data/README.md CHANGED
@@ -250,3 +250,60 @@ Different elemet types get treated differently by webdriver, textfields can not
250
250
  - filefield - provide a full path to the file you would upload here
251
251
  - a -link
252
252
  - element any element that can be simply clicked. No need to provide the type in this case, it will be implied by default.
253
+
254
+ ### Tips and tricks
255
+
256
+ 1. Sometimes a web element may or may not be present on a page depending on the
257
+ user workflow. Say, depending on whether a user is freshly registered or
258
+ not, he may be presented with the checkbox to accept license agreement. If
259
+ you describe this element in the page and it will not be there, an action
260
+ will fail although it really passes. To make it pass, then, you need to mark
261
+ an element optional. This is done through *may_absent* keyword, like this:
262
+ ```
263
+ expected_fields:
264
+ field_one:
265
+ type: textfield
266
+ selector:
267
+ id: 'i-always-exist'
268
+ field_two:
269
+ type: checkbox
270
+ selector:
271
+ id 'i-am-optional'
272
+ may_absent: true
273
+
274
+ ```
275
+
276
+ 2. Sometimes you need a way to stop the action execution at some point to
277
+ perform some unusual actions, like clicking "Cancel" button or anything
278
+ else. This is possible through passing *:stop_at* key with the name of the
279
+ page as a value in options passed to the *run_action* method. Imagine you
280
+ have an action that involves accessing three pages and you want to stop at
281
+ the last page to click some unusual button:
282
+
283
+ ```
284
+ my_beautiful_action:
285
+ expected_pages:
286
+ - 'page_one'
287
+ - 'page_two'
288
+ - 'page_three'
289
+ ```
290
+ Then in you step definition construct the option hash like this:
291
+ ```
292
+ options = {
293
+ :some_field => 'value'
294
+ :some_other_field => 'other_value'
295
+ :stop_at => :third_page
296
+ }
297
+ @result = @web.run_action(:my_beautiful_action, options)
298
+ ```
299
+ then in the next step you can explicitly access whatever element you like on
300
+ the third page of your action
301
+
302
+ 3. Similarly, sometimes you need a way to stop the execution and drop into a
303
+ ruby shell to try some low-level interaction with the webdriver. Well, this
304
+ is easily achieved, just pass
305
+ ```
306
+ :debug_at => :page_three
307
+ ```
308
+ in the options and yo will be dropped into a shell right after page three is
309
+ loaded in the browser window.
@@ -1,9 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gem 'json'
3
2
  gem 'cucumber'
4
- gem 'watir-webdriver'
5
3
  gem 'web4cucumber'
6
4
  gem 'rspec-expectations'
7
- gem 'byebug'
8
- gem 'headless'
9
- gem 'pry'
data/lib/web4cucumber.rb CHANGED
@@ -185,7 +185,7 @@ class Web4Cucumber
185
185
  # some point to have a human control over the webdriver instance. Then
186
186
  # in the same way stick the :debug_at keyword with the page name as a value
187
187
  # into the options hash. The webdriver is available via @@b clas variable
188
- if options.has_key?(:debug_at) and options[:stop_at] == page
188
+ if options.has_key?(:debug_at) and options[:debug_at] == page
189
189
  require "byebug"
190
190
  byebug
191
191
  end
@@ -196,6 +196,16 @@ class Web4Cucumber
196
196
  if page_rules.has_key? :expected_fields
197
197
  page_rules[:expected_fields].each_pair { |name, prop|
198
198
  # Beginning of page fields
199
+ # The following allows you to put <value> as a selector value
200
+ # :select_item:
201
+ # :selector:
202
+ # :text: 'Some text <value>'
203
+ # and then pass the value in options
204
+ prop[:selector].each do |propkey, propval|
205
+ if propval.match Regexp.new("<value>")
206
+ prop[:selector][propkey] = propval.gsub('<value>', options[name])
207
+ end
208
+ end
199
209
  possible_elements = {
200
210
  # There could be more than one element with the same
201
211
  # properties and only one would be visible. As an example:
@@ -362,7 +372,7 @@ class Web4Cucumber
362
372
  button.click
363
373
  rescue Exception => e
364
374
  @result[:result]=false
365
- @result[:error_message] = e.message
375
+ @result[:errors] << e.message
366
376
  screenshot_save
367
377
  end
368
378
  elsif page_rules[:commit].has_key?(:type) and page_rules[:commit][:type] == 'alert'
@@ -1,3 +1,3 @@
1
1
  module Web4Cucumber
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web4cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Fayans