shoot 1.0.0 → 1.1.0

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: aeabb7d1b0a3c562b69bd4176f58fd70efce1f73
4
- data.tar.gz: 0826500463dd17d0d1d6258e6bccc728a4db32c0
3
+ metadata.gz: 4331d59d5b33ac9a34a36c7274543815c9227959
4
+ data.tar.gz: 4d5a81d84d44a5ce417ff9e7947e4c28b3ba8b8f
5
5
  SHA512:
6
- metadata.gz: e280c175e5cd57471645f856b68ca74c0d76551edd530d6b4918e9b10c1badd7a355a1fbdacb3b3b3ec4e492d65db6b34ae5f6ac03b0e7ea6c09d34ffa9b2414
7
- data.tar.gz: 44fc47dbf6035f462b66f8d20cf47760ffaec6eeff791f0a60b814b431850b277baece61c99c754d96c3625b1a5f1977c9461a51eba02e739ee9daf1482edd84
6
+ metadata.gz: f56bed5a01c1cc3a3cdc718be79ea17b210dc466f7b933def485766bb20f110ddff156e22efaa29f525c7828e27205886add3027f2233f67909f340aa7212477
7
+ data.tar.gz: 3ab3a44aa10da24e97b62414b63ca3a2e70a4bde8c87d87124b6b9d087eb02f067a4b8bea4ab93fa739398533735abf5c576b3efd1bdcb3c618618945835420c
data/README.md CHANGED
@@ -63,10 +63,30 @@ Now run:
63
63
 
64
64
  $ shoot scenario my_scenario.rb
65
65
 
66
- This will run all the methods of MyScenario and generate screenshots for all active browsers.
66
+ This will run all the methods of MyScenario and generate screenshots for all active browsers, at the end of each method.
67
67
 
68
68
  The resulting images will be saved on <font size="7"> `.screenshots`</font> folder.
69
69
 
70
+ If you wanna have multiple shots on each method, use the `shoot` method:
71
+
72
+ ```ruby
73
+ class MyScenario < Shoot::Scenario
74
+ def login
75
+ visit "http://url.to.login"
76
+ shoot(:blank_form)
77
+
78
+ fill_in('user', with: 'john')
79
+ fill_in('password', with: '1234')
80
+ shoot(:filled_form)
81
+
82
+ click_button('Login')
83
+ find('#welcome') # This makes sure it waits before you take another shot
84
+ shoot(:welcome_page)
85
+ end
86
+ end
87
+ ```
88
+
89
+
70
90
  If you wanna just test your scenarios, without paying SauceLabs and wasting time with remote connections:
71
91
 
72
92
  $ shoot test my_scenario.rb
data/lib/shoot/cli.rb CHANGED
@@ -66,14 +66,23 @@ module Shoot
66
66
 
67
67
  no_commands do
68
68
  def open_all_screenshots
69
- `open .screenshots/*.png`
69
+ `open #{Dir.glob(".screenshots/**/*.png").join(" ")}`
70
70
  end
71
71
 
72
72
  def run(file, config=nil)
73
73
  klass = get_const_from_file(file)
74
74
  instance = klass.new(config)
75
+ puts set_color instance.platform_name, :white, :bold
75
76
  klass.instance_methods(false).each do |method|
76
- instance.shoot(method)
77
+ print set_color " ➥ #{klass}##{method} ... ", :white, :bold
78
+
79
+ ok, error = instance.run(method)
80
+ if ok
81
+ print set_color "OK\n", :green
82
+ else
83
+ print set_color "FAILED\n", :red
84
+ puts set_color " ⚠ #{error}", :red
85
+ end
77
86
  end
78
87
  instance.ok
79
88
  end
@@ -1,5 +1,7 @@
1
1
  require 'selenium-webdriver'
2
2
  require 'capybara'
3
+ require 'timeout'
4
+
3
5
  class Shoot::Scenario
4
6
  URL = sprintf 'http://%s:%s@hub.browserstack.com/wd/hub',
5
7
  ENV['BROWSERSTACK_USER'],
