Skip to content

Commit

Permalink
Hook up the original results write to the new htmlrunner.
Browse files Browse the repository at this point in the history
Although it doesn't actually report the correct results yet.
  • Loading branch information
shs96c committed Jul 18, 2016
1 parent 9044e15 commit 28035f0
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 65 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,23 @@ public void run(Results results, WebDriver driver, Selenium selenium) {
driver.get(url);
}

String rawSource = driver.getPageSource();
List<LoggableStep> steps = findCommands(driver);
TestState state = new TestState();
List<StepResult> testResults = new ArrayList<>(steps.size());
List<StepResult> stepResults = new ArrayList<>(steps.size());
NextStepDecorator decorator = NextStepDecorator.IDENTITY;
for (LoggableStep step : steps) {
LOG.info(step.toString());
decorator = Preconditions.checkNotNull(decorator.evaluate(step, selenium, state), step);
testResults.add(new StepResult(step, null));
stepResults.add(new StepResult(step, decorator.getCause()));
if (!decorator.isOkayToContinueTest()) {
break;
} else {
stepResults.add(new StepResult(step, null));
}
}

results.addTest(rawSource, stepResults);
}

private List<LoggableStep> findCommands(WebDriver driver) {
Expand Down Expand Up @@ -124,7 +129,7 @@ public String toString() {
}
}

private static class StepResult {
static class StepResult {
private final LoggableStep step;
private final Throwable cause;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void run(Results results, WebDriver driver, Selenium selenium) {
allTables.get(0));

for (String testUrl : allTestUrls) {
new CoreTest(testUrl).run(results, driver, selenium);
new CoreTestCase(testUrl).run(results, driver, selenium);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Expand All @@ -43,12 +46,14 @@

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -146,9 +151,21 @@ private String runHTMLSuite(String browser, String browserURL, String suiteURL,
driver = createDriver(browser);
URL suiteUrl = determineSuiteUrl(browserURL, suiteURL);

driver.get(suiteUrl.toString());
Selenium selenium = new WebDriverBackedSelenium(driver, browserURL);
Results results = new Results();
new CoreTest(suiteUrl.toString()).run(results, driver, selenium);
List<WebElement> allTables = driver.findElements(By.id("suiteTable"));
if (allTables.isEmpty()) {
throw new RuntimeException("Unable to find suite table: " + driver.getPageSource());
}
String rawSuite =
(String) ((JavascriptExecutor) driver).executeScript("return arguments[0].outerHTML", allTables.get(0));
Results results = new Results(rawSuite);
new CoreTestSuite(suiteUrl.toString()).run(results, driver, selenium);

HTMLTestResults htmlResults = results.toSuiteResult();
try (Writer writer = Files.newBufferedWriter(outputFile.toPath())) {
htmlResults.write(writer);
}

return results.isSuccessful() ? "PASSED" : "FAILED";
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,52 @@

abstract class NextStepDecorator {

static NextStepDecorator IDENTITY = new NextStepDecorator() {
static NextStepDecorator IDENTITY = new NextStepDecorator(null) {

@Override
public boolean isOkayToContinueTest() {
return true;
}
};

static NextStepDecorator ASSERTION_FAILED = new NextStepDecorator() {
static NextStepDecorator ASSERTION_FAILED = new NextStepDecorator(null) {

@Override
public boolean isOkayToContinueTest() {
return false;
}
};

static NextStepDecorator VERIFICATION_FAILED = new NextStepDecorator() {
static NextStepDecorator VERIFICATION_FAILED = new NextStepDecorator(null) {

@Override
public boolean isOkayToContinueTest() {
return true;
}
};

public abstract boolean isOkayToContinueTest();
private final Throwable cause;

public NextStepDecorator() {
this(null);
}

public NextStepDecorator(Throwable cause) {
this.cause = cause;
}

public abstract boolean isOkayToContinueTest();

public NextStepDecorator evaluate(CoreStep nextStep, Selenium selenium, TestState state) {
return nextStep.execute(selenium, state);
}

public Throwable getCause() {
return cause;
}

public static NextStepDecorator ERROR(Throwable cause) {
return new NextStepDecorator() {
return new NextStepDecorator(cause) {
@Override
public boolean isOkayToContinueTest() {
return false;
Expand Down
60 changes: 58 additions & 2 deletions java/server/src/org/openqa/selenium/server/htmlrunner/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,71 @@

package org.openqa.selenium.server.htmlrunner;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import org.openqa.selenium.internal.BuildInfo;

import java.util.LinkedList;
import java.util.List;

public class Results {

private final String suiteSource;
private final List results = new LinkedList<>();
private final List<String> allTables = new LinkedList<>();
private final StringBuilder log = new StringBuilder();
private final long start = System.currentTimeMillis();

private boolean succeeded = true;
private long numberOfPasses;
private long commandPasses;
private long commandFailures;
private long commandErrors;

public Results(String suiteSource) {
this.suiteSource = suiteSource;
}

public boolean isSuccessful() {
return succeeded;
}

public void addTestFailure() {
succeeded = false;
public void addTest(String rawSource, List<CoreTestCase.StepResult> stepResults) {
allTables.add(rawSource);
boolean passed = true;
for (CoreTestCase.StepResult stepResult : stepResults) {
passed &= stepResult.isSuccessful();
if (stepResult.isSuccessful()) {
commandPasses++;
} else if (stepResult.isError()) {
commandErrors++;
} else {
commandFailures++;
}
}

if (passed) {
numberOfPasses++;
}
}

public HTMLTestResults toSuiteResult() {
BuildInfo buildInfo = new BuildInfo();

return new HTMLTestResults(
buildInfo.getReleaseLabel(),
buildInfo.getBuildRevision(),
isSuccessful() ? "PASS" : "FAIL",
String.valueOf(SECONDS.convert(System.currentTimeMillis() - start, MILLISECONDS)),
String.valueOf(results.size()),
String.valueOf(numberOfPasses),
String.valueOf(results.size() - numberOfPasses),
String.valueOf(commandPasses),
String.valueOf(commandFailures),
String.valueOf(commandErrors),
suiteSource,
allTables,
log.toString());
}
}

0 comments on commit 28035f0

Please sign in to comment.