spectron icon indicating copy to clipboard operation
spectron copied to clipboard

Spectron opens multiple instances of the electron app along with the terminals on windows.

Open Ankitr19 opened this issue 5 years ago • 9 comments

I am using spectron to test an electron app, the spectron version is ^9.0.0 and the electron version is ^7.1.0, when I run the test using mocha, it opens up multiple app instances.

Ankitr19 avatar Nov 25 '19 09:11 Ankitr19

I get the same issue with spectron 9.0.0 and when I used spectron 5.0.0 it worked but app.electron, app.webContents, etc.. undefined.

sonnguyen-logigear avatar Dec 10 '19 04:12 sonnguyen-logigear

This issue is resolved ? Even I am also facing same issue with spectron 8.0.0

Kishore1984 avatar Jan 03 '20 17:01 Kishore1984

The same issue. I have tried with previous versions of electron ^4.0.0 and spectron ^6.0.0

VentsislavKostadinov avatar Jan 08 '20 12:01 VentsislavKostadinov

I was getting this when I used electron-mocha to trigger spectron, I tried mocha and it works fine now.

Ankitr19 avatar Jan 14 '20 02:01 Ankitr19

It's a hacky way, but I don't know why electron-mocha doesn't work.

Ankitr19 avatar Jan 14 '20 02:01 Ankitr19

Hi, i'm using electron 7.1.9 with spectron 9.0.0 and have some undefinied and weird issues about app.electron, etc, with a multiple app instance opening.

By testing some stuff, i realize that all is working great when i comment in the main.js file the devtool :

/* win.webContents.openDevTools({ mode: 'detach' }); */

Momotoculteur avatar Jan 23 '20 14:01 Momotoculteur

It seems like chromeDriver version not match, my Electron version is 7.1.8, spectron version is 9.0.0, but lib/application client.init() reject by session not created: This version of ChromeDriver only supports Chrome version 76, actually 7.1.8 Electron match 78.

image

dengyaolong avatar Feb 06 '20 05:02 dengyaolong

Hi, I am using electron version 12 and an appropriate spectron version but still when I am triggering my tests it's launching multiple instances of the application.

Has anyone found a solution or a work around for this issue?

harshendrathakur avatar Jun 08 '21 11:06 harshendrathakur

Okay, I was having the same issue. And solved by setting remote debugging port.

chromeDriverArgs: ['remote-debugging-port=9222']:

const Application = require('spectron').Application const assert = require('assert') const electronPath = require('electron') // Require Electron from the binaries included in node_modules. const path = require('path')

describe('Application launch', function () { this.timeout(10000)

beforeEach(function () {
    this.app = new Application({
        // Your electron path can be any binary
        // i.e for OSX an example path could be '/Applications/MyApp.app/Contents/MacOS/MyApp'
        // But for the sake of the example we fetch it from our node_modules.
        path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron' + (process.platform === 'win32' ? '.cmd' : '')),

        // Assuming you have the following directory structure

        //  |__ my project
        //     |__ ...
        //     |__ main.js
        //     |__ package.json
        //     |__ index.html
        //     |__ ...
        //     |__ test
        //        |__ spec.js  <- You are here! ~ Well you should be.

        // The following line tells spectron to look and use the main.js file
        // and the package.json located 1 level above.
        args: [path.join(__dirname, '..')],
        env: {
            ELECTRON_ENABLE_LOGGING: true,
            ELECTRON_ENABLE_STACK_DUMPING: true,
            NODE_ENV: 'test'
        },
        waitTimeout: 10e3,
        requireName: 'electronRequire',
        chromeDriverLogPath: '../chromedriverlog.txt',
        chromeDriverArgs: ['remote-debugging-port=9222']
    })
    return this.app.start()
})

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

it('shows an initial window', function () {
    return this.app.client.getWindowCount().then(function (count) {
        assert.equal(count, 1)
        // Please note that getWindowCount() will return 2 if `dev tools` are opened.
        // assert.equal(count, 2)
    })
})

})

majedur-rahaman avatar Jul 29 '21 09:07 majedur-rahaman