Skip to content

[Task-2247] Named Browser Sessions For Dual-Driver Browser Instances#671

Open
nasif-z wants to merge 10 commits intoreq-81-playwright-selenium-dual-driverfrom
task-2247-browser-sessions
Open

[Task-2247] Named Browser Sessions For Dual-Driver Browser Instances#671
nasif-z wants to merge 10 commits intoreq-81-playwright-selenium-dual-driverfrom
task-2247-browser-sessions

Conversation

@nasif-z
Copy link
Collaborator

@nasif-z nasif-z commented Mar 5, 2026

This PR introduces session-based browser isolation to allow testers to easily spawn fresh browser windows and intuitively interact with them individually. It follows the same session model used in database actions.


Changes

  • Session Isolation: Added browser_sessions shared variable to hold necessary browser driver information whenever opening new browser windows. By default, generates a browser_session named default.
  • Existing Variables: The sessions simply contains the pointers to the driver variables that were already in use.
  • Dynamic Ports: Automatically assigns unique remote debugging ports (9222–9322) for dual-driver CDP connections.
  • Dual Driver Support: Implemented in both Selenium and Playwright. Commonly used actions were modified to check if session is available and switches the active driver accordingly.
  • Targeted Actions & Teardown: Web functions now accept a session parameter to only execute the actions on specific instances without affecting others.

Backwards Compatibility

  • No Breaking Changes: If the session parameter is omitted, the framework defaults to the legacy single-instance behavior.
  • Legacy Parameters: driverid support is maintained for Selenium.

Usage

Add row in action in this format: session | optional parameter | session name (string)

1. Selenium Multi-Session

Pass a unique string to the session parameter to spawn separate windows.

# Session A
Go_To_Link([
    ("session", "optional parameter", "user_1"),
    ("go to link", "selenium action", "https://google.com")
])

# Session B
Go_To_Link([
    ("session", "optional parameter", "user_2"),
    ("go to link", "selenium action", "https://bing.com")
])

2. Apply action on specific session

# Will apply the click action on the browser with session name admin_auth
# even when there are multiple sessions active
Click_Element([
    ("session", "optional parameter", "admin_auth"),
    ("id", "element parameter", "login-btn"),
    ("click", "playwright action", "click")
])

3. Specific Session Cleanup

Tear_Down_Selenium([
    ("session", "optional parameter", "user_1"),
    ("tear down", "selenium action", "tear down")
])

4. Without "session" parameter

Omitting the session parameter in step/action data will preserve the behavior as it was before the addition of this feature.

@nasif-z nasif-z requested a review from sazid March 5, 2026 16:54
@nasif-z nasif-z self-assigned this Mar 5, 2026
@nasif-z nasif-z changed the title [Task-2247] Named Browser Sessions: Isolated Dual-Driver Browser Instances [Task-2247] Named Browser Sessions For Dual-Driver Browser Instances Mar 5, 2026
@sazid
Copy link
Member

sazid commented Mar 6, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e8e79d1b04

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
else:
selenium_driver = selenium_details[driver_id]["driver"]
selenium_driver = get_browser_session(session_name)["selenium_driver"]

Choose a reason for hiding this comment

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

P1 Badge Resolve existing Selenium driver by driver_id, not default session

When Go_To_Link reuses an already-open Selenium driver, this lookup uses session_name, which defaults to "default" when no session/driverid is provided. If the active driver was created under a non-default ID, get_browser_session("default") returns {} and indexing ['selenium_driver'] raises, so previously valid flows that relied on implicit current-driver reuse now fail.

Useful? React with 👍 / 👎.

# Get the correct remote debugging port for current driver
debug_port = 9222 # fallback
if current_driver_id and current_driver_id in selenium_details:
debug_port = selenium_details[current_driver_id].get("remote-debugging-port", 9222)

Choose a reason for hiding this comment

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

P1 Badge Guard against None remote-debugging port for CDP connect

This assignment treats a present-but-None remote-debugging-port as valid, so debug_port can become None and the subsequent CDP URL becomes http://localhost:None. That happens on the normal browser-open path where the stored port is not populated from the generated session port, causing playwright() bridge actions to fail to connect.

Useful? React with 👍 / 👎.

Comment on lines +263 to +264
elif left_l in ("driver id", "page id", "driver tag", "session"):
page_id = right_v

Choose a reason for hiding this comment

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

P2 Badge Keep parsing Playwright driver id from input parameter

The driver id/page id/driver tag value is now only read from optional parameter, so existing steps that pass it as input parameter are ignored and fall back to page_id="default". That silently collapses distinct Playwright instances into the default slot and breaks backward-compatible multi-page routing.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants