Skip to content

Commit

Permalink
add support for RemoteWebDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Sep 14, 2023
1 parent c9fa586 commit 4647516
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
SPRING_ACTUATOR_PORT: 8081
SPRING_ADMIN_SERVER_HOST: localhost
SPRING_ADMIN_SERVER_PORT: 9090
WEBDRIVER_API_URI: http://chrome:4444/wd/hub
WITHINGS_ACCOUNTS_URI: https://account.withings.com
WITHINGS_API_URI: https://wbsapi.withings.net
STRAVA_API_URI: https://www.strava.com
Expand Down Expand Up @@ -54,3 +55,8 @@ services:
chmod 600 /tmp/pgpass;
/entrypoint.sh;
"
chrome:
image: seleniarm/standalone-chromium:116.0-chromedriver-116.0-grid-4.10.0-20230828
restart: unless-stopped
shm_size: '2gb'
36 changes: 36 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,41 @@
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Start e2e environment",
"command": "node",
"args": [
"docker-compose.js",
"|",
"docker",
"compose",
"--file",
"-",
"up",
"--force-recreate",
"--build",
"--remove-orphans",
"--wait",
"--pull",
"always"
],
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Run e2e tests",
"command": "mvn",
"args": ["test"],
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/test"
},
"problemMatcher": []
},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.Data;

@Data
@Configuration
@ConfigurationProperties(prefix = "webdriver")
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=*");
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;
ChromeDriver driver = new ChromeDriver(options);
driver.setLogLevel(Level.WARNING);
return driver;
}

// @Bean
// public WebDriver getWebDriver() throws MalformedURLException {
// ChromeOptions options = new ChromeOptions();
// ChromeOptions options = new ChromeOptions().addArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage");

// RemoteWebDriver driver = new RemoteWebDriver(new URL("http://chrome:4444"),
// options);
// driver.setLogLevel(Level.WARNING);
// return driver;
// RemoteWebDriver driver = new RemoteWebDriver(new URL(apiUri), options);
// driver.setLogLevel(Level.WARNING);
// return new Augmenter().augment(driver);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.v113.network.Network;
import org.openqa.selenium.devtools.v113.network.model.RequestId;
import org.openqa.selenium.devtools.v113.network.model.ResourceType;
Expand Down Expand Up @@ -62,7 +62,7 @@ public Optional<Fitness> getFitnessLevel() {
WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
wait.until(ExpectedConditions
.visibilityOfElementLocated(By.id("email")));
DevTools devTools = ((ChromeDriver) webDriver).getDevTools();
DevTools devTools = ((HasDevTools) webDriver).getDevTools();
devTools.createSession();
List<RequestId> matches = new ArrayList<>();
devTools.send(Network.enable(Optional.of(1000000), Optional.empty(), Optional.empty()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"properties": [
{
"name": "withings",
"type": "mucsi96.traininglog.withings.WithingsConfiguration",
"description": "Configuration for Withings API"
},
{
"name": "strava",
"type": "mucsi96.traininglog.strava.StravaCOnfiguration",
"description": "Configuration for Strava API"
}
]
}
{"properties": [
{
"name": "withings",
"type": "mucsi96.traininglog.withings.WithingsConfiguration",
"description": "Configuration for Withings API"
},
{
"name": "strava",
"type": "mucsi96.traininglog.strava.StravaCOnfiguration",
"description": "Configuration for Strava API"
},
{
"name": "webdriver",
"type": "mucsi96.traininglog.core.WebDriverConfiguration",
"description": "Configuration for webdriver"
}
]}
2 changes: 2 additions & 0 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ logging:
springdoc:
swagger-ui:
path: /
webdriver:
api-uri: ${WEBDRIVER_API_URI}
withings:
api-uri: ${WITHINGS_API_URI}
strava:
Expand Down

0 comments on commit 4647516

Please sign in to comment.