sw2at-capybara 0.0.1 → 0.0.2

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: a3dd0225b894a38289696982a015ae3a71038ae3
4
- data.tar.gz: 350c44c3e4372b5595b12fb2108df5de29d39f75
3
+ metadata.gz: f0e1ec747896b153771a6e937ad57d81b1005c07
4
+ data.tar.gz: 612f7089c773f1c253d343b007c5dda26a1e5a82
5
5
  SHA512:
6
- metadata.gz: e57264d872b9960487f6cd94771eb2d91691b403fb1967234b6a94cf9ee43aebb587ca0be400e1979aeb665679baedaf7c92a2573db7bf9015425e6d7262a064
7
- data.tar.gz: d5d9cce526f391dc2127d233b427dcd114f3a498a9f1c28a7fe814f2091335d95456b3d61f05bfdb6d5f367969fdd910e57d58a0a2f952421bda3df0dcf9170d
6
+ metadata.gz: 2adb397119002086ee71cbfbbe269865f36c1f2f9f17197f59e4cd6f4e684bd0aae828b05b41e78eea391c0da1313268fb66b912ecb1bbbad7c7b03503a647dd
7
+ data.tar.gz: 88ae551c9482a7793abfc8c5215b873b5491042f4b6858f16458812420f15d22d566126441565f8acc227c388de68cdcc746b63da577ccb5d6aa3178bb22302c
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gem 'rspec'
4
4
  gem 'sourcify'
5
5
  gem 'capybara', '>= 2.2.0'
6
6
  gem 'selenium-webdriver', '>= 2.43.0'
7
+ gem 'tarvit-helpers', '>= 0.0.8'
7
8
  gem 'pry', '~> 0.10.1'
8
9
 
9
10
  group :development do
@@ -1,8 +1,15 @@
1
- = sw2at-capybara
1
+ sw2at-capybara
2
+ ==============
2
3
 
3
- Description goes here.
4
+ sw2at-capybara is a suite of methods, which help to make test automation easier, faster and more stable.
4
5
 
5
- == Contributing to sw2at-capybara
6
+ Installation
7
+ -----------------
8
+
9
+ gem install sw2at-capybara
10
+
11
+ Contributing to sw2at-capybara
12
+ -----------------
6
13
 
7
14
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
15
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -12,8 +19,8 @@ Description goes here.
12
19
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
20
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
21
 
15
- == Copyright
16
-
22
+ Copyright
23
+ -----------------
17
24
  Copyright (c) 2015 Vitaly Tarasenko. See LICENSE.txt for
18
25
  further details.
19
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -11,9 +11,13 @@ module Swat
11
11
  output: { enabled: true, started: ?>, step: ?. }
12
12
  }
13
13
  def initialize(rspec_config, opts = {})
14
- rspec_config.include Swat::Capybara::PrintHelper
15
- rspec_config.include Swat::Capybara::Helpers, type: :feature
16
- rspec_config.extend Swat::Capybara::RspecSetup
14
+ if rspec_config
15
+ rspec_config.include Swat::Capybara::PrintHelper
16
+ rspec_config.include Swat::Capybara::Helpers, type: :feature
17
+ rspec_config.extend Swat::Capybara::RspecSetup
18
+ rspec_config.formatter = Swat::Capybara::RspecSetup::SwatFormatter
19
+ end
20
+
17
21
  @options = DEFAULT_OPTIONS.merge opts
18
22
  @options[:output] = DEFAULT_OPTIONS[:output].merge(opts[:output] || {})
19
23
  end
@@ -1,5 +1,6 @@
1
1
  require 'swat/capybara/exceptions'
2
- require 'swat/capybara/colorize'
2
+ require 'tarvit-helpers/extensions/colored_string'
3
+ require 'ostruct'
3
4
 
4
5
  module Swat
5
6
  module Capybara
@@ -11,21 +12,19 @@ module Swat
11
12
  end
12
13
 
13
14
  def explain_step(message)
14
- swc_print "\n - #{message.blue}"
15
- @swc_step ||= 1
15
+ swat_logger.print "\n - #{message.blue}"
16
16
  yield() if block_given?
17
- @swc_step += 1
18
17
  rescue Exception => ex
19
18
  print_exception(ex)
