View Javadoc

1   /*
2    * Copyright 2007 united internet (unitedinternet.com) Robert Zimmermann
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package com.unitedinternet.portal.selenium.utils.logging;
18  
19  import org.apache.commons.lang.ArrayUtils;
20  
21  /**
22   * Metrics and environment information (user-agent, versions) collected during test run.
23   *
24   * TODO: maybe also count commandsProcessed, verificationsProcessed which were not inside a Wait
25   *
26   * @author robertzimmermann
27   *
28   * $Id: TestMetricsBean.java 96 2008-04-05 10:36:28Z bobbyde $
29   */
30  public class TestMetricsBean {
31      private long startTimeStamp;
32  
33      private long endTimeStamp;
34  
35      private static final String LOGGING_SELENIUM_REVISION = "$Revision: 96 $";
36  
37      private static final int REVISION_PREFIX_LENGTH = "$Revision: ".length();
38  
39      private long commandsProcessed = 0;
40  
41      private long failedCommands = 0;
42  
43      private long verificationsProcessed = 0;
44  
45      private String userAgent;
46  
47      private String seleniumCoreVersion;
48  
49      private String seleniumCoreRevision;
50  
51      private String seleniumRcVersion;
52  
53      private String seleniumRcRevision;
54  
55      private String lastFailedCommandMessage;
56  
57      String[] commandsExcludedFromLogging = {};
58  
59      public long getStartTimeStamp() {
60          return startTimeStamp;
61      }
62  
63      public void setStartTimeStamp(long startTimeStamp) {
64          this.startTimeStamp = startTimeStamp;
65      }
66  
67      public long getEndTimeStamp() {
68          return endTimeStamp;
69      }
70  
71      public void setEndTimeStamp(long endTimeStamp) {
72          this.endTimeStamp = endTimeStamp;
73      }
74  
75      public long getCommandsProcessed() {
76          return commandsProcessed;
77      }
78  
79      public void setCommandsProcessed(long commandsProcessed) {
80          this.commandsProcessed = commandsProcessed;
81      }
82  
83      /**
84       * Increment commandsProcessed by one.
85       *
86       * Convenience method to shortcut usage like this: setCommandsProcessed(getCommandsProcessed()+1)
87       */
88      public void incCommandsProcessed() {
89          this.commandsProcessed++;
90      }
91  
92      public long getFailedCommands() {
93          return failedCommands;
94      }
95  
96      public void setFailedCommands(long failedCommands) {
97          this.failedCommands = failedCommands;
98      }
99  
100     /**
101      * Increment failedCommands by one.
102      *
103      * Convenience method to shortcut usage like this: setFailedCommands(getFailedCommands()+1)
104      */
105     public void incFailedCommands() {
106         this.failedCommands++;
107     }
108 
109     /**
110      * Compute test duration out of startTimeStamp and endTimeStamp.
111      *
112      * wrong values are negative startTimeStamp or negative difference
113      * between endTimeStamp and startTimeStamp
114      *
115      * @return duration in millis. will be 0 in case of missing or wrong values
116      */
117     public long getTestDuration() {
118         long testDuration = 0;
119         if (startTimeStamp > 0 && endTimeStamp > startTimeStamp) {
120             testDuration = endTimeStamp - startTimeStamp;
121         }
122         return testDuration;
123     }
124 
125     public long getVerificationsProcessed() {
126         return verificationsProcessed;
127     }
128 
129     public void setVerificationsProcessed(long verificationsProcessed) {
130         this.verificationsProcessed = verificationsProcessed;
131     }
132 
133     /**
134      * Increment verificationsProcessed by one.
135      *
136      * Convenience method to shortcut usage like this: setVerificationsProcessed(getVerificationsProcessed()+1)
137      */
138     public void incVerificationsProcessed() {
139         this.verificationsProcessed++;
140     }
141 
142     public String getUserAgent() {
143         return userAgent;
144     }
145 
146     public void setUserAgent(String userAgent) {
147         this.userAgent = userAgent;
148     }
149 
150     public String getSeleniumCoreVersion() {
151         return seleniumCoreVersion;
152     }
153 
154     public void setSeleniumCoreVersion(String seleniumCoreVersion) {
155         this.seleniumCoreVersion = seleniumCoreVersion;
156     }
157 
158     public String getSeleniumCoreRevision() {
159         return seleniumCoreRevision;
160     }
161 
162     public void setSeleniumCoreRevision(String seleniumCoreRevision) {
163         this.seleniumCoreRevision = seleniumCoreRevision;
164     }
165 
166     public String getSeleniumRcVersion() {
167         return seleniumRcVersion;
168     }
169 
170     public void setSeleniumRcVersion(String seleniumRcVersion) {
171         this.seleniumRcVersion = seleniumRcVersion;
172     }
173 
174     public String getSeleniumRcRevision() {
175         return seleniumRcRevision;
176     }
177 
178     public void setSeleniumRcRevision(String seleniumRcRevision) {
179         this.seleniumRcRevision = seleniumRcRevision;
180     }
181 
182     public String getLastFailedCommandMessage() {
183         return lastFailedCommandMessage;
184     }
185 
186     public void setLastFailedCommandMessage(String lastFailedCommandMessage) {
187         this.lastFailedCommandMessage = lastFailedCommandMessage;
188     }
189 
190     public String getLoggingSeleniumRevision() {
191         return LOGGING_SELENIUM_REVISION.substring(REVISION_PREFIX_LENGTH, LOGGING_SELENIUM_REVISION.length() - 2);
192     }
193 
194     public String[] getCommandsExcludedFromLogging() {
195         return (String[]) ArrayUtils.clone(commandsExcludedFromLogging);
196     }
197 
198     public void setCommandsExcludedFromLogging(String[] commandsExcludedFromLogging) {
199         this.commandsExcludedFromLogging = (String[]) ArrayUtils.clone(commandsExcludedFromLogging);
200     }
201 }