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

Workaround for webdrivermanager #825

Merged
merged 3 commits into from Oct 2, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,12 +5,16 @@

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import static io.github.bonigarcia.wdm.WebDriverManager.config;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class WebDriverBinaryManager {
private static final Logger log = Logger.getLogger(WebDriverBinaryManager.class.getName());

public void setupBinaryPath(Browser browser) {
if (browser.isChrome()) setupChrome();
if (browser.isEdge()) setupEdge();
Expand Down Expand Up @@ -58,20 +62,35 @@ private void setupFirefox() {

private void cacheMeIfYouCan(String systemPropertyName, Runnable webdriverSetup) {
if (webdriverIsAlreadyInitialized(systemPropertyName)) {
log.info("Skip: webdriver is already initialized: " + System.getProperty(systemPropertyName));
Copy link
Collaborator

@rosolko rosolko Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it on info level?
I think debug will be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to delete this commit in future. It's temporary needed to debug the problem.

return;
}

File lastCheckIndicator = new File(config().getTargetPath(), lastModifiedFileName(systemPropertyName));
boolean canUseCachedWebdriver = lastCheckIndicator.exists() && hasRecentlyCheckedForUpdates(lastCheckIndicator);
log.info("lastCheckIndicator=" + lastCheckIndicator.getAbsolutePath() +
", exists=" + lastCheckIndicator.exists() + ", lastModified=" + new Date(lastCheckIndicator.lastModified()) +
", now=" + new Date() + ", diff: " + (System.currentTimeMillis() - lastCheckIndicator.lastModified()) + " ms.");

if (canUseCachedWebdriver) {
log.info("Can use cache");
config().setForceCache(true);
}
else {
log.info("Cannot use cache");
}

webdriverSetup.run();

if (!canUseCachedWebdriver) {
long ts = System.currentTimeMillis();
log.info("Mark as recently checked: " + lastCheckIndicator.getAbsolutePath() + ", ts=" + ts + ", now=" + new Date(ts));
markAsRecentlyChecked(lastCheckIndicator);
}
else {
long ts = System.currentTimeMillis();
log.info("Not marking as recently checked: " + lastCheckIndicator.getAbsolutePath() + ", ts=" + ts + ", now=" + new Date(ts));
}
}

private boolean webdriverIsAlreadyInitialized(String systemPropertyName) {
Expand Down