20
- raise_again = !ENV['SWAT_STOP_FAIL']
21
- binding.pry if (ENV['FPRY'] || ENV['SWAT_DBG'])
19
+ raise_again = !swat_stop_fail?
20
+ binding.pry if swat_debug?
22
21
  raise ex if raise_again
23
22
  end
24
23
 
25
24
  def print_exception(ex)
26
- swc_print "\n#{ex.message.red}\n"
27
- ex.backtrace.select{|l|l.to_s.include?(Rails.root.to_s)}.map(&:red).each do |line|
28
- swc_print "\n#{line.red}"
25
+ swat_logger.print "\n#{ex.message.red}\n"
26
+ ex.backtrace.each do |line|
27
+ swat_logger.print "\n#{line.red}"
29
28
  end
30
29
  end
31
30
 
@@ -71,11 +70,35 @@ module Swat
71
70
  all(*args)
72
71
  end
73
72
 
73
+ def select_option(selector, value)
74
+ dropdown = safe_find(selector)
75
+ wait_for_condition do
76
+ dropdown.all(:option).map(&:text).include? value
77
+ end
78
+ dropdown.all(:option).select{|op| op.text == value}.first.select_option
79
+ end
80
+
81
+ def safe_set(field, value)
82
+ safe_find(field).set(value)
83
+ end
84
+
85
+ def page_refresh
86
+ page.driver.browser.navigate.refresh
87
+ end
88
+
89
+ def sub_step(message)
90
+ swat_logger.print "\n > #{message.blue} ".yellow
91
+ yield() if block_given?
92
+ end
93
+
94
+ def xstep name
95
+ swat_logger.print "Skipped step: #{name}"
96
+ end
97
+
74
98
  def click_by_text(text, tag='span')
75
99
  safe_click(tag, text: text)
76
100
  end
77
101
 
78
-
79
102
  def check_text(text, selector=Capybara.config.default_selector, tries=Capybara.config.tries)
80
103
  result = nil
81
104
  wait_for_condition(tries) do
@@ -114,23 +137,41 @@ module Swat
114
137
  end
115
138
 
116
139
  def wait_for_condition(tries = Capybara.config.tries, &condition)
117
- swc_print Capybara.config.output[:started]
140
+ swat_logger.print Capybara.config.output[:started]
118
141
  tries.times do
119
- swc_print Capybara.config.output[:step]
142
+ swat_logger.print Capybara.config.output[:step]
120
143
  result = condition.()
121
144
  return result if result
122
145
  sleep(Capybara.config.min_pause)
123
146
  false
124
147
  end
125
- swc_puts "Failed: #{condition.to_source.red}" rescue nil
148
+ swat_logger.puts "Failed: #{condition.to_source.red}" rescue nil
126
149
  result = ENV['SWAT_STOP_FAIL'] || false
127
150
  binding.pry if (ENV['FPRY'] || ENV['SWAT_DBG'])
128
151
  result
129
152
  end
130
153
 
131
154
  def print_failed_args(res, args, message=nil)
132
- swc_puts message.yellow if message
133
- swc_puts " With args: [#{args*', '}]".red unless res
155
+ swat_logger.puts message.yellow if message
156
+ swat_logger.puts " With args: [#{args*', '}]".red unless res
157
+ end
158
+
159
+ def swat_store
160
+ @swat_store ||= OpenStruct.new
161
+ end
162
+
163
+ def swat_logger
164
+ swat_store.swat_logger ||= TarvitHelpers::ConditionalLogger.new do
165
+ !ENV['SWAT_LOGS_DISABLED']
166
+ end
167
+ end
168
+
169
+ def swat_stop_fail?
170
+ !!ENV['SWAT_STOP_FAIL']
171
+ end
172
+
173
+ def swat_debug?
174
+ ENV['SWAT_DBG'] || ENV['FPRY']
134
175
  end
135
176
  end
136
177
 
@@ -2,30 +2,67 @@ module Swat
2
2
  module Capybara
3
3
  module RspecSetup
4
4
 
