From 1a905443b7d77484537027d061da7a01b072e566 Mon Sep 17 00:00:00 2001 From: Igor Bari Date: Thu, 14 Sep 2023 11:40:13 +0000 Subject: [PATCH] chore: fix webdriver configuration --- .../core/WebDriverConfiguration.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/mucsi96/traininglog/core/WebDriverConfiguration.java b/server/src/main/java/mucsi96/traininglog/core/WebDriverConfiguration.java index 4eee1fd..4f2b9a6 100644 --- a/server/src/main/java/mucsi96/traininglog/core/WebDriverConfiguration.java +++ b/server/src/main/java/mucsi96/traininglog/core/WebDriverConfiguration.java @@ -1,13 +1,18 @@ package mucsi96.traininglog.core; +import java.net.MalformedURLException; +import java.net.URL; import java.util.logging.Level; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.Augmenter; +import org.openqa.selenium.remote.RemoteWebDriver; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import lombok.Data; @@ -18,22 +23,24 @@ public class WebDriverConfiguration { private String apiUri; @Bean - public WebDriver getWebDriver() { - ChromeOptions options = new ChromeOptions().addArguments("--headless", - "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage", - "--window-size=1920,1080", "--remote-allow-origins=*"); - - ChromeDriver driver = new ChromeDriver(options); - driver.setLogLevel(Level.WARNING); - return driver; + @Profile({ "test", "local" }) + public WebDriver getLocalWebDriver() { + ChromeOptions options = new ChromeOptions().addArguments("--headless", + "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage", + "--window-size=1920,1080", "--remote-allow-origins=*"); + + ChromeDriver driver = new ChromeDriver(options); + driver.setLogLevel(Level.WARNING); + return driver; } - // @Bean - // public WebDriver getWebDriver() throws MalformedURLException { - // ChromeOptions options = new ChromeOptions().addArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage"); + @Bean + @Profile({ "prod" }) + public WebDriver getRemoteWebDriver() throws MalformedURLException { + ChromeOptions options = new ChromeOptions().addArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage"); - // RemoteWebDriver driver = new RemoteWebDriver(new URL(apiUri), options); - // driver.setLogLevel(Level.WARNING); - // return new Augmenter().augment(driver); - // } + RemoteWebDriver driver = new RemoteWebDriver(new URL(apiUri), options); + driver.setLogLevel(Level.WARNING); + return new Augmenter().augment(driver); + } }