feat(electron): add session-scoped API mocking tools - #146
Conversation
|
|
@nthompson-bitwarden Cannot this feature be bundled into a global browser.mock tooling? Kinda similar to start_session -- based on the context it decides if it inits an appium or webdriver session I could imagine the same for this mocking as well: If its an electron session then it executes against an electron mock, otherwise uses a browser mock I may have missed the mark before with the const metadata = state.currentSession ? state.sessionMetadata.get(state.currentSession) : undefined;
if (metadata?.runtime !== 'electron') {
return { isError: true, content: [{ type: 'text', text: 'Error executing Electron script: no active Electron session.' }] };
}What do you think? Could the mock tooling and the execute_script be merged (I know the execute_script change could be considered breaking, if it does not sit alright with you, I can defer it till v4)?
|
|
Agreed, I like the idea of a shared mocking interface. I can consolidate the mock tools and keep the implementation Electron-only for now, with an unsupported error for other runtimes like you suggested. One thing I’d suggest is an explicit mock kind, since browser.mock() targets network requests while Electron mocks target API functions. That would also leave room for both kinds within an Electron session. For execute_script: an Electron session still needs access to both the renderer and the main process, so session metadata alone won't tell us which context the caller wants. Maybe could add something like context: 'electron-main', preserve the current behavior by default, and keep execute_electron_script as an alias until v4? Happy to tackle the shared mock interface in this PR and leave script consolidation for a follow-up if that works for you? |
@nthompson-bitwarden Awesome! I really like the explocit "mockType" argument in the mock methods I would suggest that webdriver runtimes would default to browser, appium session throws an error, and electron should be the one that can effectively use both So for execute_script there should be a similar distinction? I would not expand the whole pallette of tooling for a localized use-case But sure, execute_electorn_script cab remain as its already in the code I just plan on introducing wdi5 (SAP) runtime as well, so I have to think of the branching now 😁 Please tackle the mock consolidation, and I will resolve the rest |
|
@Winify thanks for the context! I've pushed that update with your suggestions and PR is ready for review |
Proposed changes
Adds shared, session-scoped mocking tools:
mock,get_mock_calls, andmanage_mock, with optionalmockType: 'electron' | 'browser'.browser, including sessions whose metadata omits runtime.mockType: 'electron'and rejects missing or unsupported selectors.Types of changes
Validation
Checklist
Reviewers: @webdriverio/project-committers