Skip to content

Commit c8ddfbf

Browse files
balu836balavengaiah.matam
andauthored
Grid screenshot issue (#50)
* added exception wait time out to handle tolerant methods * applied the changes as mentioned in the review comments for tolerant methods * Changed the method to package private to not expose this method * Added test to validate the tolerant method without passing wait time for method * changed the variable names for the TolerantAction object as mentioned * futureDataAvoidingWeekendsAndBankHolidays issue which need to avoid weekends when adding bank holidays count * added overload method for tolerantItemByIndex and tolerantItemByHtmlValueAttribute * resolved conflicts * changed from private package to public * Changed onException method to take screenshot only on Local run not on running on grid * Changed onException method to take screenshot only on Local run not on running on grid * Added boolean parameter in config file to handle taking snapshots Co-authored-by: balavengaiah.matam <[email protected]>
1 parent bdcaffa commit c8ddfbf

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/main/java/uk/co/evoco/webdriver/WebDriverListener.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,17 @@ public void afterSwitchToWindow(String s, WebDriver webDriver) {
246246
* @param webDriver active WebDriver instance
247247
*/
248248
public void onException(Throwable throwable, WebDriver webDriver) {
249-
File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
250249
try {
251-
String filename = new StringBuilder(UUID.randomUUID().toString())
252-
.append("-FAILED-")
253-
.append(throwable.getClass().getName())
254-
.append(".jpeg")
255-
.toString();
256-
257-
FileUtils.copyFile(scrFile, new File(screenshotDirectory.getPath() + "/" + filename));
250+
if(TestConfigHelper.get().isTakeScreenshotOnError()) {
251+
File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
252+
String filename = new StringBuilder(UUID.randomUUID().toString())
253+
.append("-FAILED-")
254+
.append(throwable.getClass().getName())
255+
.append(".jpeg")
256+
.toString();
257+
258+
FileUtils.copyFile(scrFile, new File(screenshotDirectory.getPath() + "/" + filename));
259+
}
258260
} catch (Exception e) {
259261
logger.error("Unable to Save to directory: {}", screenshotDirectory.getPath());
260262
}

src/main/java/uk/co/evoco/webdriver/configuration/WebDriverConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class WebDriverConfig {
2525
private Map<String, ObjectNode> browserPreferences;
2626
private TolerantActionExceptions tolerantActionExceptions;
2727
private MetricsConfig metricsConfig;
28+
private boolean takeScreenshotOnError;
2829

2930
/**
3031
*
@@ -220,4 +221,17 @@ public void setMetricsConfig(MetricsConfig metricsConfig) {
220221
public MetricsConfig getMetricsConfig() {
221222
return metricsConfig;
222223
}
224+
225+
/**
226+
*
227+
* @return takeScreenshotOnErrors boolean configuring for taking screenshots on Errors
228+
*/
229+
public boolean isTakeScreenshotOnError() {
230+
return takeScreenshotOnError;
231+
}
232+
233+
@JsonProperty("takeScreenshotOnError")
234+
public void setTakeScreenshotOnError(boolean takeScreenshotOnError) {
235+
this.takeScreenshotOnError = takeScreenshotOnError;
236+
}
223237
}

src/test/resources/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"baseUrl": "https://www.google.com",
44
"timeout": "30",
55
"headless": true,
6-
"runType": "GRID",
6+
"runType": "LOCAL",
7+
"takeScreenshotOnError": true,
78
"testConfig": {
89
"sample": "sample text"
910
},

0 commit comments

Comments
 (0)