Skip to content

Commit

Permalink
Grid screenshot issue (#50)
Browse files Browse the repository at this point in the history
* 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 <balavengaiah.matam@dwp.gov.uk>
  • Loading branch information
balu836 and balavengaiah.matam authored Apr 21, 2020
1 parent bdcaffa commit c8ddfbf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/main/java/uk/co/evoco/webdriver/WebDriverListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,17 @@ public void afterSwitchToWindow(String s, WebDriver webDriver) {
* @param webDriver active WebDriver instance
*/
public void onException(Throwable throwable, WebDriver webDriver) {
File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
try {
String filename = new StringBuilder(UUID.randomUUID().toString())
.append("-FAILED-")
.append(throwable.getClass().getName())
.append(".jpeg")
.toString();

FileUtils.copyFile(scrFile, new File(screenshotDirectory.getPath() + "/" + filename));
if(TestConfigHelper.get().isTakeScreenshotOnError()) {
File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
String filename = new StringBuilder(UUID.randomUUID().toString())
.append("-FAILED-")
.append(throwable.getClass().getName())
.append(".jpeg")
.toString();

FileUtils.copyFile(scrFile, new File(screenshotDirectory.getPath() + "/" + filename));
}
} catch (Exception e) {
logger.error("Unable to Save to directory: {}", screenshotDirectory.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class WebDriverConfig {
private Map<String, ObjectNode> browserPreferences;
private TolerantActionExceptions tolerantActionExceptions;
private MetricsConfig metricsConfig;
private boolean takeScreenshotOnError;

/**
*
Expand Down Expand Up @@ -220,4 +221,17 @@ public void setMetricsConfig(MetricsConfig metricsConfig) {
public MetricsConfig getMetricsConfig() {
return metricsConfig;
}

/**
*
* @return takeScreenshotOnErrors boolean configuring for taking screenshots on Errors
*/
public boolean isTakeScreenshotOnError() {
return takeScreenshotOnError;
}

@JsonProperty("takeScreenshotOnError")
public void setTakeScreenshotOnError(boolean takeScreenshotOnError) {
this.takeScreenshotOnError = takeScreenshotOnError;
}
}
3 changes: 2 additions & 1 deletion src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"baseUrl": "https://www.google.com",
"timeout": "30",
"headless": true,
"runType": "GRID",
"runType": "LOCAL",
"takeScreenshotOnError": true,
"testConfig": {
"sample": "sample text"
},
Expand Down

0 comments on commit c8ddfbf

Please sign in to comment.