acceptance_test2 0.9.0 → 0.10.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: d56f22549436449880aaf128ab8e5e4bfbdf2a65
4
- data.tar.gz: f9521bc9149ce7d9092dd23dd02b6711ccd01048
3
+ metadata.gz: 7897f04e82d60a587e4b526ff0041807d2330432
4
+ data.tar.gz: 85d96b26ab159f3afc3ac41a89743cfde7203c28
5
5
  SHA512:
6
- metadata.gz: 07ea431d1e6bcca3839d2d2510e0a2ec92c32df620cc191ee4b84b6fa598cec0999e58a6be489ca929e8fadedbc4e373415898013920165ac8b832949534f9ce
7
- data.tar.gz: 37f1788539ae3f578f8ae2cd5f6979c592d62670158f16949dd687b9715a1510a3d70aa0e629307169682eb3030d34be673f70447f729dbae9132008191aadfe
6
+ metadata.gz: 3c01751f63ff9df04dbfa000951596dce962e61d8a41d8abbc883cb2a887332dba592fe8c680feeed1e1544a0e2f9bba81b81e8f3fe172fa141b5d41bc1dcbe0
7
+ data.tar.gz: cceaf93ffecdaa997c49c036c6ce17a2de00b3809c0d4f004fcf62e41e79304d101065960c4ed7d7e9c6f82440739a685b7163751fb5e21144622ad81b27c98c
data/.gitignore CHANGED
@@ -38,3 +38,4 @@ Gemfile.lock
38
38
  .vagrant
39
39
  output
40
40
  .idea
41
+ node_modules
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.3.1
@@ -0,0 +1,42 @@
1
+ #
2
+ # Acceptance Dockerfile
3
+ #
4
+
5
+ FROM ubuntu:14.04
6
+
7
+ MAINTAINER Alexander Shvets "alexander.shvets@gmail.com"
8
+
9
+ # 1. Update system
10
+ RUN sudo apt-get update
11
+ RUN sudo locale-gen en_US.UTF-8
12
+
13
+ # 2. Install sshd
14
+
15
+ RUN sudo apt-get install -y openssh-server
16
+ RUN mkdir /var/run/sshd
17
+ RUN echo 'root:root' |chpasswd
18
+ RUN sed --in-place=.bak 's/without-password/yes/' /etc/ssh/sshd_config
19
+
20
+ EXPOSE 22
21
+
22
+ CMD /usr/sbin/sshd -D
23
+
24
+ # 3. Create vagrant user
25
+ RUN groupadd vagrant
26
+ RUN useradd -d /home/vagrant -g vagrant -m -s /bin/bash vagrant
27
+ RUN sudo sed -i '$a vagrant ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
28
+ RUN echo vagrant:vagrant | chpasswd
29
+ RUN sudo chown -R vagrant /home/vagrant
30
+
31
+ # 4. Prepare directories for the project
32
+
33
+ # Add project dir to docker
34
+
35
+ ADD . /home/vagrant/demo
36
+ WORKDIR /home/vagrant/demo
37
+
38
+ EXPOSE 9292
39
+
40
+ # Define default command.
41
+ CMD ["bash"]
42
+
data/Gemfile CHANGED
@@ -5,27 +5,57 @@ group :development do
5
5
  gem "gemcutter"
6
6
  end
7
7
 
8
+ group :default do
9
+ gem 'thor', "~> 0.19.1"
10
+ gem "script_executor", "~> 1.7.7"
11
+ gem "parallel_tests", "~> 2.6.0"
12
+
13
+ if Gem::Platform.local.os.to_sym == :linux
14
+ gem "headless"
15
+ end
16
+ end
17
+
8
18
  group :minitest, :default do
9
- gem "minitest", "~> 5.8.1"
10
- gem "minitest-capybara", "~> 0.7.2"
19
+ gem "minitest", "~> 5.9.0"
20
+ gem "minitest-capybara", "~> 0.8.2"
11
21
  gem "minitest-metadata", "~> 0.6.0"
12
- gem "minitest-reporters", "~> 1.1.2"
22
+ gem "minitest-reporters", "~> 1.1.9"
13
23
  end
14
24
 
25
+ # Note: for capybara-webkit you need to install qt first:
26
+ #
27
+ # Mac: brew install qt5 ; ln -s /usr/local/Cellar/qt5/5.6.1/bin/qmake /usr/local/bin/qmake
28
+ # Ubuntu: sudo apt-get install libqt4-dev libqtwebkit-dev
29
+ # Debian: sudo apt-get install libqt4-dev
30
+ # Fedora: yum install qt-webkit-devell
31
+
32
+ # for chrome support:
33
+ # brew install chromedriver
34
+
35
+ # Note: for poltergeist you have to install phantomjs first
36
+ # brew install phantomjs
37
+
15
38
  group :capybara, :default do