5
- def init_capybara
6
- before(:each) do |example|
7
- type = example.metadata[:type] == :feature ? 'FEATURE' : 'TEST'
8
- $swat_example = example
9
- $swat_ctx = self
10
- swc_puts "\n#{ "[#{type}] " + example.description }".yellow if example.metadata[:type]
11
- end
12
-
13
- after(:each) do |example|
14
- if example.metadata[:type]
15
- if example.exception.nil?
16
- swc_puts "\n[PASSED] #{ example.description }".green
17
- else
18
- swc_puts "\n[FAILED] #{ example.description }".red
19
- end
5
+ require 'rspec'
6
+ require 'rspec/core/formatters'
7
+ require 'rspec/core/formatters/base_formatter'
8
+
9
+ class SwatFormatter < RSpec::Core::Formatters::BaseFormatter
10
+ require 'tarvit-helpers/extensions/colored_string'
11
+ require 'tarvit-helpers/modules/conditional_logger'
12
+
13
+ RSpec::Core::Formatters.register self, :example_started, :example_passed, :example_failed, :start, :stop
14
+
15
+ START_MESSAGE = <<STM
16
+ -------------------------------
17
+ [ SW2AT-CAPYBARA initialized ]
18
+ -------------------------------
19
+ STM
20
+
21
+ def initialize(arg)
22
+ super
23
+ @swat_logger = TarvitHelpers::ConditionalLogger.new do
24
+ !ENV['SWAT_LOGS_DISABLED']
20
25
  end
21
26
  end
22
27
 
28
+ def start(notification)
29
+ @swat_logger.puts START_MESSAGE.blue
30
+ end
31
+
32
+ def example_started(notification)
33
+ @started = Time.now
34
+ @swat_logger.puts "\n[FEATURE] #{notification.example.description}".yellow
35
+ end
36
+
37
+ def example_passed(notification)
38
+ @swat_logger.puts "\n[PASSED] #{ notification.example.description } (#{ finished_in(notification.example) })".green
39
+ end
40
+
41
+ def example_failed(notification)
42
+ @swat_logger.puts "\n[FAILED] #{ notification.example.description } (#{ finished_in(notification.example) })".red
43
+ end
44
+
45
+ def stop(notification)
46
+ # Do nothing
47
+ end
48
+
49
+ private
50
+
51
+ def finished_in(example)
52
+ test_duration = Time.at(example.metadata[:execution_result].run_time)
53
+ Time.at(test_duration).utc.strftime("%H:%M:%S")
54
+ end
55
+
56
+ end
57
+
58
+ def init_capybara(rspec_config)
59
+ # adds possiblity to create helpers automatically required and extended by a convention
23
60
  def require_specific_helper(current_file, context)
24
61
  parts = current_file.split('/')
25
62
  parts[-1] = 'specific_helper'
26
63
  path = parts*'/'
27
64
  require path
28
- context.extend SpecificHelper
65
+ context.extend eval('SpecificHelper')
29
66
  end
30
67
  end
31
68
 
@@ -2,31 +2,30 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sw2at-capybara 0.0.1 ruby lib
5
+ # stub: sw2at-capybara 0.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sw2at-capybara"
9
- s.version = "0.0.1"
9
+ s.version = "0.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Vitaly Tarasenko"]
14
- s.date = "2015-06-21"
14
+ s.date = "2015-06-22"
15
15
  s.description = " Gem helps to create capybara tests for pages with a very dynamic content. "
16
16
  s.email = "vetal.tarasenko@gmail.com"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
23
  "Gemfile",
24
24
  "LICENSE.txt",
25
- "README.rdoc",
25
+ "README.md",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/sw2at-capybara.rb",
29
- "lib/swat/capybara/colorize.rb",
30
29
  "lib/swat/capybara/config.rb",
31
30
  "lib/swat/capybara/exceptions.rb",
32
31
  "lib/swat/capybara/helpers.rb",
@@ -47,6 +46,7 @@ Gem::Specification.new do |s|
47
46
  s.add_runtime_dependency(%q<sourcify>, [">= 0"])
48
47
  s.add_runtime_dependency(%q<capybara>, [">= 2.2.0"])
49
48
  s.add_runtime_dependency(%q<selenium-webdriver>, [">= 2.43.0"])
49
+ s.add_runtime_dependency(%q<tarvit-helpers>, [">= 0.0.8"])
50
50
  s.add_runtime_dependency(%q<pry>, ["~> 0.10.1"])
51
51
  s.add_development_dependency(%q<shoulda>, [">= 0"])
52
52
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -58,6 +58,7 @@ Gem::Specification.new do |s|
58
58
  s.add_dependency(%q<sourcify>, [">= 0"])
59
59
  s.add_dependency(%q<capybara>, [">= 2.2.0"])
