Skip to content

Commit

Permalink
Merge pull request #4819 from thc202/selenium/add-more-stats
Browse files Browse the repository at this point in the history
selenium: add browser launch stats with requester
  • Loading branch information
psiinon authored Aug 18, 2023
2 parents 2a56f0d + 6abbf32 commit 76f657f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions addOns/selenium/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Add statistics for browser launch successes and failures that include the requester, e.g.:
- `stats.selenium.launch.<requester-id>.<browser-id>`
- `stats.selenium.launch.<requester-id>.<browser-id>.failure`

### Changed
- Maintenance changes.
- Update Selenium to version 4.11.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,7 @@ public static WebDriver getWebDriver(
String proxyAddress,
int proxyPort,
boolean enableExtensions) {
validateProxyAddressPort(proxyAddress, proxyPort);

WebDriver wd =
getWebDriverImpl(
requester, browser, proxyAddress, proxyPort, c -> {}, enableExtensions);
webDrivers.add(wd);
updateStats(browser);
return wd;
return getWebDriver(requester, browser, proxyAddress, proxyPort, c -> {}, enableExtensions);
}

public static WebDriver getWebDriver(
Expand All @@ -914,8 +907,6 @@ public static WebDriver getWebDriver(
int proxyPort,
Consumer<MutableCapabilities> consumer,
boolean enableExtensions) {
validateProxyAddressPort(proxyAddress, proxyPort);

return getWebDriver(-1, browser, proxyAddress, proxyPort, consumer, enableExtensions);
}

Expand All @@ -928,16 +919,33 @@ public static WebDriver getWebDriver(
boolean enableExtensions) {
validateProxyAddressPort(proxyAddress, proxyPort);

WebDriver wd =
getWebDriverImpl(
requester, browser, proxyAddress, proxyPort, consumer, enableExtensions);
WebDriver wd;
try {
wd =
getWebDriverImpl(
requester,
browser,
proxyAddress,
proxyPort,
consumer,
enableExtensions);
updateLaunchStats(requester, browser, true);
} catch (Exception e) {
updateLaunchStats(requester, browser, false);
throw e;
}
webDrivers.add(wd);
updateStats(browser);
return wd;
}

private static void updateStats(Browser browser) {
Stats.incCounter("stats.selenium.launch." + browser.getId());
private static void updateLaunchStats(int requester, Browser browser, boolean success) {
String key = "stats.selenium.launch." + requester + "." + browser.getId();
if (success) {
Stats.incCounter("stats.selenium.launch." + browser.getId());
} else {
key += ".failure";
}
Stats.incCounter(key);
}

private static void setCommonOptions(
Expand Down

0 comments on commit 76f657f

Please sign in to comment.