Search code examples
mocha.jselectronwebdriver-ioavaspectron

Access multiple renderers with spectron


I'm working on an Electron application. The main process opens a first renderer (browserWindow). When the user click on a button, this renderer sends an IPC message to the main process. When this message is received, the main process opens a second, different, renderer. Those two renderers live concurently. The application works fine.

Then, using Spectron to test this app, how to access both renderers ? The problem is app.rendererProcess always returns the first renderer.

This is the same problem with app.client which always contains the WebdriverIO browser object of the first renderer and never the second.

Is there a way to list all the process of a Spectron application in a test? Is it possible to access the browser object of the second renderer ?

With AVA:

test.(async t => {
    // the application is open before the test
    // at this point, the first renderer is open

    // click on the button to open the second renderer
    await t.context.app.client.click('#bt_openSecondRenderer');

    // wait for the second renderer to open

    // error: this element doesn't exist
    await t.context.app.client.click('elt_of_the_scnd_renderer');
});

I'm using AVA but I don't think it is the problem. So if anyone know how to make this works with Mocha or anything else, it would be very helpfull.

Thanks !


Solution

  • Following the philosophy given by Tim answer, instead of using BrowserWindow, we can use WebDriverIO to focus the desired window:

    test.(async t => {
        // here, t.context.app.client handles the first window
        await t.context.app.client.windowByIndex(1).then(() => {
            // here, t.context.app.client handles the second window
        });
    });