Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty terminals display on Windows #60

Open
szwacz opened this issue Jun 5, 2016 · 37 comments · May be fixed by #562
Open

Empty terminals display on Windows #60

szwacz opened this issue Jun 5, 2016 · 37 comments · May be fixed by #562
Labels

Comments

@szwacz
Copy link

szwacz commented Jun 5, 2016

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/

@kevinsawicki
Copy link
Collaborator

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

@szwacz
Copy link
Author

szwacz commented Jun 6, 2016

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

@kevinsawicki kevinsawicki changed the title [windows] spectron opens multiple windows multiple windows display on Windows Jun 6, 2016
@kevinsawicki kevinsawicki changed the title multiple windows display on Windows Empty terminals displays on Windows Jun 6, 2016
@kevinsawicki kevinsawicki changed the title Empty terminals displays on Windows Empty terminals display on Windows Jun 6, 2016
@kevinsawicki
Copy link
Collaborator

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

@zhenchaoli
Copy link

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

@areel
Copy link

areel commented Jun 12, 2016

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.

@ambrt
Copy link

ambrt commented Jan 7, 2017

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.

@sla89
Copy link

sla89 commented Jun 14, 2017

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?

@AbrahamAlcaina
Copy link

I have the same issue. Any update?

@poppein
Copy link

poppein commented Sep 11, 2017

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

@mduqueoviedo
Copy link

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.

@evanlarsen
Copy link

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

@AGiantSquid
Copy link

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

@pyprasad
Copy link

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

@chrisgeorge0911
Copy link

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?

@matt-buckley
Copy link

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

@kraenhansen
Copy link

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

@peni4142
Copy link

Same here... is someone working on it?

1 similar comment
@zhaozhongyu
Copy link

Same here... is someone working on it?

@scottrippey
Copy link
Contributor

scottrippey commented Jan 9, 2019

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
Copy link
Contributor

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.

@reach2jeyan
Copy link

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

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

@Bharath-Kumar-S
Copy link

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.

@AdamMauger
Copy link

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')
})
})

@pcardosolei
Copy link

pcardosolei commented Apr 10, 2019

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

@SleeplessByte
Copy link

Just back-referencing why it's opening empty windows.

@binaryfunt
Copy link

binaryfunt commented Oct 19, 2019

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

@senyszrm
Copy link

senyszrm commented Mar 16, 2020

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.

@wburgess-invision
Copy link

@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

@alisherafat01
Copy link

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

@feifeipan
Copy link

any updates?

electron@7 and spectron@9

@dhanyn10
Copy link

same here
i'm using electron 10.1.2 and spectron 11.1.0

@petef19
Copy link

petef19 commented Dec 6, 2020

same here Electron 8.5.5 and Spectron 10.0.1

@ginnyyadav
Copy link

I had the similar issues on Windows and wanted to let you know a couple solutions I found. I'm using Electron 8.5.3 and Spectron 10.0.1 along with jest 24.9.0.

Everything worked well on MacOS , but when I tried to run my tests with jest, I would have tons of electron process terminals open up (like 6 per test), along with my app, then all my tests would fail.

One thing a co-worker noticed is that with our jest we actually had "@jest-runner/electron" as our default runner. This was opening the electron process and, in trying to run that with spectron, I was essentially creating all these electron processes that weren't necessary. we went ahead and changed this by creating a seperate config file including :

//jest.config.js
const {defaults} = require('jest-config');
module.exports = {
 ...defaults
};

and then in our package.json referenced this config file

"spectron-test": " jest --config test/spectron/jest.config.js"

Introducing this had the tests passing immediately. We still had a couple open electron processes in the background, but i went ahead used the app.browserWindow.focus() in order to make up for that. It works on appveyor now, so I'm thrilled. Hope this helps someone.

@Wensh
Copy link

Wensh commented Feb 4, 2021

@ginnyyadav couldn't reproduce the fix with [email protected], [email protected], [email protected] on Windows

Tried with both jest-runner and @jest-runner/electron, the @jest-runner/electronw wouldn't even start.

Update: Re-testing with your exact same library versions also doesn't work.

@ginnyyadav
Copy link

ginnyyadav commented Feb 6, 2021

@Wensh you'll definitely want to use the default jest-runner. Would it help to see my project? We are an open source company so feel free to peruse. https://github.com/tidepool-org/uploader/tree/integrate-spectron/test/spectron this is my branch where I am integrating spectron. I've sent you the direct link to the spectron folder where all the spectron stuff lives.

Edit: Just so you know I am using page objects, so it may look a bit different than the typical spectron setup.

@Wensh
Copy link

Wensh commented Feb 16, 2021

@ginnyyadav Thanks for your help, I checked your project, but it was too dissimilar with mine (TypeScript, Electron-webpack etc).

For now I am using the solution from @wburgess-invision

@AlfredLuan
Copy link

it looks like electron problem, i used electron only and had the same issue, the solution in this link works for me, by removing app.commandLine.appendSwitch("--enable-logging") from main.js in electron
electron/electron#3846 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.