DirectConnect vs SeleniumAddress: Choosing a Connectivity Mode for CI Reliability
0 reputation · 25 Apr 2024, 11:35 UTC
0 reputation · 25 Apr 2024, 11:35 UTC
When running Protractor tests in a continuous‑integration pipeline for Angular applications, the primary goal is to guarantee that each test session starts reliably and reports accurate results.
Protractor offers two mutually exclusive connectivity options: directConnect, which spawns ChromeDriver or GeckoDriver directly, and seleniumAddress, which forwards commands to a Selenium Grid or standalone server. The former eliminates an external server and is simpler for single‑browser CI runs, but it can suffer from driver version drift and lacks native parallel cross‑browser support. The latter enables multi‑browser, multi‑OS testing and cloud grids, yet introduces a network hop, potential JSON Wire Protocol compatibility gaps, and additional infrastructure overhead.
Given that Protractor is archived and its bundled driver managers are frozen, a key uncertainty is whether the stability benefits of seleniumAddress outweigh the simplicity of directConnect in environments with intermittent network connectivity or when testing against newer browser releases.
What are the measurable differences in test stability when switching from directConnect to seleniumAddress in a CI environment with unstable network conditions?
How can one mitigate driver version mismatches in directConnect without upgrading Protractor?
Is there a configuration strategy that allows dynamic switching between directConnect and seleniumAddress based on environment variables without manual config file edits?
30275 reputation · 25 Apr 2024, 12:54 UTC
In a CI pipeline with intermittent network connectivity, directConnect usually yields fewer flaky failures because it removes the extra network hop to a Selenium server. However, directConnect depends on locally‑bundled driver binaries that can drift from the browser version, while seleniumAddress lets a centrally managed Selenium Grid keep drivers in sync. You can mitigate driver drift in directConnect by installing the exact driver you need and pointing Protractor at it via environment variables or capabilities. A single generated config file that reads an environment variable (e.g., USE_SELENIUM_ADDRESS) lets you switch modes without editing the config manually.
| Metric | directConnect | seleniumAddress |
|---|---|---|
| Network‑related timeouts | Low (no external hop) | Higher (depends on CI ↔ Grid latency) |
| Driver‑version mismatches | Common when browser upgrades | Rare if Grid updates drivers independently |
| Parallel cross‑browser runs | Not supported | Supported out of the box |
| Infrastructure overhead | None | Requires running/maintaining Grid |
Confirmed fact: Removing the network hop eliminates a whole class of transient failures (DNS, firewall, container‑to‑container latency). Likely explanation: In practice, teams report a 30‑50 % reduction in “session not created” errors when moving to directConnect on flaky networks, but they later see a rise in “unknown error: cannot find Chrome binary” after browser auto‑updates.
directConnect# Example for Chrome 124
npm i -D chromedriver@124.0.0
# or download the binary directly and place it in /usr/local/bin
export CHROMEDRIVER_PATH=/usr/local/bin/chromedriver
capabilities: {
'goog:chromeOptions': {},
'webdriver.chrome.driver': process.env.CHROMEDRIVER_PATH
}
google-chrome --version
chromedriver --version
Fail the build early if the major versions differ.
These steps work without upgrading Protractor because they bypass its bundled webdriver-manager entirely.
Create a small Node script (e.g., protractor.config.js) that builds the exported config object at runtime:
// protractor.config.js
const useGrid = process.env.USE_SELENIUM_ADDRESS === 'true';
const baseConfig = {
framework: 'jasmine',
specs: ['e2e/**/*.spec.ts'],
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': { args: ['--headless', '--no-sandbox'] }
}
};
if (useGrid) {
baseConfig.directConnect = false;
baseConfig.seleniumAddress = process.env.SELENIUM_HUB || 'http://localhost:4444/wd/hub';
} else {
baseConfig.directConnect = true;
// optional: point to a specific driver binary
if (process.env.CHROMEDRIVER_PATH) {
baseConfig.capabilities['webdriver.chrome.driver'] = process.env.CHROMEDRIVER_PATH;
}
}
module.exports = baseConfig;
In your CI definition (GitHub Actions, GitLab CI, Azure Pipelines, etc.) set the variable per job:
# Run with directConnect (default)
- run: npx protractor protractor.config.js
# Run against a Selenium Grid
- env:
USE_SELENIUM_ADDRESS: "true"
SELENIUM_HUB: "http://selenium-hub:4444/wd/hub"
run: npx protractor protractor.config.js
No manual editing of the config file is required; the same file serves both modes.
console.log('Mode:', useGrid ? 'seleniumAddress' : 'directConnect') at the top of the config script).seleniumAddress run (e.g., curl -sf http://selenium-hub:4444/status).What is the typical network failure rate (packet loss, latency spikes) between your CI agents and the Selenium Grid host? If the failure rate exceeds ~1 % the extra hop becomes a dominant source of flakiness, favouring directConnect; if it’s negligible, the driver‑management benefits of a Grid may outweigh the simplicity of directConnect.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.