spectron
spectron copied to clipboard
Empty terminals display on Windows
Running 'getting started' script from http://electron.atom.io/spectron/
This is the result:
First window is the application as I wanted it to be (but tests don't pass), other windows look like terminals without anything inside. Anyone seen something similar?
I'm using Windows 10 via VM from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/mac/
Are you able to share the app you are testing with?
Yes. I want to integrate it into my boilerplate. Here is work in progress: https://github.com/szwacz/electron-boilerplate/tree/e2e Those two commands will do the job:
npm install
npm run e2e
I was able to replicate the empty terminals, not sure why this occurring, ChromeDriver spawns those windows so I'm not sure if it could be a regression there.
I tried looking in their issue tracker and also tried a few tweaks to how ChromeDriver is spawned but no luck.
You should still be able to get your tests passing though. On my Windows 10 VM, if I set the timeout to 10 seconds then they consistently pass without any other changes.
this.timeout(10000);

I have the same problem.. Spawning new windows makes it hard to write test for browserWindow.isFocused
I have the same issue, I am also on Windows 10 and as @fantasticsid mentioned one of the empty terminal windows has focus, so you need to add a
.browserWindow.focus()
at the beginning of your tests.
On installing spectron repo and running the tests it is only those that test for focus that are failing out of the box.
Same here. Spectron test for number of windows:
app.client.waitUntilWindowLoaded().getWindowCount().should.eventually.equal(1);
fails with
AssertionError: expected 3 to equal 1
on just one window opened.
I have the same problem with my Window 10 64 bit machine. I am using Spectron 3.6.2 and Electron 1.6.7. Since the change log does not mention any changes regarding this issue I assume that a newer version will not fix this?
I have the same issue. Any update?
Is anyone working on getting this fixed ? Right now the only workaround i found is :
setTimeout(() => { return this.app.client.getWindowCount().then(function (count) { assert.equal(count, 1); }); }, 1);
Happening to me as well. Opening my app spawns 8 (!) empty terminal windows. They have the same title than the "good" one, so it's not easy to identify and switch to it.
I'm having the same issue. I'm running on Windows 10 and I am literally just using the first example off the Spectron readme. I published my code up to github here:
https://github.com/evanlarsen/IssueWithSpectronSpawningMultipleTerminals
Having the same issue, has anyone found a workaround for this?
Having same problem/issue, did anyone has solution to suppress the empty windows ?
I am also having the 2 terminal windows appearing issue. browserWindow.focus didn't work for me, I had to do a browserWindow.setAlwaysOnTop(true). It's very annoying. Does anyone have any idea what's going on ? is it a ChromeDriver issue?
@chrisgeorge0911 How exactly was browserWindow.focus
not working for? Presently, it isn't for me either (I get a browserWindow is undefined TypeError), but when I try browserWindow.setAlwaysOnTop(true)
I get the same error again.
I have the same issue and for me the promise returned by app.start()
also never resolves.
Same here... is someone working on it?
Same here... is someone working on it?
I'm able to reproduce this with these bare minimal steps:
npm init -y
npm i electron@3 spectron@5
node -e "new (require('spectron').Application)({ path: require('electron') }).start()"
This launches the main Electron app (with default screen), and also 2 of the empty console windows!
Here's a screenshot:
I'm able to workaround this issue by manually focusing the window:
await app.client.waitUntilWindowLoaded();
await app.client.waitUntil(async () => {
await app.browserWindow.focus();
return await app.browserWindow.isFocused();
});
This has to be run every time a window is opened, since each new window brings up 2 new consoles.
When we set electronPath
to be require('electron')
this occurs.
Any workarounds for this? Is it usual behaviour on mac as well?
https://stackoverflow.com/questions/51972307/spectron-opens-empty-terminals-during-test-run
I had tested the same electron application using selenium with the help of chrome capabilities that point to the electron exe instead of chrome binary. https://stackoverflow.com/a/51186740/8903949
I don't see these empty terminals there.
For example: it('set text1_validation', function () { return this.app.client.click('#main').then(() => { this.app.browserWindow.setAlwaysOnTop(true) return this.app.client.getWindowCount() }).then((count) => { return this.app.client.windowByIndex(1) }).then(() => { this.app.browserWindow.setAlwaysOnTop(true) this.app.client.element('#text1_validation').setValue('SPECTRON AUTOMATED TESTING') }).then(() => { return this.app.client.click('#text1_validation').getValue('#text1_validation') }).then((text) => { console.log('response: ' + JSON.stringify(text)) assert.equal(text, 'SPECTRON AUTOMATED TESTING') }).then(() => { this.app.client.click('#send') }) })
@AdamMauger I looked on your function I think a combination of focus() with alwaysOnTop(true). Solved.
at least for me.
I'm using Mocha with chai as promised. If you need more code I can add more here. My devDependencies are using electron 1.8.2 for now:
"devDependencies": {
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"electron-packager": "9.1.0",
"eslint": "^5.16.0",
"mocha": "^6.0.2",
"prettier": "^1.16.4",
"spectron": "^3.8.0"
},
beforeEach(function() {
app = new Application({
path: electronPath,
env: {
ELECTRON_ENV: 'test'
},
startTimeout: 10000,
waitTimeout: 10000,
args: [path.join(__dirname, '..')]
});
chaiAsPromised.transferPromiseness = app.transferPromiseness;
return app.start().then( async () => {
await app.browserWindow.focus();
await app.browserWindow.setAlwaysOnTop(true);
});
});
Just back-referencing why it's opening empty windows.
- This commit: https://github.com/electron/spectron/commit/d74b5a0ddf500747bce30629a8be239db82edcd1 changed the launcher on windows to a
.bat
. - A
.bat
will always launch a command window.
I tried installing v3.7.1 - the latest release before the change of launcher to .bat
as mentioned just above by @SleeplessByte. I then opened a new powershell window and tried running npm test
. While it still shows two command windows for me, the problem with app.start()
's promise never returning mentioned by @kraenhansen is fixed. (I'm using Jasmine rather than Mocha, don't know if that has any effect)
npm uninstall spectron
npm install --save-dev [email protected]
Update: It seems I can only run this with Electron 2.0.18 and Spectron 3.7.1, every other combination I've tried results in a hopelessly broken thing
Our project ran into this issue when running ava tests using spectron and since we have it set up to run multiple electron apps in parallel this would flood the machine with like 4-8 popup Electron console windows while running the tests. I managed to make a change that fixed it in our case. I noticed that it was happening because of the --enable-logging parameter being passed in. So I made a modified version of launcher.js which purposely didn't include --enable-logging and it worked fine for us:
if (arg !== '--enable-logging') {
chromeArgs.push(arg)
}
I couldn't find where the spectron launcher was managing to pick up the --enable-logging flag from as I thought a better solution would have been just not providing it to launcher.js in the first place but I couldn't find out so I just went with the solution that worked for now. My assumption was that the --enable-logging flag was being picked up somewhere inside of webdriverio when the client is initialized and thus calls launcher.bat but I couldn't find out where.
@senyszrm - This worked! Thank you so much.
I had to splice it off after it concat(chromeArgs)
, I believe the flag was coming from within there:
// launcher.js
. . .
var args = appArgs.concat(chromeArgs)
// add this line
args.splice(args.indexOf('--enable-logging'), 1)
Spectron version: 10.0.1
Same problem for me.
Any update?
I'm using spectron@6 and electron@4
any updates?
electron@7 and spectron@9