Skip to content

Commit

Permalink
MAD2-151 Browser not closing once the Automation Test Failed
Browse files Browse the repository at this point in the history
  • Loading branch information
rcsantiago committed May 2, 2017
1 parent 5cb8ed2 commit 5aee45e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Expand Up @@ -163,9 +163,12 @@ class MadcowTestCase implements IJSONSerializable {
}

this.lastExecutedStep = step;
if (step.result.failed())
if (step.result.failed()) {
if (!new MadcowConfig().closeBrowserOnFail) {
stepRunner.setFailed()
}
throw new RuntimeException("Step <${step.blade.line}> failed - ${step.result}");

}
if ((step.children != null) && (!step.children.empty)) {
step.stopWatch.reset();
step.stopWatch.start();
Expand Down
Expand Up @@ -46,6 +46,7 @@ class MadcowConfig implements IJSONSerializable {
public int retryCount = 0;

public boolean parallel = true;
public boolean closeBrowserOnFail = true;

public String stepRunner;
public HashMap<String, String> stepRunnerParameters;
Expand Down Expand Up @@ -117,6 +118,16 @@ class MadcowConfig implements IJSONSerializable {
}
}

//get the default closeBrowserOnFail run setting if set
def closeBrowserOnFailTxt = this.execution."closeBrowserOnFail"?.text() ?: '';
if (closeBrowserOnFailTxt != '') {
try {
closeBrowserOnFail = !closeBrowserOnFailTxt.equals("false") as boolean;
} catch (ignored) {
throw new Exception('Invalid "closeBrowserOnFail" field specified - only true or false is allowed');
}
}

// get the default retry count and use it if none is set
def retriesText = this.execution."retries".text() ?: '1';
if (retriesText != '') {
Expand Down
Expand Up @@ -32,6 +32,7 @@ import au.com.ps4impact.madcow.MadcowTestCase
abstract class MadcowStepRunner {

public MadcowTestCase testCase;
private boolean isFailed = false

public MadcowStepRunner() {
this(null);
Expand All @@ -46,6 +47,13 @@ abstract class MadcowStepRunner {
// overridden in children
}

public boolean isFailed(){
return isFailed
}

public boolean setFailed(){
isFailed = true
}
/**
* Execute a MadcowStep. This is the main entry point for calling
* out to a MadcowStepRunner.
Expand Down
1 change: 1 addition & 0 deletions madcow-core/src/main/resources/madcow-config.xsd
Expand Up @@ -43,6 +43,7 @@
</xs:element>
<xs:element name="env.default" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="parallel" minOccurs="0" maxOccurs="1" type="xs:boolean"/>
<xs:element name="closeBrowserOnFail" minOccurs="0" maxOccurs="1" type="xs:boolean"/>
<xs:element name="retries" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:nonNegativeInteger">
Expand Down
Expand Up @@ -21,6 +21,7 @@

package au.com.ps4impact.madcow.runner.webdriver

import au.com.ps4impact.madcow.config.MadcowConfig
import au.com.ps4impact.madcow.runner.webdriver.driver.WebDriverType
import au.com.ps4impact.madcow.step.MadcowStepRunner
import au.com.ps4impact.madcow.step.MadcowStep
Expand Down Expand Up @@ -432,7 +433,8 @@ class WebDriverStepRunner extends MadcowStepRunner {
}

public void finishTestCase() {
if (_lazyDriver == null) {
//if test is failed and closeBrowserOnFail = false then don't close the browser
if (_lazyDriver == null || ( isFailed())) {
return;
}
if (driverType == WebDriverType.CHROME) {
Expand Down

0 comments on commit 5aee45e

Please sign in to comment.