How to connect to an existing Electron app using Spectron

767 Views Asked by At

Is it possible to connect to an existing Electron application using Spectron? I am not particularly sure on how to go about implementing this..

I'd like to be able to do something like:

import { Application } from 'spectron';
import electronPath from 'electron';
import path from 'path';

// but don't spawn new electron application
new Application({
  path: electronPath,
  args: [path.join(__dirname, '..', '..', 'app')],
});

There are some documentation out there for using debuggerAddress option in Spectron, but I'm not really sure on whether that is what I am looking for, since the arguments for debuggerAddress is url, like so: '127.0.0.1:1234'.

2

There are 2 best solutions below

0
On

I struggled making this work for Electron 6, was able to in the end, here is a working repo (made changes on top of an older one)

https://github.com/florin05/electron-spectron-example

0
On

Please make sure that you have created Test Folder in the same directory and create spectron file in this file.

Json File Changes:

"scripts": {"test": "mocha"}
const app = new Application({path: electronPath,args:[path.join(__dirname,'..')],})

beforeEach(function () {return app.start()})

afterEach(function () {if (app && app.isRunning()) {return app.stop()}})