sapphire 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,42 +5,68 @@ require 'sapphire'
5
5
  include Sapphire::Sapphire
6
6
 
7
7
  $reporters = []
8
+ $instances = []
8
9
 
9
10
  ARGV.each do |arg|
11
+ if arg.start_with? "reporter="
12
+ item = arg.split "reporter="
13
+ $reporters << item.last
10
14
 
11
- #if arg.start_with? "reporter="
12
- # item = arg.split "reporter="
13
- # $reporters << Object.const_get(item.last).new()
14
- # next
15
- #end
15
+ next
16
+ end
17
+
18
+ if arg.start_with? "file="
19
+ item = arg.split "file="
20
+ @file = item.last
21
+ next
22
+ end
16
23
 
17
24
  if !arg.end_with? ".rb"
18
25
  next
19
26
  end
20
27
 
21
28
  require arg
22
- Runner.instance.last_scenario.file_name = arg if Runner.instance.last_scenario and Runner.instance.last_scenario.file_name == ""
23
- end
24
29
 
25
- if $reporters.empty?
26
- $reporters << ConsoleReporter.new()
30
+ Runner.instance.last_scenario.file_name = arg if Runner.instance.last_scenario and Runner.instance.last_scenario.file_name == ""
27
31
  end
28
32
 
29
33
  def Report(&block)
30
- $reporters.each do |reporter|
34
+ $instances.each do |reporter|
31
35
  block.call reporter
32
36
  end
33
37
  end
34
38
 
35
- if Runner.instance.test_plans.count > 0
36
- Runner.instance.last_test_plan.execute
37
- else
38
- Report do |x| x.BeginTesting end
39
+ def Process()
40
+ $reporters.each do |r|
41
+ $instances << Object.const_get(r).new()
42
+ $instances.last.file = @file if $instances.last.is_a? HtmlReporter
43
+ end
39
44
 
40
- Runner.instance.scenarios.each do |scenario|
41
- scenario.execute
45
+ if $instances.empty?
46
+ $instances << ConsoleReporter.new()
42
47
  end
43
48
 
44
- Report do |x| x.TestingComplete end
45
- Report do |x| x.OutputResults end
46
- end
49
+ if Runner.instance.test_plans.count > 0
50
+ Runner.instance.last_test_plan.execute
51
+ else
52
+ Report do |x| x.BeginTesting end
53
+
54
+ Runner.instance.scenarios.each do |scenario|
55
+ scenario.execute
56
+ end
57
+
58
+ Report do |x| x.TestingComplete end
59
+ Report do |x| x.OutputResults end
60
+ end
61
+ end
62
+
63
+ if @file.nil?
64
+ Process()
65
+ else
66
+ File.open(@file, 'w') do |f|
67
+ $stdout = f
68
+ Process()
69
+ end
70
+ end
71
+
72
+
@@ -8,6 +8,10 @@ module Sapphire
8
8
  @rootUrl = url
9
9
  end
10
10
 
11
+ def Screenshot(file_name)
12
+ self.browser.save_screenshot(file_name)
13
+ end
14
+
11
15
  def Close
12
16
  self.browser.close
13
17
  end
@@ -5,10 +5,22 @@ module Sapphire
5
5
  if(item.is_a? Job)
6
6
  job = item
7
7
  if(job.Arg)
8
- system(job.PsExecPath + " " + job.Server + " " + job.Path + " " + job.Arg.to_s)
8
+ @command = job.Path + " " + job.Arg.to_s
9
9
  else
10
- system(job.PsExecPath + " " + job.Server + " " + job.Path)
10
+ @command = job.Path
11
11
  end
12
+
13
+ psFile = "C:\\runjob.ps1"
14
+ psCommand = "& icm " + job.Server + " {" + @command + "}"
15
+ File.open(psFile, 'w') {|f| f.write(psCommand) }
16
+ puts ""
17
+ puts ""
18
+ puts "executing your job via powershell command: " + psCommand
19
+ system "powershell -inputformat none " + psFile
20
+ File.delete(psFile)
21
+ puts ""
22
+ puts ""
23
+
12
24
  else
