From 085ab178eb18e3feba73584e244f8313f6c29776 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 27 Jan 2025 09:08:05 +0000 Subject: [PATCH] test: add e2e --- .../modules/session/EventManager.ts | 6 ++-- tests/session/test_subscription.py | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/bidiMapper/modules/session/EventManager.ts b/src/bidiMapper/modules/session/EventManager.ts index b1d1faa3c..b40aef2c6 100644 --- a/src/bidiMapper/modules/session/EventManager.ts +++ b/src/bidiMapper/modules/session/EventManager.ts @@ -247,12 +247,12 @@ export class EventManager extends EventEmitter { if (userContextIds.length) { const userContexts = await this.#userContextStorage.getUserContexts(); const knownUserContextIds = new Set( - userContexts.map(({userContext}) => userContext), + userContexts.map((userContext) => userContext.userContext), ); for (const userContextId of userContextIds) { - if (knownUserContextIds.has(userContextId)) { + if (!knownUserContextIds.has(userContextId)) { throw new NoSuchUserContextException( - `User context ${userContextId} not found.`, + `User context ${userContextId} not found`, ); } } diff --git a/tests/session/test_subscription.py b/tests/session/test_subscription.py index c894169bd..a0a7a4867 100644 --- a/tests/session/test_subscription.py +++ b/tests/session/test_subscription.py @@ -69,6 +69,35 @@ async def test_subscribeWithoutContext_subscribesToEventsInAllContexts( assert resp["params"]["context"] == context_id +@pytest.mark.asyncio +async def test_subscribeUserContext(websocket, context_id, html): + result = await execute_command( + websocket, { + "method": "session.subscribe", + "params": { + "events": ["browsingContext.load"], + "userContexts": ["default"] + } + }) + assert result == {'subscription': ANY_UUID} + + # Navigate to some page. + await send_JSON_command( + websocket, { + "method": "browsingContext.navigate", + "params": { + "url": html("

test

"), + "wait": "complete", + "context": context_id + } + }) + + # Wait for `browsingContext.load` event. + resp = await read_JSON_message(websocket) + assert resp["method"] == "browsingContext.load" + assert resp["params"]["context"] == context_id + + @pytest.mark.asyncio async def test_subscribeWithContext_subscribesToEventsInGivenContext( websocket, context_id, html):