60
60
  s.add_dependency(%q<selenium-webdriver>, [">= 2.43.0"])
61
+ s.add_dependency(%q<tarvit-helpers>, [">= 0.0.8"])
61
62
  s.add_dependency(%q<pry>, ["~> 0.10.1"])
62
63
  s.add_dependency(%q<shoulda>, [">= 0"])
63
64
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -70,6 +71,7 @@ Gem::Specification.new do |s|
70
71
  s.add_dependency(%q<sourcify>, [">= 0"])
71
72
  s.add_dependency(%q<capybara>, [">= 2.2.0"])
72
73
  s.add_dependency(%q<selenium-webdriver>, [">= 2.43.0"])
74
+ s.add_dependency(%q<tarvit-helpers>, [">= 0.0.8"])
73
75
  s.add_dependency(%q<pry>, ["~> 0.10.1"])
74
76
  s.add_dependency(%q<shoulda>, [">= 0"])
75
77
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
metadata CHANGED
@@ -1,172 +1,184 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sw2at-capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Tarasenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-21 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sourcify
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: capybara
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: selenium-webdriver
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.43.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.43.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: tarvit-helpers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.8
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.8
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ~>
74
88
  - !ruby/object:Gem::Version
75
89
  version: 0.10.1
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ~>
81
95
  - !ruby/object:Gem::Version
82
96
  version: 0.10.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: shoulda
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - '>='
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - '>='
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rdoc
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "~>"
115
+ - - ~>
102
116
  - !ruby/object:Gem::Version
103
117
  version: '3.12'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "~>"
122
+ - - ~>
109
123
  - !ruby/object:Gem::Version
110
124
  version: '3.12'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - "~>"
129
+ - - ~>
116
130
  - !ruby/object:Gem::Version
117
131
  version: '1.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - "~>"
136
+ - - ~>
123
137
  - !ruby/object:Gem::Version
124
138
  version: '1.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: jeweler
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ~>
130
144
  - !ruby/object:Gem::Version
131
145
  version: 2.0.1
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ~>
137
151
  - !ruby/object:Gem::Version
138
152
  version: 2.0.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: simplecov
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - '>='
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - '>='
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
- description: " Gem helps to create capybara tests for pages with a very dynamic content.
154
- \ "
167
+ description: ' Gem helps to create capybara tests for pages with a very dynamic content. '
155
168
  email: vetal.tarasenko@gmail.com
156
169
  executables: []
157
170
  extensions: []
158
171
  extra_rdoc_files:
159
172
  - LICENSE.txt
160
- - README.rdoc
173
+ - README.md
161
174
  files:
162
- - ".document"
175
+ - .document
163
176
  - Gemfile
164
177
  - LICENSE.txt
165
- - README.rdoc
178
+ - README.md
166
179
  - Rakefile
167
180
  - VERSION
168
181
  - lib/sw2at-capybara.rb
169
- - lib/swat/capybara/colorize.rb
170
182
  - lib/swat/capybara/config.rb
171
183
  - lib/swat/capybara/exceptions.rb
172
184
  - lib/swat/capybara/helpers.rb
@@ -183,12 +195,12 @@ require_paths:
183
195
  - lib
184
196
  required_ruby_version: !ruby/object:Gem::Requirement
185
197
  requirements:
186
- - - ">="
198
+ - - '>='
187
199
  - !ruby/object:Gem::Version
188
200
  version: '0'
189
201
  required_rubygems_version: !ruby/object:Gem::Requirement
190
202
  requirements:
191
- - - ">="
203
+ - - '>='
192
204
  - !ruby/object:Gem::Version
193
205
  version: '0'
194
206
  requirements: []
@@ -1,33 +0,0 @@
1
- class String
2
- def colorize(color_code)
3
- "\e[#{color_code}m#{self}\e[0m"
4
- end
5
-
6
- def yellow
7
- colorize(93)
8
- end
9
-
10
- def bg_yellow
11
- colorize(43)
12
- end
13
-
14
- def green
15
- colorize(32)
16
- end
17
-
18
- def blue
19
- colorize(96)
20
- end
21
-
22
- def dark_blue
23
- colorize(34)
24
- end
25
-
26
- def bg_blue
27
- colorize(44)
28
- end
29
-
30
- def red
31
- colorize(31)
32
- end
33
- end