16
- gem "capybara", "~> 2.5.0"
39
+ gem "capybara", "~> 2.7.1"
17
40
  gem "capybara-extensions", "~> 0.4.1"
18
- gem "selenium-webdriver", "~> 2.47.1"
19
- gem "capybara-webkit", "~> 1.7.1"
41
+ gem "selenium-webdriver", "~> 2.53.3"
20
42
  end
21
43
 
44
+ # group :webkit do
45
+ # gem "capybara-webkit", "~> 1.7.1"
46
+ # end
47
+ #
48
+ # group :poltergeist do
49
+ # gem "poltergeist", "~> 1.9.0"
50
+ # end
51
+
22
52
  group :rspec, :default do
23
- gem "rspec", "~> 3.3.0"
53
+ gem "rspec", "~> 3.4.0"
24
54
  end
25
55
 
26
- group :turnip, :default do
27
- gem "turnip", "~> 1.3.1"
28
- gem "turnip_formatter", "~> 0.3.4"
29
- gem "gnawrnip", "~> 0.3.2"
30
- #gem "turnip", :git => 'https://github.com/jnicklas/turnip.git', :branch => '2_0_0_rc1'
31
- end
56
+ # group :turnip do
57
+ # gem "turnip", "~> 2.1.1"
58
+ # gem "turnip_formatter", "~> 0.5.0"
59
+ # gem "gnawrnip", "~> 0.5.0"
60
+ # #gem "turnip", :git => 'https://github.com/jnicklas/turnip.git', :branch => '2_0_0_rc1'
61
+ # end
data/README.md CHANGED
@@ -185,62 +185,6 @@ Feature: Using Wikipedia
185
185
  Then I should see "Capybara"
