Skip to content

Conversation

@AlexSanin
Copy link
Contributor

@AlexSanin AlexSanin commented Dec 25, 2025

Summary

Fixes #844

Previously, SeleniumRecordingContainer always created a new internal network, ignoring any network provided via withNetwork() or withNetworkMode(). This broke scenarios where Selenium needed to communicate with other containers on a shared network.

Changes

  • Added createNetworkIfNeeded() helper that only creates a network if the user didn't provide one
  • Updated ffmpeg container to use withNetworkMode() instead of withNetwork() for flexibility
  • Made internalNetwork optional in StartedSeleniumRecordingContainer - only cleaned up if we created it
  • Added test to verify user-provided network is respected

Test plan

  • Existing tests pass (backwards compatibility)
  • New test verifies Selenium container can reach other containers on a user-provided network

Previously, SeleniumRecordingContainer always created a new internal
network, ignoring any network provided via withNetwork() or
withNetworkMode(). This broke scenarios where Selenium needed to
communicate with other containers on a shared network.

The fix:
- Only create an internal network if user didn't provide one
- Use the user-provided network for both Selenium and ffmpeg containers
- Only stop the network on cleanup if we created it internally

Fixes testcontainers#844
@netlify
Copy link

netlify bot commented Dec 25, 2025

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 4680d35
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/694e51ccd01ccb0008eacfa1
😎 Deploy Preview https://deploy-preview-1207--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Dec 25, 2025
const { exitCode } = await container.exec(["getent", "hosts", "webserver"]);
expect(exitCode).toBe(0);

await container.stop();
Copy link
Collaborator

@cristianrgreco cristianrgreco Dec 25, 2025

Choose a reason for hiding this comment

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

Nit: can use await using container and drop this stop

@cristianrgreco cristianrgreco changed the title fix(selenium): respect user-provided network when recording is enabled Selenium support user-provided network Dec 25, 2025
Replace manual container.stop() with await using declaration for
consistent resource management pattern across the test file.
@cristianrgreco cristianrgreco merged commit a558850 into testcontainers:main Dec 26, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selenium container not using provided network

2 participants