diff --git a/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerSuite.scala b/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerSuite.scala index be0c9a01..e3cd59c2 100644 --- a/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerSuite.scala +++ b/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerSuite.scala @@ -19,6 +19,7 @@ package org.scalatestplus.play import org.scalatest._ import play.api.Application import play.api.test._ +import play.core.server.ServerConfig /** * Trait that provides a new `Application` and running `TestServer` instance per ScalaTest `Suite`. @@ -143,7 +144,11 @@ trait BaseOneServerPerSuite extends TestSuiteMixin with ServerProvider { this: T implicit lazy val app: Application = fakeApplication() protected implicit lazy val runningServer: RunningServer = - DefaultTestServerFactory.start(app) + new DefaultTestServerFactory() { + // Restoring the previous behaviour before https://github.com/playframework/playframework/pull/11173 was merged + // Also see https://github.com/playframework/playframework/issues/5473 + protected override def serverConfig(app: Application): ServerConfig = super.serverConfig(app).copy(port = Some(0)) + }.start(app) /** * Invokes `start` on a new `TestServer` created with the `Application` provided by `app` and the diff --git a/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerTest.scala b/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerTest.scala index 8e7432de..97e9a257 100644 --- a/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerTest.scala +++ b/module/src/main/scala/org/scalatestplus/play/BaseOneServerPerTest.scala @@ -19,6 +19,7 @@ package org.scalatestplus.play import play.api.Application import play.api.test._ import org.scalatest._ +import play.core.server.ServerConfig /** * Trait that provides a new `Application` and running `TestServer` instance for each test executed in a ScalaTest `Suite`. @@ -107,7 +108,11 @@ trait BaseOneServerPerTest extends TestSuiteMixin with ServerProvider { this: Te def newAppForTest(testData: TestData): Application = fakeApplication() protected def newServerForTest(app: Application, testData: TestData): RunningServer = - DefaultTestServerFactory.start(app) + new DefaultTestServerFactory() { + // Restoring the previous behaviour before https://github.com/playframework/playframework/pull/11173 was merged + // Also see https://github.com/playframework/playframework/issues/5473 + protected override def serverConfig(app: Application): ServerConfig = super.serverConfig(app).copy(port = Some(0)) + }.start(app) /** * Creates new `Application` and running `TestServer` instances before executing each test, and