soda 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Soda.rb CHANGED
@@ -46,6 +46,7 @@ require "SodaCSV"
46
46
  require "SodaXML"
47
47
  require 'SodaFireFox'
48
48
  require 'SodaTestCheck'
49
+ require 'SodaScreenShot'
49
50
  require "utils/sodalookups"
50
51
  require "fields/SodaField"
51
52
  require "fields/TextField"
@@ -2667,6 +2668,17 @@ JSCode
2667
2668
  @rep.ReportFailure(msg)
2668
2669
  PrintDebug("Global Time was: #{$global_time}\n")
2669
2670
  PrintDebug("Timeout Time was: #{time_check}\n")
2671
+
2672
+ begin
2673
+ result_dir = @rep.GetResultDir()
2674
+ shooter = SodaScreenShot.new(result_dir)
2675
+ image_file = shooter.GetOutputFile()
2676
+ @rep.log("ScreenShot taken: #{image_file}\n")
2677
+ rescue Excaption => e
2678
+ @rep.ReportException(e, false, false)
2679
+ ensure
2680
+ end
2681
+
2670
2682
  result = -1
2671
2683
  thread_soda.exit()
2672
2684
  break
@@ -614,6 +614,21 @@ HTML
614
614
  return row_data
615
615
  end
616
616
 
617
+ def FormatScreenShot(line)
618
+ row_data = Hash.new()
619
+ line =~ /\[(\d+\/\d+\/\d+-\d+:\d+:\d+)\](\(.\))(.*)/
620
+ row_data['date'] = "#{$1}"
621
+ row_data['msg_type'] = "#{$2}"
622
+ msg = "#{$3}"
623
+ row_html = ""
624
+
625
+ data = msg.split(/:/)
626
+ msg = "<b>#{data[0]}:</b> <a href=\"file://#{data[1]}\">#{data[1]}</a>"
627
+ row_data['msg'] = msg
628
+
629
+ return row_data
630
+ end
631
+
617
632
  ###############################################################################
618
633
  # FormatReplacingString -- Method
619
634
  # This method finds the replace string message and reformats it a little.
@@ -725,6 +740,8 @@ HTML
725
740
  row_data = FormatClickingElement(line)
726
741
  when /element:/i
727
742
  row_data = FormatClickingElement(line)
743
+ when /screenshot\staken/i
744
+ row_data = FormatScreenShot(line)
728
745
  else
729
746
  line =~ /\[(\d+\/\d+\/\d+-\d+:\d+:\d+)\](\(.\))(.*)/
730
747
  row_data['date'] = "#{$1}"
data/lib/SodaReporter.rb CHANGED
@@ -113,6 +113,20 @@ class SodaReporter
113
113
  log("Saving HTML files => #{@saveHtmlFiles.to_s()}.\n")
114
114
  end
115
115
 
116
+ ###############################################################################
117
+ # GetResultDir -- Method
118
+ # This method returns the current result dir.
119
+ #
120
+ # Input:
121
+ # None.
122
+ #
123
+ # Output:
124
+ # returns the current result directory.
125
+ #
126
+ ###############################################################################
127
+ def GetResultDir()
128
+ return @ResultsDir
129
+ end
116
130
 
117
131
  ###############################################################################
118
132
  # IncSkippedTest -- Method
@@ -0,0 +1,174 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010, SugarCRM, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of SugarCRM, Inc. nor the
13
+ # names of its contributors may be used to endorse or promote products
14
+ # derived from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ # ARE DISCLAIMED. IN NO EVENT SHALL SugarCRM, Inc. BE LIABLE FOR ANY
20
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ ###############################################################################
27
+
28
+ require 'SodaUtils'
29
+
30
+ ###############################################################################
31
+ # SodaScreenShot -- Class
32
+ # This class is for taking desktop screen shots of the current running os.
33
+ # Currently only Winows & Linux are supported. Really any unix platform
34
+ # running X11 is supported, they just have to be added to the case.
35
+ #
36
+ # Input:
37
+ # dir: This is the directory to store the snapshots in.
38
+ #
39
+ ###############################################################################
40
+ class SodaScreenShot
41
+
42
+ LINUX_XWD_BIN = "xwd"
43
+ LINUX_CONVERT_BIN = "convert"
44
+ OUTPUT_FILE = "screenshot-"
45
+
46
+ def initialize(dir)
47
+ os = nil
48
+ err = nil
49
+ time = Time.now()
50
+ time = time.to_i()
51
+ hostname = "#{ENV['HOSTNAME']}"
52
+ @outputfile = nil
53
+
54
+ if (!File.exist?(dir))
55
+ raise "Failed to find needed diectory: '#{dir}!'\n"
56
+ end
57
+
58
+ if ( (hostname.empty?) || (hostname.length < 5) )
59
+ hostname = `hostname`
60
+ hostname = hostname.chomp()
61
+ end
62
+
63
+ os = SodaUtils.GetOsType()
64
+ case (os)
65
+ when /linux/i
66
+ xwd = FindLinuxXwd()
67
+ if (xwd == nil)
68
+ raise "Failed to find needed program: 'xwd'!\n"
69
+ end
70
+
71
+ @outputfile = "#{dir}/#{OUTPUT_FILE}#{time}-#{hostname}.xwd"
72
+ cmd = "#{xwd} -root -out #{@outputfile}"
73
+ err = Kernel.system(cmd)
74
+ if (!err)
75
+ raise "Failed trying to take screenshot!\n"
76
+ end
77
+
78
+ convert = FindLinuxConvert()
79
+ if (convert != nil)
80
+ old_outfile = @outputfile
81
+ ext = File.extname(old_outfile)
82
+ @outputfile = @outputfile.gsub(/#{ext}$/, "")
83
+ @outputfile << ".png"
84
+ cmd = "#{convert} #{old_outfile} #{@outputfile}"
85
+ err = Kernel.system(cmd)
86
+ if (!err)
87
+ @outputfile = old_outfile
88
+ else
89
+ File.unlink(old_outfile)
90
+ end
91
+ end
92
+ when /windows/i
93
+ require 'Win32/screenshot'
94
+ @outputfile = "#{dir}/#{OUTPUT_FILE}#{time}-#{hostname}.bmp"
95
+ Win32::Screenshot.desktop do |width, height, bmp|
96
+ fd = File.new(@outputfile, "w+")
97
+ fd.write(bmp)
98
+ fd.close()
99
+ end
100
+ end
101
+ end
102
+
103
+ ###############################################################################
104
+ # GetOutputFile -- Method
105
+ # This is a getter for getting the newly created snapshot file.
106
+ #
107
+ # Input:
108
+ # None.
109
+ #
110
+ # Output:
111
+ # retutns a string with the full path and filename to the new file.
112
+ #
113
+ ###############################################################################
114
+ def GetOutputFile()
115
+ return @outputfile
116
+ end
117
+
118
+ ###############################################################################
119
+ # FindLinuxXwd -- Method
120
+ # This method trys to find the xwd X11 util in you current path.
121
+ #
122
+ # Input:
123
+ # None.
124
+ #
125
+ # Output:
126
+ # Returns the full path and exe name on success or nil on failure.
127
+ #
128
+ ###############################################################################
129
+ def FindLinuxXwd()
130
+ tmp = nil
131
+ found = nil
132
+
133
+ tmp = ENV['PATH'].split(/:/)
134
+ tmp.each do |p|
135
+ path = "#{p}/#{LINUX_XWD_BIN}"
136
+ if (File.exist?(path))
137
+ found = path
138
+ break
139
+ end
140
+ end
141
+
142
+ return found
143
+ end
144
+ private :FindLinuxXwd
145
+
146
+ ###############################################################################
147
+ # FindLinuxConvert -- Method
148
+ # This method trys to find the linux convert util in you current path.
149
+ #
150
+ # Input:
151
+ # None.
152
+ #
153
+ # Output:
154
+ # Returns the full path and exe name on success or nil on failure.
155
+ #
156
+ ###############################################################################
157
+ def FindLinuxConvert()
158
+ tmp = nil
159
+ found = nil
160
+
161
+ tmp = ENV['PATH'].split(/:/)
162
+ tmp.each do |p|
163
+ path = "#{p}/#{LINUX_CONVERT_BIN}"
164
+ if (File.exist?(path))
165
+ found = path
166
+ break
167
+ end
168
+ end
169
+
170
+ return found
171
+ end
172
+ private :FindLinuxConvert
173
+
174
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soda
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Trampus Richmond
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-09 00:00:00 -08:00
18
+ date: 2010-11-10 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ extra_rdoc_files: []
59
59
  files:
60
60
  - lib/SodaReportSummery.rb
61
61
  - lib/SodaCSV.rb
62
+ - lib/SodaScreenShot.rb
62
63
  - lib/soda.rb
63
64
  - lib/SodaXML.rb
64
65
  - lib/SodaUtils.rb