cucumber_steps 0.0.1.sketch → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 884c20285202cd562a175d92e46ccd6ce35509a6
4
- data.tar.gz: fa4cdab4834ce029f799b79b3dba39a3882b4cd9
3
+ metadata.gz: 45beaf5b6ca6bd6506e2ca36e6a581c239617fe4
4
+ data.tar.gz: a4737c0e677888d5187695011019fc9950c3579b
5
5
  SHA512:
6
- metadata.gz: cd734f205303e751e1fe063ccaea6b8c5b856b98f1afcccde3db993a04e482ee543dd6594e228b3735edcbb938e5620bbafc523c237b79468a7caedaa52776ff
7
- data.tar.gz: df35443ec4014b4505de3bff8622fe52cc6af2763fa901f54b5e24f8c992046c5046998b5fe0f7d859cba5921c5c74a09a1b81c0f00e23e6ad5b38508b5e6352
6
+ metadata.gz: 82bc10db105114a1cbaa1533c23bac2a4dd927a94e186c25b4bb7cb8cdaae9714ea8e31b21beb9db86b7c927ba1997bc69408457fee2c417b9f14ad176ac0448
7
+ data.tar.gz: 51df69ea1ef561d2ec2f04ee6fdf15d946e084b83acdb22fbfe8fd8b5350c80a53d4e7cf44ab9a715b1f55055bd1593c232d58a95754d8051e9a5a3da32fa552
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in cucumber_steps.gemspec
4
- gemspec
2
+ gemspec
data/README.md CHANGED
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ### ENV variables
22
+
23
+ * BROWSER_NAME
24
+ * phantomjs
25
+ * chrome
26
+ * firefox
27
+ * etx
28
+
29
+ * BROWSER_NOT_EXIT_AFTER_TEST
30
+ * Do not apply browser object to close on exit
22
31
 
23
32
  ## Contributing
24
33
 
data/Rakefile CHANGED
@@ -1,2 +1,45 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ # From https://gist.github.com/778535
4
+ # In turn based on http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/
5
+ desc "List all available steps"
6
+ task :steps do
7
+ require 'hirb'
8
+ extend Hirb::Console
9
+ features_dir = ENV['FEATURES_PATH'] || "features"
10
+ step_candidates = Dir.glob(File.join(features_dir,'**/*.rb'))
11
+
12
+ # Follow all the gem requires, and identify which files have steps in them
13
+ step_files = []
14
+ step_candidates.each do |candidate|
15
+
16
+ File.foreach(candidate) do |line|
17
+ if line =~ /require ['"](.*\/.*)['"]/
18
+ if libfile = `gem which #{$1} 2>/dev/null`.chomp
19
+ step_candidates << libfile unless step_candidates.include?(libfile)
20
+ end
21
+ elsif line =~ /^\s*(?:Given|When|Then)\s+/
22
+ step_files << candidate
23
+ end
24
+ end
25
+ end
26
+
27
+ step_files.uniq.each do |step_file|
28
+ puts "File: #{step_file}"
29
+ puts ""
30
+ results = []
31
+ File.new(step_file).read.each_line.each_with_index do |line, number|
32
+ next unless line =~ /^\s*(?:Given|When|Then)\s+|\//
33
+ res = /(?:Given|When|Then)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/.match(line)
34
+ next unless res
35
+ matches = res.captures
36
+ results << OpenStruct.new(
37
+ :steps => matches[0],
38
+ :args => matches[2]
39
+ )
40
+ end
41
+ table results, :resize => false, :fields=>[:steps, :args]
42
+ puts ""
43
+
44
+ end
45
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.sketch
1
+ 0.0.1
@@ -23,7 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
24
  spec.add_development_dependency "rake"
25
25
 
26
+ spec.add_dependency 'watir'
26
27
  spec.add_dependency 'rspec'
27
28
  spec.add_dependency 'cucumber'
28
29
 
30
+ spec.add_development_dependency 'hirb'
31
+
29
32
  end
@@ -1,3 +1,12 @@
1
1
  module CucumberSteps
2
- # Your code goes here...
2
+
3
+ require 'cucumber_steps/env_fetcher'
4
+
5
+ require 'cucumber_steps/debug' if CucumberSteps::ENVFetcher.development?
6
+
7
+ require 'cucumber'
8
+ require 'cucumber/rb_support/rb_dsl'
9
+
10
+ require 'cucumber_steps/browser'
11
+
3
12
  end
@@ -0,0 +1,47 @@
1
+ require 'cucumber_steps/browser/browser_steps'
2
+ require 'cucumber_steps/browser/click_steps'
3
+ require 'cucumber_steps/browser/expect_steps'
4
+ require 'cucumber_steps/browser/hover_steps'
5
+ require 'cucumber_steps/browser/sketch_steps'
6
+ require 'cucumber_steps/browser/typing_steps'
7
+ require 'cucumber_steps/browser/visit_steps'
8
+
9
+ module CucumberSteps::Browser
10
+
11
+ require 'cucumber_steps/browser/instance'
12
+
13
+ def browser
14
+ @browser || reopen_browser!
15
+ end
16
+
17
+ def reopen_browser!
18
+
19
+ if @browser.is_a?(::CucumberSteps::Browser::Instance)
20
+ @browser.close
21
+ end
22
+
23
+ browser = ::CucumberSteps::Browser::Instance.new(browser_name)
24
+ @browser = browser
25
+
26
+ end
27
+
28
+ def browser_name=(new_browser_name)
29
+ @browser_name = new_browser_name.to_s.strip
30
+ end
31
+
32
+ def browser_name
33
+ CucumberSteps::ENVFetcher.browser_name || @browser_name || 'phantomjs'
34
+ end
35
+
36
+ def parse_html_attributes(raw_attributes)
37
+ raw_attributes.scan(/(\w+)="([^"]+)"/).reduce({}) do |all_matcher, (attr_name, value)|
38
+ all_matcher[attr_name.downcase.to_sym]=value
39
+ all_matcher
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ World(CucumberSteps::Browser)
46
+
47
+
@@ -0,0 +1,11 @@
1
+ And /^I use "([^"]+)"(?: as the)? browser$/i do |new_browser_name|
2
+ self.browser_name= new_browser_name
3
+ end
4
+
5
+ And /^the browser is (.*)$/i do |new_browser_name|
6
+ self.browser_name= new_browser_name
7
+ end
8
+
9
+ And /^the browser resolution is (\d+)x(\d+) pixels$/i do |width, height|
10
+ browser.window.resize_to(width.to_i, height.to_i)
11
+ end
@@ -0,0 +1,16 @@
1
+
2
+ And /^I click to the "([^"]+)" field that is near to the "([^"]+)" label$/i do |tag_name,label_text|
3
+ relative_positioned_label = browser.current_scope.label(text: label_text).when_present
4
+ element_to_click = relative_positioned_label.parent.element(tag_name: tag_name).when_present
5
+ element_to_click.click
6
+ end
7
+
8
+ And /^I press the "([^"]+)" button$/i do |button_text|
9
+ element_to_click = browser.current_scope.element(text: button_text).when_present
10
+ element_to_click.click
11
+ end
12
+
13
+ And /^I press click to the element that html attributes match the following: (.*)$/ do |raw_html_attributes|
14
+ element_to_click = browser.current_scope.element(parse_html_attributes(raw_html_attributes)).when_present
15
+ element_to_click.click
16
+ end
@@ -0,0 +1,33 @@
1
+ Then(/^the browser url should include "([^"]*)"$/) do |include_text|
2
+ Watir::Wait.until(10, "the url do not include the #{include_text.inspect} text") do
3
+ browser.url.include?(include_text)
4
+ end
5
+ end
6
+
7
+ Then(/^the browser url should not include "([^"]*)"$/) do |include_text|
8
+ Watir::Wait.until(10, "the url do include the #{include_text.inspect} text\n#{browser.url}") do
9
+ not browser.url.include?(include_text)
10
+ end
11
+ end
12
+
13
+ And(/^The browser's url should match the following: \/(.*)\/$/i) do |expected_url|
14
+ Watir::Wait.until(10, "the url do not match the /#{expected_url}/ regular expression") do
15
+ !!(browser.url =~ Regexp.new(expected_url))
16
+ end
17
+ end
18
+
19
+ And(/^the (\w+) with the attributes: (.*?) should match the following text: (.*)$/i) do |tag_name, raw_attr_matcher, expected_match_text|
20
+ Watir::Wait.until(10, "the url do not match the /#{expected_match_text}/ regular expression") do
21
+ begin
22
+ !!((browser.current_scope.element({tag_name: tag_name}.merge(parse_html_attributes(raw_attr_matcher))).when_present.text) =~ Regexp.new(expected_match_text))
23
+ rescue
24
+ false
25
+ end
26
+ end
27
+ end
28
+
29
+ And(/^the browser should include the following text:$/) do |text|
30
+ Watir::Wait.until(10, "the browser do not include the following text: #{text}") do
31
+ browser.current_scope.text.include?(text.strip)
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ And /^I hover(?: mouse)? to the "([^"])" button$/i do |button_text|
2
+ browser.current_scope.element(text: button_text).when_present.hover
3
+ end
4
+
5
+ And /^I hover mouse to the element that html attributes match the following: (.*)$/ do |raw_html_attributes|
6
+ browser.current_scope.element(parse_html_attributes(raw_html_attributes)).when_present.hover
7
+ end
@@ -0,0 +1,17 @@
1
+ require 'watir'
2
+ class CucumberSteps::Browser::Instance < Watir::Browser
3
+
4
+ require 'cucumber_steps/browser/instance/defaults'
5
+ extend CucumberSteps::Browser::Instance::Defaults
6
+
7
+ require 'cucumber_steps/browser/instance/scope_handler'
8
+ include CucumberSteps::Browser::Instance::ScopeHandler
9
+
10
+ protected
11
+
12
+ def initialize(browser_name, *args)
13
+ super(browser_name, *self.class.args_with_default_options(browser_name, *args))
14
+ Kernel.at_exit { self.close rescue nil } if CucumberSteps::ENVFetcher.close_browser_at_exit?
15
+ end
16
+
17
+ end
@@ -0,0 +1,32 @@
1
+ module CucumberSteps::Browser::Instance::Defaults
2
+
3
+ BROWSER_ARGUMENTS = {
4
+ 'phantomjs' => {
5
+ # --load-plugins=[yes|no] Load all plugins (i.e. 'Flash', 'Silverlight', ...) (default is 'no').
6
+ # --ignore-ssl-errors=[yes|no] Ignore SSL errors (i.e. expired or self-signed certificate errors).
7
+ # --ssl-protocol=any
8
+ # --config=/path/to/config
9
+ # # javascriptCanCloseWindows: true
10
+ # # javascriptCanOpenWindows: true
11
+ # # javascriptEnabled: true
12
+ args: ['--ssl-protocol=any']
13
+ }
14
+
15
+ }
16
+
17
+ def args_with_default_options(browser_name, *args)
18
+
19
+ unless args.any? { |e| e.is_a?(Hash) }
20
+ args.unshift({})
21
+ end
22
+
23
+ options = args.find { |e| e.is_a?(Hash) }
24
+
25
+ pare_defined_options = ::CucumberSteps::Browser::Instance::Defaults::BROWSER_ARGUMENTS[browser_name.to_s] || {}
26
+ options.merge!(pare_defined_options) if pare_defined_options.is_a?(Hash)
27
+
28
+ return args
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,35 @@
1
+ module CucumberSteps::Browser::Instance::ScopeHandler
2
+
3
+ def current_scope
4
+ target_scope = self
5
+
6
+ locating_scopes.each do |location_def|
7
+ target_scope = location_def.call(target_scope)
8
+ end
9
+
10
+ target_scope
11
+ end
12
+
13
+ def add_locating_scope(locating_scope_name, &block)
14
+ locating_scopes.push([locating_scope_name.to_s.to_sym, block])
15
+ nil
16
+ end
17
+
18
+ def pop_locating_scope(locating_scope_name)
19
+ locating_scope_name = locating_scope_name.to_s.to_sym
20
+ locating_scopes.delete_if { |name, block| name == locating_scope_name }
21
+ nil
22
+ end
23
+
24
+ def clear_locating_scopes!
25
+ locating_scopes.clear
26
+ nil
27
+ end
28
+
29
+ protected
30
+
31
+ def locating_scopes
32
+ @locating_scopes ||= []
33
+ end
34
+
35
+ end
@@ -0,0 +1,15 @@
1
+ And /^From here I work (?:in|with) iframe$/i do
2
+ browser.add_locating_scope :work_with_iframe do |scope|
3
+ ::Watir::Wait.until { scope.iframes.count > 0 }
4
+
5
+ scope.iframe
6
+ end
7
+ end
8
+
9
+ And /^I no longer work (?:in|with) iframe$/i do
10
+ browser.pop_locating_scope(:work_with_iframe)
11
+ end
12
+
13
+ And /^in the browser(?: without any additional scoping)?$/ do
14
+ browser.clear_locating_scopes!
15
+ end
@@ -0,0 +1,17 @@
1
+ # And(/fill Password text\-field with "([^"]*)"$/i) do |password_text|
2
+ #
3
+ # password_element = browser.elements(text: /^ *passw(?:or)?d:? *$/i).sort_by { |e| e.text.length }.first.to_subtype
4
+ #
5
+ # case password_element
6
+ #
7
+ # when Watir::TableDataCell
8
+ # # [:cell_index, :tab_index]
9
+ # value_td = password_element.parent.td(index: password_element.cell_index + 1)
10
+ # value_td.elements.first.set(password_text)
11
+ #
12
+ # end
13
+ #
14
+ # # $element = password_element
15
+ # # irb_session
16
+ #
17
+ # end
@@ -0,0 +1,21 @@
1
+ And /^I type the following into the browser:$/i do |text_to_be_typed|
2
+ browser.send_keys(text_to_be_typed.to_s)
3
+ end
4
+
5
+ [
6
+
7
+ :null, :cancel, :help, :backspace, :tab, :clear, :return, :enter, :shift, :left_shift, :control, :left_control, :alt, :left_alt,
8
+ :pause, :escape, :space, :page_up, :page_down, :end, :home, :left, :arrow_left, :up, :arrow_up, :right, :arrow_right, :down, :arrow_down, :insert, :delete, :semicolon, :equals,
9
+ :numpad0, :numpad1, :numpad2, :numpad3, :numpad4, :numpad5, :numpad6, :numpad7, :numpad8, :numpad9,
10
+ :multiply, :add, :separator, :subtract, :decimal, :divide,
11
+ :f1, :f2, :f3, :f4, :f5, :f6, :f7, :f8, :f9, :f10, :f11, :f12,
12
+ :meta, :command
13
+
14
+ ].each do |special_key|
15
+
16
+ And /^I hit #{special_key.to_s.inspect} to the browser$/ do
17
+ browser.send_keys(:enter)
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,7 @@
1
+ And /^I (?:visit|goto) the following url: *(.*)$/ do |url|
2
+ browser.goto(url.strip)
3
+ end
4
+
5
+ And /^I (?:visit|goto) the "([^"]+)" url$/ do |url|
6
+ browser.goto(url)
7
+ end
@@ -0,0 +1,21 @@
1
+ def start_irb
2
+ require 'irb'
3
+ require 'irb/completion'
4
+ ARGV.clear
5
+ IRB.start
6
+ end
7
+
8
+ module DebugSteps
9
+
10
+ def irb_session
11
+ $b = $browser = browser
12
+ start_irb
13
+ end
14
+
15
+ end
16
+
17
+ World(DebugSteps)
18
+
19
+ And /irb/i do
20
+ irb_session
21
+ end
@@ -0,0 +1,40 @@
1
+ module CucumberSteps::ENVFetcher
2
+ extend self
3
+
4
+ CLI_ALIASES_FOR_TRUE = %W[yes true]
5
+ CLI_ALIASES_FOR_FALSE = %W[no false]
6
+
7
+ def development?
8
+ lookup_for_true_case('DEVELOPER_ENV')
9
+ end
10
+
11
+ def close_browser_at_exit?
12
+ lookup_for_true_case('CLOSE_BROWSER_AT_EXIT') or
13
+ not lookup_for_false_case('BROWSER_NOT_EXIT_AFTER_TEST', 'BROWSER_NOT_EXIT_AT_EXIT')
14
+ end
15
+
16
+ def browser_name
17
+ lookup_value_by('BROWSER','BROWSER_NAME')
18
+ end
19
+
20
+ protected
21
+
22
+ def lookup_for_true_case(*env_keys)
23
+ filtered_env(env_keys).any? { |k, v| CLI_ALIASES_FOR_TRUE.include?(v.to_s.downcase) }
24
+ end
25
+
26
+ def lookup_for_false_case(*env_keys)
27
+ filtered_env(env_keys).any? { |k, v| CLI_ALIASES_FOR_FALSE.include?(v.to_s.downcase) }
28
+ end
29
+
30
+ def lookup_value_by(*env_keys)
31
+ filtered_env(env_keys).values.first
32
+ end
33
+
34
+ def filtered_env(env_keys)
35
+ lookup_env_keys = env_keys.map(&:to_s).map(&:upcase)
36
+
37
+ ENV.select { |env_key, value| lookup_env_keys.include?(env_key) }
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.sketch
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: watir
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hirb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: collection of often used cucumber steps to avoid the violation of DRY
70
98
  principle
71
99
  email:
@@ -82,6 +110,20 @@ files:
82
110
  - VERSION
83
111
  - cucumber_steps.gemspec
84
112
  - lib/cucumber_steps.rb
113
+ - lib/cucumber_steps/browser.rb
114
+ - lib/cucumber_steps/browser/browser_steps.rb
115
+ - lib/cucumber_steps/browser/click_steps.rb
116
+ - lib/cucumber_steps/browser/expect_steps.rb
117
+ - lib/cucumber_steps/browser/hover_steps.rb
118
+ - lib/cucumber_steps/browser/instance.rb
119
+ - lib/cucumber_steps/browser/instance/defaults.rb
120
+ - lib/cucumber_steps/browser/instance/scope_handler.rb
121
+ - lib/cucumber_steps/browser/locating_scope_steps.rb
122
+ - lib/cucumber_steps/browser/sketch_steps.rb
123
+ - lib/cucumber_steps/browser/typing_steps.rb
124
+ - lib/cucumber_steps/browser/visit_steps.rb
125
+ - lib/cucumber_steps/debug.rb
126
+ - lib/cucumber_steps/env_fetcher.rb
85
127
  homepage: ''
86
128
  licenses:
87
129
  - MIT
@@ -97,9 +139,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
139
  version: '0'
98
140
  required_rubygems_version: !ruby/object:Gem::Requirement
99
141
  requirements:
100
- - - ">"
142
+ - - ">="
101
143
  - !ruby/object:Gem::Version
102
- version: 1.3.1
144
+ version: '0'
103
145
  requirements: []
104
146
  rubyforge_project:
105
147
  rubygems_version: 2.2.2