Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] replace executor pool for driver close by fluent wait #227

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<repository>
<id>zebrunner_snapshots</id>
<name>zebrunner Snapshots</name>
<url>https://nexus.zebrunner.dev/repository/ce-snapshots/</url>
<url>https://public-nexus.zebrunner.com/repository/ce-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
Expand Down Expand Up @@ -567,7 +567,7 @@
<snapshotRepository>
<id>ZBR_Nexus</id>
<name>Zebrunner Snapshots</name>
<url>https://nexus.zebrunner.dev/repository/ce-snapshots/</url>
<url>https://public-nexus.zebrunner.com/repository/ce-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
59 changes: 19 additions & 40 deletions src/main/java/com/zebrunner/carina/webdriver/IDriverPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
package com.zebrunner.carina.webdriver;

import java.lang.invoke.MethodHandles;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import io.appium.java_client.remote.MobileCapabilityType;
import org.apache.commons.lang3.tuple.ImmutablePair;
Expand All @@ -36,10 +32,10 @@
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.support.decorators.Decorated;
import org.openqa.selenium.support.ui.FluentWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zebrunner.agent.core.registrar.Label;
import com.zebrunner.carina.utils.R;
import com.zebrunner.carina.utils.common.CommonUtils;
import com.zebrunner.carina.utils.commons.SpecialKeywords;
Expand Down Expand Up @@ -286,38 +282,27 @@ default void removeCapabilities() {
private void quitDriver(CarinaDriver carinaDriver, @Deprecated boolean keepProxyDuring) {
try {
carinaDriver.getDevice().disconnectRemote();

// castDriver to disable DriverListener operations on quit
WebDriver drv = castDriver(carinaDriver.getDriver());
POOL_LOGGER.debug("start driver quit: {}", carinaDriver.getName());

Future<?> future = Executors.newSingleThreadExecutor().submit((Callable<Void>) () -> {
if (Configuration.get(WebDriverConfiguration.Parameter.CHROME_CLOSURE, Boolean.class).orElse(false)) {
// workaround to not cleaned chrome profiles on hard drive
POOL_LOGGER.debug("Starting drv.close()");
drv.close();
POOL_LOGGER.debug("Finished drv.close()");
}
POOL_LOGGER.debug("Starting drv.quit()");
drv.quit();
POOL_LOGGER.debug("Finished drv.quit()");
return null;
});

// default timeout for driver quit 1/2 of explicit
long timeout = Configuration.getRequired(WebDriverConfiguration.Parameter.EXPLICIT_TIMEOUT, Integer.class) / 2;
Duration timeout = Duration.ofSeconds(Configuration.getRequired(Parameter.DRIVER_CLOSE_TIMEOUT, Integer.class));
try {
future.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
POOL_LOGGER.error("InterruptedException: Unable to quit driver!", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
if (e.getMessage() != null && e.getMessage().contains("not found in active sessions")) {
POOL_LOGGER.warn("Skip driver quit for already disconnected session!");
} else {
POOL_LOGGER.error("ExecutionException: Unable to quit driver!", e);
}
} catch (java.util.concurrent.TimeoutException e) {
new FluentWait<>(castDriver(carinaDriver.getDriver()))
.pollingEvery(timeout.plus(Duration.ofSeconds(5)))
.withTimeout(timeout)
.until(driver -> {
if (Configuration.get(WebDriverConfiguration.Parameter.CHROME_CLOSURE, Boolean.class).orElse(false)) {
// workaround to not cleaned chrome profiles on hard drive
POOL_LOGGER.debug("Starting drv.close()");
driver.close();
POOL_LOGGER.debug("Finished drv.close()");
}
POOL_LOGGER.debug("Starting drv.quit()");
driver.quit();
POOL_LOGGER.debug("Finished drv.quit()");
return true;
});
} catch (org.openqa.selenium.TimeoutException e) {
POOL_LOGGER.error("Unable to quit driver for {} sec!", timeout, e);
}
} catch (WebDriverException e) {
Expand All @@ -327,12 +312,6 @@ private void quitDriver(CarinaDriver carinaDriver, @Deprecated boolean keepProxy
POOL_LOGGER.error("Error discovered during driver quit!", e);
} finally {
POOL_LOGGER.debug("finished driver quit: {}", carinaDriver.getName());
if (!keepProxyDuring) {
// ProxyPool.stopProxy();
// if (com.zebrunner.carina.proxy.ProxyPool.isProxyRegistered()) {
// com.zebrunner.carina.proxy.ProxyPool.stopProxy();
// }
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public enum Parameter implements IParameter {
*/
ALLOW_FULLSIZE_SCREENSHOT("allow_fullsize_screenshot"),

/**
* Driver close timeout (in seconds). <b>Default: 20</b>
*/
DRIVER_CLOSE_TIMEOUT("driver_close_timeout"),

/**
* Timeout is seconds to wait for a certain condition to occur before proceeding further in the code.
* <b>Default: {@code 20}</b>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ proxy_pac_local=false
proxy_zebrunner_args=NULL
auto_screenshot=false
allow_fullsize_screenshot=false
driver_close_timeout=20
explicit_timeout=20
read_timeout=660
auto_download=false
Expand Down