Skip to content

Commit

Permalink
Merge pull request #66 from automate-website/#53-selenium-3-4-0
Browse files Browse the repository at this point in the history
Upgraded selenium-java to 3.4.0 (#53)
  • Loading branch information
build-failure authored Jul 9, 2017
2 parents d4bf4eb + 7cbc139 commit 2aa555a
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 36 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ java -jar <path to jar> -<argument name> [<argument value> ...]
| *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].

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium-java.version>2.53.1</selenium-java.version>
<selenium-java.version>3.4.0</selenium-java.version>
</properties>

<licenses>
Expand Down

This file was deleted.

60 changes: 30 additions & 30 deletions src/main/java/website/automate/jwebrobot/report/Reporter.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
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;
import website.automate.jwebrobot.listener.ExecutionEventListener;
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;

Expand Down Expand Up @@ -84,22 +78,28 @@ public void beforeAction(ScenarioExecutionContext context, Action action) {
actionReportMap.put(action, actionReport);
}

private void processLogEntries(ScenarioExecutionContext context, ActionReport actionReport) {
List<org.openqa.selenium.logging.LogEntry> logEntries = context.getDriver().manage().logs().get("browser").getAll();
ExecutorOptions options = context.getGlobalContext().getOptions();

List<LogEntry> convertedLogEntries = new ArrayList<>();
void processLogEntries(ScenarioExecutionContext context, ActionReport actionReport) {
try {
List<org.openqa.selenium.logging.LogEntry> 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<LogEntry> 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) {
Expand Down
97 changes: 97 additions & 0 deletions src/test/java/website/automate/jwebrobot/report/ReporterTest.java
Original file line number Diff line number Diff line change
@@ -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<List<website.automate.waml.report.io.model.LogEntry>> 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<website.automate.waml.report.io.model.LogEntry> logEntryList = logEntryListCaptor.getValue();
assertThat(logEntryList, hasSize(1));
}
}

0 comments on commit 2aa555a

Please sign in to comment.