From 616ffb1fb21b79fbdeda40f392a50bf6e9a330bf Mon Sep 17 00:00:00 2001
From: Pavel Anihimovsky <47742067+pavelanihimovsky@users.noreply.github.com>
Date: Thu, 21 May 2020 09:36:40 +0300
Subject: [PATCH] Add method getLogs to Browser (#98)
* Add method getLogs to Browser
* Increase version
* Update aquality-selenium-core
---
pom.xml | 4 ++--
.../aquality/selenium/browser/Browser.java | 21 ++++++++++++++-----
.../configuration/BrowserProfile.java | 2 +-
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 67a718d..0edf774 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.aquality-automation
aquality-selenium
- 2.2.0
+ 2.3.0
jar
Aquality Selenium
@@ -74,7 +74,7 @@
com.github.aquality-automation
aquality-selenium-core
- 1.0.1
+ 1.0.2
diff --git a/src/main/java/aquality/selenium/browser/Browser.java b/src/main/java/aquality/selenium/browser/Browser.java
index 6206993..2f45657 100644
--- a/src/main/java/aquality/selenium/browser/Browser.java
+++ b/src/main/java/aquality/selenium/browser/Browser.java
@@ -12,6 +12,7 @@
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver.Navigation;
+import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
@@ -23,14 +24,15 @@
import java.util.function.Supplier;
public class Browser implements IApplication {
+
private final RemoteWebDriver webDriver;
private final ITimeoutConfiguration timeouts;
- private Duration timeoutImpl;
private final IBrowserProfile browserProfile;
private final IConditionalWait conditionalWait;
private final ILocalizationManager localizationManager;
private final ILocalizedLogger localizedLogger;
+ private Duration implicitTimeout;
public Browser(RemoteWebDriver remoteWebDriver) {
conditionalWait = AqualityServices.getConditionalWait();
@@ -39,8 +41,8 @@ public Browser(RemoteWebDriver remoteWebDriver) {
this.browserProfile = AqualityServices.getBrowserProfile();
this.timeouts = AqualityServices.get(ITimeoutConfiguration.class);
webDriver = remoteWebDriver;
- this.timeoutImpl = timeouts.getImplicit();
- getDriver().manage().timeouts().implicitlyWait(timeoutImpl.getSeconds(), TimeUnit.SECONDS);
+ this.implicitTimeout = timeouts.getImplicit();
+ getDriver().manage().timeouts().implicitlyWait(implicitTimeout.getSeconds(), TimeUnit.SECONDS);
setPageLoadTimeout(timeouts.getPageLoad());
setScriptTimeout(timeouts.getScript());
}
@@ -161,7 +163,7 @@ public void setImplicitWaitTimeout(Duration timeout) {
localizedLogger.debug("loc.browser.implicit.timeout", timeout.getSeconds());
if (!timeout.equals(getImplicitWaitTimeout())) {
getDriver().manage().timeouts().implicitlyWait(timeout.getSeconds(), TimeUnit.SECONDS);
- timeoutImpl = timeout;
+ implicitTimeout = timeout;
}
}
@@ -201,6 +203,15 @@ public byte[] getScreenshot() {
return getDriver().getScreenshotAs(OutputType.BYTES);
}
+ /**
+ * Gets logs from WebDriver.
+ * @param logKind Type of logs {@link org.openqa.selenium.logging.LogType}
+ * @return Storage of LogEntries.
+ */
+ public LogEntries getLogs(final String logKind) {
+ return getDriver().manage().logs().get(logKind);
+ }
+
/**
* Executes JS (jQuery) script asynchronous.
*
@@ -350,6 +361,6 @@ public final BrowserName getBrowserName() {
}
private Duration getImplicitWaitTimeout() {
- return timeoutImpl;
+ return implicitTimeout;
}
}
diff --git a/src/main/java/aquality/selenium/configuration/BrowserProfile.java b/src/main/java/aquality/selenium/configuration/BrowserProfile.java
index 841aa3e..80f6919 100644
--- a/src/main/java/aquality/selenium/configuration/BrowserProfile.java
+++ b/src/main/java/aquality/selenium/configuration/BrowserProfile.java
@@ -36,7 +36,7 @@ public boolean isElementHighlightEnabled() {
@Override
public IDriverSettings getDriverSettings() {
IDriverSettings driverSettings;
- switch (getBrowserName()){
+ switch (getBrowserName()) {
case CHROME:
driverSettings = new ChromeSettings(settingsFile);
break;