使用scala-js-env-selenium进行交叉浏览器测试

时间:2016-05-24 22:20:15

标签: scala.js

我正在使用https://github.com/scala-js/scala-js-env-selenium进行浏览器内测试,到目前为止,测试在本地浏览器中运行良好。现在我想在远程浏览器(https://app.crossbrowsertesting.com

中运行我的测试

我创建了新的CrossBrowser

import org.openqa.selenium.remote.{DesiredCapabilities, RemoteWebDriver}
import org.scalajs.jsenv.selenium.{BrowserDriver, SeleniumBrowser}
import java.net.URL

object CrossBrowser {
  def apply(): CrossBrowser = new CrossBrowser

  val username = "email"
  // Your username
  val authkey = "xxxxxxxxxx" // Your authkey

}

class CrossBrowser private() extends SeleniumBrowser {
  def name: String = "RemoteBrowser"

  def newDriver: BrowserDriver = new CrossDriver

  private class CrossDriver extends BrowserDriver {
    protected def newDriver(): RemoteWebDriver = {
      val caps = new DesiredCapabilities()

      caps.setCapability("name", "Selenium Test Example")
      caps.setCapability("build", "1.0")
      caps.setCapability("browser_api_name", "IE10")
      caps.setCapability("os_api_name", "Win7x64-C2")
      caps.setCapability("screen_resolution", "1024x768")
      caps.setCapability("record_video", "true")
      caps.setCapability("record_network", "true")

      new RemoteWebDriver(new URL("http://" + CrossBrowser.username + ":" + CrossBrowser.authkey + "@hub.crossbrowsertesting.com:80/wd/hub"), caps)
    }
  }

}

并更新了构建设置

 jsEnv  := new org.scalajs.jsenv.selenium.SeleniumJSEnv(CrossBrowser()),
 jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(CrossBrowser())

当我运行测试命令时,我得到了以下输出

[trace] Stack trace suppressed: run last client/test:loadedTestFrameworks for the full output. [error] (client/test:loadedTestFrameworks) org.openqa.selenium.WebDriverException: [fc92901a-f56a-4e4b-9d75-953402cbfe35] Test has timed out after 199 seconds [error] Command duration or timeout: 199.20 seconds [error] Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' [error] System info: host: 'Chandras-MacBook-Pro.local', ip: 'xx.xx.xxx.x', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.3', java.version: '1.8.0_25' [error] Driver info: org.openqa.selenium.remote.RemoteWebDriver [error] Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=10, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, webdriver.remote.sessionid=fc92901a-f56a-4e4b-9d75-953402cbfe35, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:33793/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}] [error] Session ID: fc92901a-f56a-4e4b-9d75-953402cbfe35

超时的原因是,测试运行试图在不存在的远程机器上加载file:/var/folders/n0/c0fyqlqx0gg15mv4t5mchgj80000gn/T/1464125278337-0/scalajsRun.html

是否可以进行这种测试..?(将文件复制到某个服务器并加载该URL ...)

1 个答案:

答案 0 :(得分:1)

如果您正在运行本地测试,Selenium将需要访问您的文件。这通常是通过代理完成的。虽然似乎支持本地测试(https://crossbrowsertesting.com/local-testing),但您可以尝试联系他们进行设置。