@@ -24,29 +26,36 @@ class Shoot::Scenario
24
26
  Capybara.run_server = false
25
27
  @platform_name = :poltergeist
26
28
  end
27
-
28
- puts "Running #{platform_name}"
29
+ Capybara.default_wait_time = 10
29
30
  Capybara.current_driver = platform_name
30
31
  end
31
32
 
32
- def shoot(method)
33
+ def find *args
34
+ Timeout.timeout(10) do
35
+ begin
36
+ super *args
37
+ rescue
38
+ retry
39
+ end
40
+ end
41
+ end
42
+
43
+ def run(method)
44
+ @current_method = method
33
45
  send(method)
34
- Kernel.sleep(1) # Just in case
35
- require 'fileutils'
36
- FileUtils::mkdir_p '.screenshots'
37
- save_screenshot(".screenshots/#{method} #{platform_name}.png")
46
+ #Kernel.sleep(1) # Just in case
47
+ shoot(:finish)
48
+ [true, nil]
38
49
  rescue => e
39
- puts "FAILED #{method}: #{e.inspect}"
40
- save_screenshot(".screenshots/failed #{method} #{platform_name}.png")
50
+ #puts "FAILED #{method}: #{e.inspect}"
51
+ shoot(:failed)
52
+ [false, e]
41
53
  end
42
54
 
43
55
  def ok
44
- puts 'OK'
45
56
  page.driver.quit
46
57
  end
47
58
 
48
- private
49
-
50
59
  def platform_name
51
60
  @platform_name ||= if @platform['device']
52
61
  @platform['device']
@@ -56,6 +65,18 @@ class Shoot::Scenario
56
65
  end
57
66
  end
58
67
 
68
+ private
69
+
70
+ def shoot(label)
71
+ directory = ".screenshots/#{platform_name.to_s.gsub(" ", "_")}/#{self.class.name}/#{@current_method}"
72
+ unless Dir.exist?(directory)
73
+ require 'fileutils'
74
+ FileUtils::mkdir_p directory
75
+ end
76
+
77
+ save_screenshot("#{directory}/#{label}.png")
78
+ end
79
+
59
80
  def config_capabilities # rubocop:disable AbcSize
60
81
  @capabilities = Selenium::WebDriver::Remote::Capabilities.new
61
82
  @capabilities[:browser] = @platform['browser']
data/lib/shoot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shoot
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -127,7 +127,7 @@ describe 'Shoot::CLI' do
127
127
  def method; end
128
128
  end
129
129
 
130
- allow_any_instance_of(Foo).to receive(:shoot)
130
+ allow_any_instance_of(Foo).to receive(:run)
131
131
  expect_any_instance_of(Foo).to receive(:ok)
132
132
 
133
133
  allow(cli).to receive(:get_const_from_file).with("foo.rb").and_return(Foo)
@@ -3,7 +3,7 @@ require 'capybara'
3
3
 
4
4
  describe 'Shoot::Scenario' do
5
5
 
6
- describe 'shoot' do
6
+ describe 'run' do
7
7
  before do
8
8
  allow(Capybara).to receive(:register_driver).with("browser 5.0 os 22.0")
9
9
  allow(Capybara).to receive(:current_driver=).with("browser 5.0 os 22.0")
@@ -21,8 +21,8 @@ describe 'Shoot::Scenario' do
21
21
  allow(@scenario).to receive(:save_screenshot)
22
22
  end
23
23
 
24
- it 'shoots' do
25
- @scenario.shoot(:foo)
24
+ it 'runs' do
25
+ @scenario.run(:foo)
26
26
  expect(@scenario).to have_received(:foo)
27
27
  expect(@scenario).to have_received(:save_screenshot)
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Lulkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,7 +156,6 @@ files:
156
156
  - lib/shoot/cli.rb
157
157
  - lib/shoot/scenario.rb
158
158
  - lib/shoot/version.rb
159
- - shoot-0.0.2.gem
160
159
  - shoot.gemspec
161
160
  - spec/cli_spec.rb
162
161
  - spec/scenario_spec.rb
data/shoot-0.0.2.gem DELETED
Binary file