13
25
  Runner.instance.last_test_plan.Add(item)
14
26
  end
@@ -54,7 +54,7 @@ module Sapphire
54
54
  end
55
55
 
56
56
  def Report(&block)
57
- $reporters.each do |reporter|
57
+ $instances.each do |reporter|
58
58
  block.call reporter
59
59
  end
60
60
  end
@@ -53,10 +53,10 @@ module Sapphire
53
53
  end
54
54
  @output.puts ""
55
55
  result.stack.each do |line|
56
- #if (!line.include? "sapphire")
56
+ if (!line.include? "sapphire")
57
57
  Indent(depth+1)
58
58
  @output.puts line
59
- #end
59
+ end
60
60
  end
61
61
 
62
62
  end
@@ -42,7 +42,7 @@ module Sapphire
42
42
  end
43
43
 
44
44
  def Report(&block)
45
- $reporters.each do |reporter|
45
+ $instances.each do |reporter|
46
46
  block.call reporter
47
47
  end
48
48
  end
@@ -1,7 +1,12 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+
1
4
  module Sapphire
2
5
  module Testing
3
6
  class HtmlReporter < Reporter
4
7
 
8
+ attr_accessor :file
9
+
5
10
  def initialize()
6
11
  @failures = []
7
12
  @example_group_number = 0
@@ -11,6 +16,7 @@ module Sapphire
11
16
  @broken_count = 0
12
17
  @test_count = 0
13
18
  @output = $stdout
19
+ @file = ""
14
20
  end
15
21
 
16
22
  def TestStarted(test)
@@ -49,6 +55,14 @@ module Sapphire
49
55
  end
50
56
  end
51
57
 
58
+ content = []
59
+ content << "<span>"
60
+
61
+ file_name = save_screenshot
62
+ content << link_for(file_name)
63
+
64
+ content << "</span>"
65
+ @output.puts content
52
66
  @output.puts " </div>"
53
67
  @output.puts " </dd>"
54
68
  end
@@ -306,6 +320,37 @@ a {
306
320
  }
307
321
  EOF
308
322
  end
323
+
324
+ def save_screenshot
325
+ if(!$driver)
326
+ return
327
+ end
328
+
329
+ begin
330
+ file_name = file_path("image.png")
331
+ $driver.Screenshot(file_name)
332
+ rescue => e
333
+ $stderr.puts "saving of screenshot failed."
334
+ $stderr.puts e.backtrace
335
+ end
336
+ file_name
337
+ end
338
+
339
+ def file_path(file_name)
340
+ extension = File.extname(file_name)
341
+ basename = File.basename(file_name, extension)
342
+ dir = File.dirname(@file)
343
+ file_path = File.join(dir, "", "#{basename}_#{Time.now.strftime("%H%M%S")}#{extension}")
344
+ file_path
345
+ end
346
+
347
+ def link_for(file_name)
348
+ return unless file_name && File.exists?(file_name)
349
+
350
+ path = Pathname.new(file_name)
351
+
352
+ "<a href='#{File.basename(path)}'>Screenshot</a>&nbsp;"
353
+ end
309
354
  end
310
355
  end
311
356
  end
@@ -3,7 +3,7 @@ module Sapphire
3
3
  module TestRunnerAdapter
4
4
 
5
5
  def Report(&block)
6
- $reporters.each do |reporter|
6
+ $instances.each do |reporter|
7
7
  block.call reporter
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.7.8"
2
+ VERSION = "0.7.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapphire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-13 00:00:00.000000000Z
12
+ date: 2012-03-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &9870684 !ruby/object:Gem::Requirement
16
+ requirement: &9714480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9870684
24
+ version_requirements: *9714480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &9870432 !ruby/object:Gem::Requirement
27
+ requirement: &9714228 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9870432
35
+ version_requirements: *9714228
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Platform
38
- requirement: &9870180 !ruby/object:Gem::Requirement
38
+ requirement: &9713976 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9870180
46
+ version_requirements: *9713976
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email: