使用Firefox的Selenium 3:active与已知命令不匹配

时间:2016-09-19 09:56:36

标签: firefox selenium-webdriver scalatest geckodriver

我正在尝试使用最新的 geckodriver.exe(v0.10.0)以及以下依赖项编写涉及最新 Firefox(48.0.2)的测试。

<dependencies>
    <dependency>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest_2.11</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <!-- version 3 is needed for current Firefox -->
        <version>3.0.0-beta3</version>
    </dependency>
</dependencies>

我的测试就像这样开始

class LoginSpec extends FeatureSpec with GivenWhenThen with Firefox 
{
    val website = "http://localhost:8080/"

    feature("Landing page")
    {    
        scenario("Wrong password")
        {
          Given("someone on the website")
          go to website

          When("he tries to login with a wrong password")
          login("mbee", "bad password")

          Then("he will stay on the login page")
          usernameField.isDisplayed
          passwordField.isDisplayed
        }
    }

    def login(username: String, password: String)
    {
      click on usernameField
      enter(username)
      click on passwordField
      enter(password)
      submit()
    }

    def usernameField = textField("j_username")

    def passwordField = pwdField("j_password")        
}

首先我尝试使用Chrome ,这很好。但使用Firefox 我已经收到enter(username)的错误:

org.openqa.selenium.UnsupportedCommandException: POST /session/2769cbe9-f066-4a63-ad49-990eec1c6740/element/active did not match a known command (WARNING: The server did not provide any stacktrace information)
...
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.activeElement(RemoteWebDriver.java:968)
    at org.scalatest.selenium.WebBrowser$ActiveElementTarget.switch(WebBrowser.scala:1502)
    at org.scalatest.selenium.WebBrowser$ActiveElementTarget.switch(WebBrowser.scala:1494)
    at org.scalatest.selenium.WebBrowser$switch$.to(WebBrowser.scala:3948)
    at org.scalatest.selenium.WebBrowser$class.enter(WebBrowser.scala:4463)
    at com.iomedico.iostudyoffice.LoginSpec.enter(LoginSpec.scala:18)
    at com.iomedico.iostudyoffice.LoginSpec.login(LoginSpec.scala:100)
...

作为解决方法如果我将enter(username)替换为usernameField.value = username等,则submit()会出现下一个错误:

WebDriver encountered problem to submit(): POST /session/c423793f-09a0-4a8e-afc0-7a2d6d1f3d6a/element/active did not match a known command (WARNING: The server did not provide any stacktrace information)
...
    at org.scalatest.selenium.WebBrowser$class.submit(WebBrowser.scala:3870)
    at com.iomedico.iostudyoffice.LoginSpec.submit(LoginSpec.scala:18)
    at com.iomedico.iostudyoffice.LoginSpec.login(LoginSpec.scala:105)
...

在这两个错误中,此活动与已知命令不匹配。

如何让它运行?

跟进:bug?

关注the code of AbstractHttpCommandCodec.java,我认为这可能是org.seleniumhq.selenium中的错误: selenium-java

defineCommand(GET_ACTIVE_ELEMENT, post("/session/:sessionId/element/active"));

“帖子”似乎错了,不是吗?

1 个答案:

答案 0 :(得分:1)

在Selenium 3.0 beta 4中,bug现在为fixed