/integration-tests/src/main/scala/gp/GuineaPigRunner.scala

https://github.com/fomkin/korolev · Scala · 110 lines · 71 code · 10 blank · 29 comment · 4 complexity · 9677c8a0c5bf8649688be130b53c4237 MD5 · raw file

  1. package gp
  2. import akka.http.scaladsl.Http
  3. import korolev.akka._
  4. import scala.concurrent.ExecutionContext.Implicits.global
  5. import korolev.state.javaSerialization._
  6. import org.openqa.selenium.remote.DesiredCapabilities
  7. import tools._
  8. import scala.concurrent.duration._
  9. import scala.concurrent.{Await, Future}
  10. object GuineaPigRunner extends App {
  11. val genericCaps = Seq(
  12. Caps(() => DesiredCapabilities.chrome)(
  13. "platform" -> "Windows 7",
  14. "version" -> "55.0",
  15. "chromedriverVersion" -> "2.27"
  16. ),
  17. Caps(() => DesiredCapabilities.edge)(
  18. "platform" -> "Windows 10",
  19. "version" -> "14.14393"
  20. ),
  21. Caps(() => DesiredCapabilities.internetExplorer)(
  22. "platform" -> "Windows 7",
  23. "version" -> "10.0"
  24. ),
  25. Caps(() => DesiredCapabilities.internetExplorer)(
  26. "platform" -> "Windows 7",
  27. "version" -> "11"
  28. ),
  29. Caps(() => DesiredCapabilities.firefox)(
  30. "platform" -> "Linux",
  31. "version" -> "45.0",
  32. "seleniumVersion" -> "2.53.0"
  33. ),//,
  34. // Caps(() => DesiredCapabilities.android)(
  35. // "deviceName" -> "Android Emulator" ,
  36. // "deviceOrientation" -> "portrait" ,
  37. // "browserName" -> "Browser" ,
  38. // "platformVersion" -> "5.1" ,
  39. // "platformName" -> "Android"
  40. // ),
  41. Caps(() => DesiredCapabilities.safari)(
  42. "platform" -> "OS X 10.11",
  43. "version" -> "10.0"
  44. )//,
  45. // Caps(() => DesiredCapabilities.iphone)(
  46. // "appiumVersion" -> "1.5.3",
  47. // "deviceName" -> "iPhone 6 Simulator",
  48. // "deviceOrientation" -> "portrait",
  49. // "platformVersion" -> "9.3",
  50. // "platformName" -> "iOS",
  51. // "browserName" -> "Safari",
  52. // "autoAcceptAlerts" -> "true"
  53. // )
  54. )
  55. val servers = List(
  56. // (scenario: () => Boolean) => {
  57. // println("Starting Blaze server")
  58. // val service = blazeService[Future, GuineaPigService.State, Any].from(GuineaPigService.service)
  59. // val config = BlazeServerConfig(port = 8000, doNotBlockCurrentThread = true)
  60. // val server = korolev.blazeServer.runServer(service, config)
  61. // Future {
  62. // val result = scenario()
  63. // server.close()
  64. // println("Blaze server shutting down")
  65. // result
  66. // }
  67. // },
  68. (scenario: () => Boolean) => {
  69. println("Starting Akka-http server")
  70. val route = akkaHttpService(GuineaPigService.service).apply(AkkaHttpServerConfig())
  71. Http().bindAndHandle(route, "localhost", 8000).map { server =>
  72. //Thread.sleep(1000000000000L)
  73. val result = scenario()
  74. println("Akka-http server shutting down")
  75. server.unbind()
  76. result
  77. }
  78. }
  79. )
  80. val appUrl = "http://localhost:8000"
  81. val runScenario = () => {
  82. val resultFutures = GuineaPigScenarios
  83. .all
  84. .map(_.run(genericCaps:_*))
  85. val resultFuture = Future
  86. .sequence(resultFutures)
  87. .map(_.reduce(_ && _))
  88. Await.result(resultFuture, 1.hour)
  89. }
  90. def runSerial(acc: Boolean, futures: List[(() => Boolean) => Future[Boolean]]): Future[Boolean] = futures match {
  91. case Nil => Future.successful(acc)
  92. case x :: xs => x(runScenario).flatMap { result =>
  93. runSerial(acc && result, xs)
  94. }
  95. }
  96. runSerial(acc = true, servers) foreach { result =>
  97. if (result) System.exit(0)
  98. else System.exit(1)
  99. }
  100. }