spectron icon indicating copy to clipboard operation
spectron copied to clipboard

Empty terminals display on Windows

Open szwacz opened this issue 8 years ago • 37 comments

Running 'getting started' script from http://electron.atom.io/spectron/

This is the result: screen shot 2016-06-05 at 18 17 01 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/

szwacz avatar Jun 05 '16 17:06 szwacz

Are you able to share the app you are testing with?

kevinsawicki avatar Jun 06 '16 16:06 kevinsawicki

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

szwacz avatar Jun 06 '16 18:06 szwacz

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);
screen shot 2016-06-06 at 1 58 38 pm

kevinsawicki avatar Jun 06 '16 21:06 kevinsawicki

I have the same problem.. Spawning new windows makes it hard to write test for browserWindow.isFocused

zhenchaoli avatar Jun 07 '16 01:06 zhenchaoli

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.

areel avatar Jun 12 '16 16:06 areel

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.

ambrt avatar Jan 07 '17 20:01 ambrt

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?

sla89 avatar Jun 14 '17 05:06 sla89

I have the same issue. Any update?

AbrahamAlcaina avatar Sep 01 '17 10:09 AbrahamAlcaina

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);

poppein avatar Sep 11 '17 07:09 poppein

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.

mduqueoviedo avatar Oct 10 '17 08:10 mduqueoviedo

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

evanlarsen avatar Dec 14 '17 18:12 evanlarsen

Having the same issue, has anyone found a workaround for this?

AGiantSquid avatar Feb 21 '18 19:02 AGiantSquid

Having same problem/issue, did anyone has solution to suppress the empty windows ?

pyprasad avatar Apr 25 '18 10:04 pyprasad

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 avatar May 16 '18 07:05 chrisgeorge0911

@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.

matt-buckley avatar Jul 31 '18 09:07 matt-buckley

I have the same issue and for me the promise returned by app.start() also never resolves.

kraenhansen avatar Aug 07 '18 13:08 kraenhansen

Same here... is someone working on it?

peni4142 avatar Sep 18 '18 09:09 peni4142

Same here... is someone working on it?

zhaozhongyu avatar Nov 05 '18 07:11 zhaozhongyu

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: image

scottrippey avatar Jan 09 '19 18:01 scottrippey

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.

scottrippey avatar Jan 18 '19 20:01 scottrippey

When we set electronPath to be require('electron') this occurs.

Any workarounds for this? Is it usual behaviour on mac as well?

reach2jeyan avatar Jan 22 '19 07:01 reach2jeyan

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.

Bharath-Kumar-S avatar Jan 28 '19 10:01 Bharath-Kumar-S

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 avatar Apr 06 '19 23:04 AdamMauger

@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);
    });
  });

pcardosolei avatar Apr 10 '19 15:04 pcardosolei

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.

SleeplessByte avatar Apr 11 '19 11:04 SleeplessByte

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

binaryfunt avatar Oct 19 '19 22:10 binaryfunt

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 avatar Mar 16 '20 18:03 senyszrm

@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

wburgess-invision avatar Mar 17 '20 15:03 wburgess-invision

Same problem for me.
Any update? I'm using spectron@6 and electron@4

alisherafat01 avatar Apr 08 '20 08:04 alisherafat01

any updates?

electron@7 and spectron@9

feifeipan avatar Aug 31 '20 07:08 feifeipan