我使用的是Scala2.10、Specs2 13.1-SNAPSHOT和Play2 Framework2.1提供的FluentLenium Api。
我的IntegrationSpec文件中有这行代码,查找一个子元素(根据FluentLenium规范):
browser.find(".myClass").find("#mySubElement") must haveSize(1)该行导致以下编译错误:
error: type mismatch;
found : org.fluentlenium.core.domain.FluentList[_ <: org.fluentlenium.core.domain.FluentWebElement]
required: org.fluentlenium.core.domain.FluentList[?0(in value $anonfun)] where type ?0(in value $anonfun) <: org.fluentlenium.core.domain.FluentWebElement
Note: org.fluentlenium.core.domain.FluentWebElement >: ?0, but Java-defined class FluentList is invariant in type E.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)它是一种基于泛型的of...incompatibilty Scala/Java吗?或者是一种我不知道的正常行为?
然而,这一行(省略任何匹配器)很好地编译:
browser.find(".myClass").find("#mySubElement")发布于 2013-02-20 09:04:18
haveSize匹配器要求被匹配的元素在作用域中有一个org.specs2.data.Sized类型类。java集合对应的类型类是:
implicit def javaCollectionIsSized[T <: java.util.Collection[_]]: Sized[T] =
new Sized[T] {
def size(t: T) = t.size()
}我怀疑这里的类型推断是问题所在,你可以试着用下面丑陋的代码来驯服它:
browser.find(".myClass").
find("#mySubElement").
asInstanceOf[FluentList[FluentWebElement]] must haveSize(1)或者也许
browser.find(".myClass").
find("#mySubElement").
asInstanceOf[Collection[_]] must haveSize(1)或
import scala.collection.convert.JavaConverters._
browser.find(".myClass").
find("#mySubElement").
asScala must haveSize(1)https://stackoverflow.com/questions/14970301
复制相似问题