diff --git a/README.md b/README.md index 5698eff..823b0ee 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,22 @@ java -jar - [ ...] | *screenshotType* | optional | Defines the way screenshots must be taken - fullscreen vs. viewport. | `VIEW_PORT` | `FULLSCREEN` | | *screenshotFormat* | optional | Defines the screenshot format. | `png` | `gif` | | *takeScreenshots* | optional | Defines when to take screenshots: NEVER, ON_FAILURE, ON_EVERY_STEP | `ON_FAILURE` | `./` | -| *browser* | optional | A browser can be selected by passing this option when running JWebRobot. Please consider that some browsers require additional configuration parameters. WAML scenarios are executed with Mozilla Firefox per default. Firefox must be installed on the same machine. E.g.: Chrome does not provide embedded webdriver so that it has to be [downloaded manually](webdriver-chrome). The path to the downloaded executable has to be forwarded via the system property `webdriver.chrome.driver`. Of course, Chrome must be present on the same machine. | `firefox` | `chrome` | +| *browser* | optional | A browser can be selected by passing this option when running JWebRobot. Please consider that some browsers require additional configuration parameters. WAML scenarios are executed with Mozilla Firefox per default. Firefox must be installed on the same machine. E.g.: Chrome does not provide embedded webdriver so that it has to be [downloaded manually](webdriver-chrome). The path to the downloaded executable has to be forwarded via the system property `webdriver.chrome.driver`. Of course, Chrome must be present on the same machine. | `firefox` | `chrome`, `chrome-headless`, `opera` | | *reportPath* | optional | Path to which the report is written to. | `./report.yaml` | `./myreport.yaml` | | *maximizeWindow* | optional | Toggles window maximization before scenario execution. | `false` | `true` | | *mode* | optional | Selects the execution mode. Currently legacy non-interactive and interactive mode with the possibility to pause/step-wise execution are supported. | `non-interactive` | `interactive` | +## Supported Browses + +Currently, the following browses-webdriver combinations are supported: + +| Browser | Version | WebDriver | +|---------|---------|-----------| +| Chrome | 59.0.3071.115 | [2.30](http://chromedriver.storage.googleapis.com/index.html?path=2.30/) | +| Firefox | 54.0.1 | [v0.17.0](https://github.com/mozilla/geckodriver/releases) | +| Opera | 46.0.2597.39 | [2.29](https://github.com/operasoftware/operachromiumdriver/releases) | + + ## Expressions Expression are evaluated by the awesome templating engine [freemarker]. The expression syntax and result may be tested using online [template-tester]. diff --git a/pom.xml b/pom.xml index 547e3d4..7c7902f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ UTF-8 - 2.53.1 + 3.4.0 diff --git a/src/main/java/website/automate/jwebrobot/executor/ExecutionResults.java b/src/main/java/website/automate/jwebrobot/executor/ExecutionResults.java deleted file mode 100644 index bf58408..0000000 --- a/src/main/java/website/automate/jwebrobot/executor/ExecutionResults.java +++ /dev/null @@ -1,4 +0,0 @@ -package website.automate.jwebrobot.executor; - -public class ExecutionResults { -} diff --git a/src/main/java/website/automate/jwebrobot/report/Reporter.java b/src/main/java/website/automate/jwebrobot/report/Reporter.java index 6f90c75..c981b1f 100644 --- a/src/main/java/website/automate/jwebrobot/report/Reporter.java +++ b/src/main/java/website/automate/jwebrobot/report/Reporter.java @@ -1,17 +1,10 @@ package website.automate.jwebrobot.report; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import com.google.inject.Inject; - +import org.openqa.selenium.UnsupportedCommandException; +import org.openqa.selenium.logging.LogType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import website.automate.jwebrobot.context.GlobalExecutionContext; import website.automate.jwebrobot.context.ScenarioExecutionContext; import website.automate.jwebrobot.executor.ExecutorOptions; @@ -19,16 +12,17 @@ import website.automate.waml.io.model.Scenario; import website.automate.waml.io.model.action.Action; import website.automate.waml.report.io.WamlReportWriter; -import website.automate.waml.report.io.model.ActionReport; -import website.automate.waml.report.io.model.ExecutionStatus; -import website.automate.waml.report.io.model.LogEntry; +import website.automate.waml.report.io.model.*; import website.automate.waml.report.io.model.LogEntry.LogLevel; -import website.automate.waml.report.io.model.ScenarioReport; -import website.automate.waml.report.io.model.SimpleActionReport; -import website.automate.waml.report.io.model.SimpleScenarioReport; -import website.automate.waml.report.io.model.WamlReport; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.util.*; public class Reporter implements ExecutionEventListener { + private static final Logger LOG = LoggerFactory.getLogger(Reporter.class); + private WamlReportWriter writer; @@ -84,22 +78,28 @@ public void beforeAction(ScenarioExecutionContext context, Action action) { actionReportMap.put(action, actionReport); } - private void processLogEntries(ScenarioExecutionContext context, ActionReport actionReport) { - List logEntries = context.getDriver().manage().logs().get("browser").getAll(); - ExecutorOptions options = context.getGlobalContext().getOptions(); - - List convertedLogEntries = new ArrayList<>(); + void processLogEntries(ScenarioExecutionContext context, ActionReport actionReport) { + try { + List logEntries = context.getDriver().manage().logs().get(LogType.BROWSER).getAll(); + ExecutorOptions options = context.getGlobalContext().getOptions(); - for (org.openqa.selenium.logging.LogEntry logEntry : logEntries) { - LogLevel actualLevel = convertLogLevel(logEntry.getLevel()); + // TODO extract mapper + List convertedLogEntries = new ArrayList<>(); - if(LogEntry.isIncluded(options.getBrowserLogLevel(), actualLevel)){ - convertedLogEntries.add(new LogEntry( - actualLevel, new Date(logEntry.getTimestamp()), logEntry.getMessage())); + for (org.openqa.selenium.logging.LogEntry logEntry : logEntries) { + LogLevel actualLevel = convertLogLevel(logEntry.getLevel()); + + if (LogEntry.isIncluded(options.getBrowserLogLevel(), actualLevel)) { + convertedLogEntries.add(new LogEntry( + actualLevel, new Date(logEntry.getTimestamp()), logEntry.getMessage())); + } } - } - actionReport.setLogEntries(convertedLogEntries); + actionReport.setLogEntries(convertedLogEntries); + } catch (UnsupportedCommandException e) { + // TODO set flag on the report: https://github.com/automate-website/waml-io/issues/2 + LOG.warn("Current WebDriver does not support browser logging!"); + } } private LogLevel convertLogLevel(java.util.logging.Level logLevel) { diff --git a/src/test/java/website/automate/jwebrobot/report/ReporterTest.java b/src/test/java/website/automate/jwebrobot/report/ReporterTest.java new file mode 100644 index 0000000..faa40f3 --- /dev/null +++ b/src/test/java/website/automate/jwebrobot/report/ReporterTest.java @@ -0,0 +1,97 @@ +package website.automate.jwebrobot.report; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.openqa.selenium.UnsupportedCommandException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.logging.LogEntries; +import org.openqa.selenium.logging.LogEntry; +import org.openqa.selenium.logging.LogType; +import org.openqa.selenium.logging.Logs; +import website.automate.jwebrobot.context.ScenarioExecutionContext; +import website.automate.waml.report.io.WamlReportWriter; +import website.automate.waml.report.io.model.ActionReport; + +import java.util.List; +import java.util.logging.Level; + +import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.class) +public class ReporterTest { + + @InjectMocks + private Reporter reporter; + + @Mock + private WamlReportWriter writer; + + @Mock + private ScenarioExecutionContext context; + + @Mock + private ActionReport actionReport; + + @Mock + private WebDriver webDriver; + + @Mock + private WebDriver.Options options; + + @Mock + private Logs logs; + + @Mock + private website.automate.jwebrobot.context.GlobalExecutionContext globalContext; + + @Mock + private website.automate.jwebrobot.executor.ExecutorOptions executorOptions; + + @Captor + private ArgumentCaptor> logEntryListCaptor; + + @Before + public void setUpContext() { + when(context.getDriver()).thenReturn(webDriver); + when(webDriver.manage()).thenReturn(options); + when(options.logs()).thenReturn(logs); + + when(context.getGlobalContext()).thenReturn(globalContext); + when(globalContext.getOptions()).thenReturn(executorOptions); + } + + @Test + public void shouldNotThrowErrorIfBrowserLogForwardingIsNotSupportedByTheDriver() { + when(logs.get(LogType.BROWSER)).thenThrow(UnsupportedCommandException.class); + + reporter.processLogEntries(context, actionReport); + } + + @Test + public void shouldConvertLogEntries() { + LogEntries logEntries = mock(LogEntries.class); + when(logs.get(LogType.BROWSER)).thenReturn(logEntries); + LogEntry logEntry = mock(LogEntry.class); + when(logEntries.getAll()).thenReturn(asList(logEntry)); + + when(logEntry.getLevel()).thenReturn(Level.FINEST); + when(executorOptions.getBrowserLogLevel()).thenReturn(website.automate.waml.report.io.model.LogEntry.LogLevel.DEBUG); + + reporter.processLogEntries(context, actionReport); + + verify(logEntries).getAll(); + + verify(actionReport).setLogEntries(logEntryListCaptor.capture()); + List logEntryList = logEntryListCaptor.getValue(); + assertThat(logEntryList, hasSize(1)); + } +}