186
186
  ```
187
187
 
188
-
189
-
190
-
191
- # Without selenium configuration
192
-
193
- Your spec class:
194
-
195
- ```ruby
196
- require 'acceptance_test'
197
-
198
- describe 'Google Search' do
199
-
200
- include_context "AcceptanceTest"
201
-
202
- before :all do
203
- acceptance_test.app_host = "http://www.google.com"
204
- end
205
-
206
- it "uses selenium driver", driver: :selenium, exclude: false do
207
- visit('/')
208
-
209
- fill_in "q", :with => "Capybara"
210
-
211
- #save_and_open_page
212
-
213
- find("#gbqfbw button").click
214
-
215
- all(:xpath, "//li[@class='g']/h3/a").each { |a| puts a[:href] }
216
- end
217
- end
218
- ```
219
-
220
- # With selenium configuration
221
-
222
- Your spec class:
223
-
224
- ```ruby
225
- require 'acceptance_test'
226
-
227
- describe 'Google Search' do
228
-
229
- include_context "AcceptanceTest"
230
-
231
- before :all do
232
- selenium_config_file = "spec/features/selenium.yml"
233
- selenium_config_name = "test"
234
-
235
- acceptance_test.load_selenium_config selenium_config_file, selenium_config_name
236
- end
237
-
238
- it "do something" do
239
- # ...
240
- end
241
- end
242
- ```
243
-
244
188
  # Using Vagrant
245
189
 
246
190
  1. Install Virtual Box & Vagrant
@@ -254,12 +198,6 @@ brew cask install vagrant
254
198
 
255
199
  vagrant up
256
200
 
257
- 3. Run docker container:
258
-
259
- vagrant docker-run default -- echo hi
260
-
261
-
262
- app -- rake db:migrate
263
201
 
264
202
 
265
203
  Capybara resources:
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  $LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
4
4
 
5
5
  require "rspec/core/rake_task"
6
+ require 'rake/testtask'
6
7
  require "acceptance_test/version"
7
8
  require "gemspec_deps_gen/gemspec_deps_gen"
8
9
 
@@ -31,8 +32,6 @@ task :release => :build do
31
32
  system "gem push #{project_name}-#{version}.gem"
32
33
  end
33
34
 
34
- require 'rake/testtask'
35
-
36
35
  task :default => :test
37
36
 
38
37
  desc 'Run minitest tests'
@@ -57,3 +56,7 @@ RSpec::Core::RakeTask.new('turnip') do |t|
57
56
  t.rspec_opts = "--color -Ispec/support/features -r turnip/rspec"
58
57
  end
59
58
 
59
+ desc 'Run tests in parallel'
60
+ RSpec::Core::RakeTask.new('para') do
61
+ system 'parallel_test -n 2 -e "rspec spec/unit/wikipedia_search_spec.rb"'
62
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless defined? Thor::Runner
4
+ require 'bundler'
5
+
6
+ gems = Bundler::Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, nil).requested_specs
7
+
8
+ gem = gems.find { |gem| gem.name == 'thor'}
9
+
10
+ load "#{ENV['GEM_HOME']}/gems/#{gem.name}-#{gem.version}/bin/thor"
11
+ end
12
+
13
+ require 'thor'
14
+
15
+ Dir.glob("thor/**/*.thor") do |name|
16
+ Thor::Util.load_thorfile(name)
17
+ end
18
+
19
+ # $LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
@@ -0,0 +1,83 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # All Vagrant configuration is done below. The "2" in Vagrant.configure
5
+ # configures the configuration version (we support older styles for
6
+ # backwards compatibility). Please don't change it unless you know what
7
+ # you're doing.
8
+ Vagrant.configure(2) do |config|
9
+ # The most common configuration options are documented and commented below.
10
+ # For a complete reference, please see the online documentation at
11
+ # https://docs.vagrantup.com.
12
+
13
+ # Every Vagrant development environment requires a box. You can search for
14
+ # boxes at https://atlas.hashicorp.com/search.
15
+
16
+ config.vm.box = "ubuntu/vivid64"
17
+ # config.vm.box = "package.box"
18
+
19
+ config.vm.network "private_network", ip: "22.22.22.22"
20
+
21
+ # Disable automatic box update checking. If you disable this, then
22
+ # boxes will only be checked for updates when the user runs
23
+ # `vagrant box outdated`. This is not recommended.
24
+ # config.vm.box_check_update = false
25
+
26
+ # Create a forwarded port mapping which allows access to a specific port
27
+ # within the machine from a port on the host machine. In the example below,
28
+ # accessing "localhost:8080" will access port 80 on the guest machine.
29
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
30
+
31
+ # Create a private network, which allows host-only access to the machine
32
+ # using a specific IP.
33
+ # config.vm.network "private_network", ip: "192.168.33.10"
34
+
35
+ # Create a public network, which generally matched to bridged network.
36
+ # Bridged networks make the machine appear as another physical device on
37
+ # your network.
38
+ # config.vm.network "public_network"
39
+
40
+ # Share an additional folder to the guest VM. The first argument is
41
+ # the path on the host to the actual folder. The second argument is
42
+ # the path on the guest to mount the folder. And the optional third
43
+ # argument is a set of non-required options.
44
+ # config.vm.synced_folder "../data", "/vagrant_data"
45
+
46
+ # Provider-specific configuration so you can fine-tune various
47
+ # backing providers for Vagrant. These expose provider-specific options.
48
+ # Example for VirtualBox:
49
+
50
+ config.vm.provider "virtualbox" do |vb|
51
+ # Display the VirtualBox GUI when booting the machine
52
+ # vb.gui = true
53
+
54
+ # Customize the amount of memory on the VM:
55
+ vb.memory = 2048
56
+ vb.cpus = 4
57
+ end
58
+
59
+ # config.vm.provider "docker" do |d|
60
+ # d.build_dir = "."
61
+ # d.remains_running = false
62
+ # end
63
+ #
64
+ # config.ssh.username = "docker"
65
+ # config.ssh.password = "tcuser"
66
+
67
+ # View the documentation for the provider you are using for more
68
+ # information on available options.
69
+
70
+ # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
71
+ # such as FTP and Heroku are also available. See the documentation at
72
+ # https://docs.vagrantup.com/v2/push/atlas.html for more information.
73
+ # config.push.define "atlas" do |push|
74
+ # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
75
+ # end
76
+
77
+ # Enable provisioning with a shell script. Additional provisioners such as
78
+ # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
79
+ # documentation for more information about their specific syntax and use.
80
+
81
+ config.vm.provision :shell, path: "thor/system_provision.sh"
82
+
83
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/acceptance_test/version')
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "acceptance_test2"
7
+ spec.summary = %q{Simplifies congiguration and run of acceptance tests.}
8
+ spec.description = %q{Description: simplifies congiguration and run of acceptance tests.}
9
+ spec.email = "alexander.shvets@gmail.com"
10
+ spec.authors = ["Alexander Shvets"]
11
+ spec.homepage = "http://github.com/shvets/acceptance_test2"
12
+
13
+ spec.files = `git ls-files`.split($\)
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+ spec.version = AcceptanceTest::VERSION
17
+ spec.license = "MIT"
18
+
19
+
20
+ spec.add_runtime_dependency "thor", ["~> 0.19.1"]
21
+ spec.add_runtime_dependency "script_executor", ["~> 1.7.7"]
22
+ spec.add_runtime_dependency "parallel_tests", ["~> 2.6.0"]
23
+ spec.add_runtime_dependency "minitest", ["~> 5.9.0"]
24
+ spec.add_runtime_dependency "minitest-capybara", ["~> 0.8.2"]
25
+ spec.add_runtime_dependency "minitest-metadata", ["~> 0.6.0"]
26
+ spec.add_runtime_dependency "minitest-reporters", ["~> 1.1.9"]
27
+ spec.add_runtime_dependency "capybara", ["~> 2.7.1"]
28
+ spec.add_runtime_dependency "capybara-extensions", ["~> 0.4.1"]
29
+ spec.add_runtime_dependency "selenium-webdriver", ["~> 2.53.3"]
30
+ spec.add_runtime_dependency "rspec", ["~> 3.4.0"]
31
+ spec.add_development_dependency "gemspec_deps_gen", [">= 0"]
32
+ spec.add_development_dependency "gemcutter", [">= 0"]
33
+
34
+
35
+ end
@@ -8,7 +8,7 @@ class CapybaraHelper
8
8
  DEFAULT_BROWSER = :chrome
9
9
  DEFAULT_WAIT_TIME = 2
10
10
 
11
- attr_reader :headless_mode, :video_mode
11
+ attr_reader :headless_mode, :video_mode, :parallel_tests_mode
12
12
 
13
13
  def initialize
14
14
  Capybara.run_server = false
@@ -21,7 +21,7 @@ class CapybaraHelper
21
21
  rescue LoadError
22
22
  @headless_mode = false
23
23
 
24
- puts "Headless mode is not supported on this OS."
24
+ headless_mode_not_supported
25
25
  end
26
26
  end
27
27
 
@@ -33,28 +33,22 @@ class CapybaraHelper
33
33
  def before_test(app_host:, driver: DEFAULT_DRIVER, browser: DEFAULT_BROWSER, wait_time: DEFAULT_WAIT_TIME)
34
34
  @old_driver = Capybara.current_driver
35
35
 
36
- driver_name = register_driver driver: driver, browser: browser, selenium_url: nil, capabilities: nil
36
+ driver_name = register_driver driver, browser: browser, selenium_url: nil, capabilities: nil
37
37
 
38
38
  use_driver(driver_name)
39
39
 
40
- # driver_manager.setup_browser_binary config[:browser].to_sym, config[:browser_binaries]
41
-
42
40
  Capybara.app_host = app_host
43
41
 
44
42
  @old_default_max_wait_time = Capybara.default_max_wait_time
45
43
 
46
44
  Capybara.configure do |conf|
47
45
  conf.default_max_wait_time = wait_time
48
-
49
- # conf.match = :first
50
- #
51
- # conf.ignore_hidden_elements = false
52
46
  end
53
47
 
54
48
  if headless_mode
55
49
  headless_params = {}
56
- #headless_params[:display] = @parallel_tests_mode ? 100 + test_number : 1
57
- headless_params[:reuse] = @parallel_tests_mode ? true : false
50
+ headless_params[:display] = 100 + test_number
51
+ headless_params[:reuse] = parallel_tests_mode ? true : false
58
52
  headless_params[:dimensions] = "1280x900x24"
59
53
 
60
54
  headless_params[:video] = {
@@ -67,19 +61,23 @@ class CapybaraHelper
67
61
  log_file_path: STDERR
68
62
  } if video_mode
69
63
 
70
- @headless = Headless.new headless_params
64
+ begin
65
+ @headless = Headless.new headless_params
71
66
 
72
- @headless.start
67
+ @headless.start
73
68
 
74
- #page.driver.browser.manage.window.resize_to(1280, 900)
69
+ @headless.video.start_capture if video_mode
70
+ rescue Headless::Exception
71
+ @headless_mode = false
75
72
 
76
- @headless.video.start_capture if video_mode
73
+ headless_mode_not_supported
74
+ end
77
75
  end
78
76
 
79
77
  driver_name
80
78
  end
81
79
 
82
- def after_test metadata: nil, exception: nil
80
+ def after_test name: nil, exception: nil
83
81
  Capybara.default_driver = @old_driver
84
82
  Capybara.current_driver = @old_driver
85
83
  Capybara.javascript_driver = @old_driver
@@ -91,68 +89,27 @@ class CapybaraHelper
91
89
  end
92
90
 
93
91
  if headless_mode
94
-
95
- #p metadata[:file_path]
96
-
97
- #if exception
98
- #File.basename(e.metadata[:file_path]
99
-
100
- name = 'report'
101
-
102
- @headless.video.stop_and_save "video_#{test_number}_#{name}.mp4" if video_mode
103
- # else
104
- # @headless.video.stop_and_discard if video_mode
105
- # end
92
+ if video_mode
93
+ @headless.video.stop_and_save success_video_name(name)
94
+ else
95
+ if exception
96
+ @headless.video.stop_and_save error_video_name(name, exception)
97
+ else
98
+ @headless.video.stop_and_discard
99
+ end
100
+ end
106
101
 
107
102
  @headless.destroy
108
103
  end
109
104
  end
110
105
 
111
- def test_number
112
- @parallel_tests_mode ? + ENV['TEST_ENV_NUMBER'].to_i : 1
113
- end
114
-
115
- def take_screenshot
116
- if headless_mode
117
- #@headless.take_screenshot
118
- end
119
- end
120
-
121
- private
122
-
123
- def register_driver driver:, browser: DEFAULT_BROWSER, selenium_url: nil, capabilities: nil
106
+ def register_driver driver, browser: DEFAULT_BROWSER, selenium_url: nil, capabilities: nil
124
107
  driver_name = build_driver_name(driver: driver, browser: browser, selenium_url: selenium_url)
125
108
 
126
- # case driver
127
- # # when :poltergeist
128
- # # require 'capybara/poltergeist'
129
- #
130
- # when :webkit
131
- # require "capybara-webkit"
132
- #
133
- # when :firefox_with_firebug
134
- # require 'capybara/firebug'
135
- #
136
- # else
137
- # ;
138
- # end
139
-
140
- # if driver == :poltergeist
141
- # properties = {}
142
- # properties[:debug] = false
143
- #
144
- # Capybara.register_driver :poltergeist do |app|
145
- # Capybara::Poltergeist::Driver.new(app, properties)
146
- # end
147
- # elsif driver == :webkit
148
- # ;
149
- # else
150
109
  if driver == :selenium
151
110
  properties = {}
152
111
 
153
- if not selenium_url
154
- properties[:browser] = browser
155
- else
112
+ if selenium_url
156
113
  properties[:browser] = :remote
157
114
  properties[:url] = selenium_url
158
115
 
@@ -166,7 +123,7 @@ class CapybaraHelper
166
123
  when :chrome
167
124
  caps = Selenium::WebDriver::Remote::Capabilities.chrome
168
125
  else
169
- ;
126
+ caps = nil
170
127
  end
171
128
 
172
129
  desired_capabilities =
@@ -181,20 +138,63 @@ class CapybaraHelper
181
138
  end
182
139
 
183
140
  properties[:desired_capabilities] = desired_capabilities if desired_capabilities
141
+ else
142
+ properties[:browser] = browser
184
143
  end
185
144
 
186
145
  Capybara.register_driver driver_name do |app|
187
146
  Capybara::Selenium::Driver.new(app, properties)
188
147
  end
148
+
149
+ # elsif driver == :poltergeist
150
+ # require 'capybara/poltergeist'
151
+ #
152
+ # properties = {}
153
+ # properties[:debug] = false
154
+ #
155
+ # Capybara.register_driver :poltergeist do |app|
156
+ # Capybara::Poltergeist::Driver.new(app, properties)
157
+ # end
158
+ #
159
+ # elsif driver == :webkit
160
+ # require "capybara-webkit"
189
161
  end
190
162
 
191
163
  driver_name
192
164
  end
193
165
 
166
+ def take_screenshot
167
+ file_path = '/vagrant/screenshot.jpg'
168
+
169
+ if headless_mode
170
+ @headless.take_screenshot file_path, {using: :imagemagick}
171
+ end
172
+ end
173
+
174
+ private
175
+
176
+ def test_number
177
+ parallel_tests_mode ? ENV['TEST_ENV_NUMBER'].to_i : 1
178
+ end
179
+
180
+ def error_video_name name, exception
181
+ exception_name = exception && exception.respond_to?(:name) ? exception.name : 'exception'
182
+
183
+ "#{exception_name}_#{name}.mp4"
184
+ end
185
+
186
+ def success_video_name name
187
+ "#{name}.mp4"
188
+ end
189
+
190
+ def headless_mode_not_supported
191
+ puts "Headless mode is not supported on this OS."
192
+ end
193
+
194
194
  def build_driver_name driver:, browser:, selenium_url: nil
195
195
  case driver
196
- when :webkit
197
- :webkit
196
+ # when :webkit
197
+ # :webkit
198
198
  # when :poltergeist
199
199
  # :poltergeist
200
200
  when :selenium