Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #132 from neilkimmett/master
Browse files Browse the repository at this point in the history
Add `test` action, for when you only want to run tests
  • Loading branch information
KrauseFx committed Apr 20, 2015
2 parents abb07ff + 3cce1af commit 0a99115
Showing 3 changed files with 33 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -157,6 +157,12 @@ To skip cleaning the project:
snapshot --noclean
```

To only run tests (i.e. don't actually take any screenshots):
```
snapshot test
```


By default, `snapshot`, will re-install the app, to make sure it's in a clean state. In case you don't want this run

```
14 changes: 14 additions & 0 deletions bin/snapshot
Original file line number Diff line number Diff line change
@@ -42,6 +42,20 @@ class SnapshotApplication
end
end

command :test do |c|
c.syntax = 'snapshot test'
c.description = 'Runs the automated tests.'

c.action do |args, options|
path = (Snapshot::Helper.fastlane_enabled?? './fastlane' : '.')
Dir.chdir(path) do # switch the context
Snapshot::DependencyChecker.check_simulators
Snapshot::SnapshotConfig.shared_instance(options.snapfile)
Snapshot::Runner.new.work(clean: !options.noclean, build: !options.nobuild, take_snapshots: false)
end
end
end

command :init do |c|
c.syntax = 'snapshot init'
c.description = "Creates a new Snapfile in the current directory"
16 changes: 13 additions & 3 deletions lib/snapshot/runner.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module Snapshot
class Runner
TRACE_DIR = '/tmp/snapshot_traces'

def work(clean: true, build: true)
def work(clean: true, build: true, take_snapshots: true)
SnapshotConfig.shared_instance.js_file # to verify the file can be found earlier

Builder.new.build_app(clean: clean) if build
@@ -14,7 +14,7 @@ def work(clean: true, build: true)
counter = 0
errors = []

FileUtils.rm_rf SnapshotConfig.shared_instance.screenshots_path if SnapshotConfig.shared_instance.clear_previous_screenshots
FileUtils.rm_rf SnapshotConfig.shared_instance.screenshots_path if (SnapshotConfig.shared_instance.clear_previous_screenshots and take_snapshots)

SnapshotConfig.shared_instance.devices.each do |device|
SnapshotConfig.shared_instance.languages.each do |language_item|
@@ -32,7 +32,7 @@ def work(clean: true, build: true)

begin
errors.concat(run_tests(device, language, locale))
counter += copy_screenshots(language)
counter += copy_screenshots(language) if take_snapshots
rescue => ex
Helper.log.error(ex)
end
@@ -43,6 +43,8 @@ def work(clean: true, build: true)

`killall "iOS Simulator"` # close the simulator after the script is finished

return unless take_snapshots

ReportsGenerator.new.generate

if errors.count > 0
@@ -132,6 +134,10 @@ def run_tests(device, language, locale)
retry_run = true
when :screenshot
Helper.log.info "Successfully took screenshot 📱"
when :pass
Helper.log.info line.strip.gsub("Pass:", "✓").green
when :fail
Helper.log.info line.strip.gsub("Fail:", "✗").red
when :need_permission
raise "Looks like you may need to grant permission for Instruments to analyze other processes.\nPlease Ctrc + C and run this command: \"#{command}\""
end
@@ -182,6 +188,10 @@ def parse_test_line(line)
return :screenshot
elsif line.include? "Instruments wants permission to analyze other processes"
return :need_permission
elsif line.include? "Pass: "
return :pass
elsif line.include? "Fail: "
return :fail
elsif line =~ /.*Error: (.*)/
raise "UIAutomation Error: #{$1}"
elsif line =~ /Instruments Usage Error :(.*)/

0 comments on commit 0a99115

Please sign in to comment.