selenium-standalone icon indicating copy to clipboard operation
selenium-standalone copied to clipboard

[🐛 Bug]: Selenium does not "frees" the port

Open joaodanielopes opened this issue 3 years ago • 7 comments

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

7.16.6

Node.js Version

v16.13.0

Mode

WDIO Testrunner

Which capabilities are you using?

No response

What happened?

I am able to run the test on the first time. However, on the next runs, I got the error:

ERROR @wdio/selenium-standalone-service: Error: Port 4444 is already in use.

To "free" the port I need to manually kill the process running in the Windows command prompt: netstat -aof | findstr :4444 taskkill /PID /F

What is your expected behavior?

After the run, selenium stops and "frees" the ports.

How to reproduce the bug.

Run a project with the following settings:

  • java version "17.0.1" 2021-10-19 LTS

  • package.json:

{ "name": "name", "version": "1.0.0", "description": "description", "scripts": { "build": "tsc", "test": "wdio wdio.conf.ts" }, "dependencies": { "@cucumber/cucumber": "^7.3.1", "@types/chai": "^4.2.22", "@types/node": "^16.11.11", "@wdio/cli": "7.16.6", "@wdio/cucumber-framework": "7.16.6", "@wdio/local-runner": "7.16.6", "@wdio/selenium-standalone-service": "7.16.6", "chai": "4.3.4", "multiple-cucumber-html-reporter": "1.18.0", "ts-node": "10.4.0", "tsconfig-paths": "3.12.0", "typescript": "4.5.2", "wdio-cucumberjs-json-reporter": "3.0.0", "webdriverio": "7.16.6" } }

  • wdio.conf.ts:

`{ runner: "local", specs: ["./src/features//*.feature"], exclude: [], maxInstances: 1, capabilities: [ { browserName: "chrome", 'goog:chromeOptions': { args: [ '--disable-infobars', '--start-maximized' ] }, }, ], logLevel: "warn", bail: 0, baseUrl: "https://www.google.com", waitforTimeout: 20000, connectionRetryTimeout: 60000, connectionRetryCount: 3, services: [ [ "selenium-standalone" ], ], framework: "cucumber", reporters: [ [ "cucumberjs-json", { jsonFolder: "reports/cucumberjs/", }, ], ], cucumberOpts: { requireModule: ["tsconfig-paths/register"], require: ["./src/steps//*.ts"], backtrace: true, dryRun: false, failFast: false, format: ["pretty"], colors: true, snippets: false, source: false, profile: [], strict: true, tagExpression: "", timeout: 60000, ignoreUndefinedDefinitions: false, }, autoCompileOpts: { autoCompile: true,

    tsNodeOpts: {
        transpileOnly: false,
        project: "tsconfig.json",
        files: true,
    },
},
...hooks,

}; `

Relevant log output

ERROR @wdio/selenium-standalone-service: Error: Port 4444 is already in use.
    at Object.start (C:\Repos\temp\ui\e2e\node_modules\selenium-standalone\lib\start.js:117:11)

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • [X] I have searched the existing issues

joaodanielopes avatar Dec 06 '21 17:12 joaodanielopes

Thanks for reporting!

I think we can definitely do something here to ensure the port gets open up again.

Any contributions that resolves the bug are highly appreciated. Please take a look into our contribution guidelines and let us know if you have any questions. Cheers!

christian-bromann avatar Mar 08 '22 07:03 christian-bromann

Unfortunately, I faced the same issue :(

Windows 11 Home, version: 21H2 OS build 22000.556 Windows Feature Experience Pack 1000.22000.556.0

Node: v16.14.2 @wdio/cli: ^7.19.3 @wdio/selenium-standalone-service: ^7.19.1

image

alexstep-dev avatar Apr 10 '22 16:04 alexstep-dev

I am also seeing this same issue

Windows 10 Node 14.7.0 @wdio/cli 7.16.15 @wdio/selenium-standalone-service 7.16.14 JDK 1.8

Nicolas-Moore avatar Apr 13 '22 15:04 Nicolas-Moore

Thanks @alexstep-dev and @Nicolas-Moore for verifying that this bug exist. Anyone has some free cycles to work on fixing it?

christian-bromann avatar Apr 13 '22 16:04 christian-bromann

Hi. Have the same issue:

Windows 10 Node 16.14.0 @wdio/cli 7.19.5 @wdio/selenium-standalone-service 7.19.5

Lara2409 avatar Apr 26 '22 12:04 Lara2409

I haven't seen this issue surface on Mac or Linux, just Windows.

But closing and re-opening the Command Line kills the Selenium session for now.

PFaz540 avatar May 25 '22 14:05 PFaz540

I had this similar issue on my windows 11. I uninstall Java JDK 18 that I had originally installed and re-install openJDK 17 winget install Microsoft.OpenJDK.17 and now this is no longer an issue. @joaodanielopes @Lara2409 @PFaz540 do you want to give a try and see if this resolves the issue?

spaudel1 avatar Sep 16 '22 06:09 spaudel1

Hi @christian-bromann , I am still getting the same error. When I am trying to execute the same test again it says -

image

I am using - Window machine 10 JDK - 18 node - 18.0.0 @wdio/cli - 7.26.0 @wdio/selenium-standalone-service - 7.26.0

Could you please confirm for me if this issue is still open or closed?

shubhamkgupta14 avatar Nov 18 '22 06:11 shubhamkgupta14

Could you please confirm for me if this issue is still open or closed?

As you can see this issue is still open.

christian-bromann avatar Nov 18 '22 06:11 christian-bromann

To me it was JAVA path issue. I used following steps to fix this problem: Go to System Properties > Environment Variables

  1. On environmental variables (windows), verify the system variable path for java is correct. e.g C:\Program Files\Microsoft\jdk-17.0.4.101-hotspot\bin
  2. If you have multiple path, moved java home path to the top on env variable list.
  3. Verify the JAVA_HOME path is correct. e.g C:\Program Files\Microsoft\jdk-17.0.4.101-hotspot\ I had to restart the machine once I made this changes.

spaudel1 avatar Jan 27 '23 22:01 spaudel1

In a way to prevent the behavior here is new feature https://github.com/webdriverio/selenium-standalone/pull/838

udarrr avatar Aug 26 '23 11:08 udarrr

it has been resolved in https://github.com/webdriverio/selenium-standalone/pull/838

udarrr avatar Oct 04 '23 10:10 udarrr