【问题标题】:scalatest selenium example compile errorscalatest selenium 示例编译错误
【发布时间】:2014-09-01 16:23:51
【问题描述】:

我是 scala 的新手,但非常想将 ScalaTest 与 Selenium 一起使用。我直接从http://www.scalatest.org/user_guide/using_selenium 复制并粘贴了示例。但在下面的语句中出现错误

"The blog app home page" should "have the correct title" in {
    go to (host + "index.html")
    pageTitle should be ("Awesome Blog")
}

错误出现在“{”之前的“in”关键字上,它表示:

此行有多个标记 - 发现隐式转换:“博客应用主页”应该“具有正确的标题”=> convertToInAndIgnoreMethods("博客应用主页"应该"有正确的标题") - 使用替代方法重载方法值:(testFun: BlogSpec.this.FixtureParam => Any)Unit (testFun: () => Any)Unit 不能应用于 (Unit) - 使用替代方法重载方法值:(testFun: BlogSpec.this.FixtureParam => Any)Unit (testFun: () => Any)Unit 不能应用于 (Unit) - 发现隐式转换:“博客应用主页”=> convertToStringShouldWrapper("The 博客应用主页”)

我相信我通过 maven 选择了所有正确的版本:

<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-library</artifactId>
  <version>2.10.2</version>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.specs2</groupId>
  <artifactId>specs2_2.10</artifactId>
  <version>1.13</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_2.10</artifactId>
  <version>2.0.M6-SNAP8</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.37.0</version>
</dependency>
  ...
  <plugin>
    <!-- see http://davidb.github.com/scala-maven-plugin -->
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.1.3</version>
    <executions>
      <execution>
        <goals>
          <goal>compile</goal>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <args>
            <arg>-make:transitive</arg>
            <arg>-dependencyfile</arg>
            <arg>${project.build.directory}/.scala_dependencies</arg>
          </args>
        </configuration>
      </execution>
    </executions>
  </plugin>

尝试了很多来解决这个问题,但失败了。任何帮助将非常感激。也尝试过https://bitbucket.org/olimination/hello-scalajava.git,但由于 maven 错误而无法运行。

【问题讨论】:

    标签: selenium scalatest


    【解决方案1】:

    这个问题似乎是一个很老的问题,也许你已经设法解决了,但是这个示例是为我编译的。

    我认为问题出在import 语句中,例如 IntelliJ Idea 似乎提出了错误的语句,使用import org.scalatest._ 时似乎一切正常,否则我会得到你的编译错误。

    这是完整的来源:

    import org.openqa.selenium.WebDriver
    import org.openqa.selenium.htmlunit.HtmlUnitDriver
    import org.scalatest.selenium.WebBrowser
    
    import org.scalatest._
    
    class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser {
    
        implicit val webDriver : WebDriver = new HtmlUnitDriver
    
        val host = "http://localhost:9000/"
    
        "The blog app home page" should "have the correct title" in {
            go to (host + "index.html")
            pageTitle should be("Awesome Blog")
        }
    }
    

    我建议使用最新版本的框架和插件(如果可以的话,也可以使用 Scala,我还是保留 2.10),这是我的pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>test</groupId>
        <artifactId>scalatest-selenium</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <dependencies>
            <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
                <version>2.10.2</version>
            </dependency>
            <dependency>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest_2.10</artifactId>
                <version>2.2.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.42.2</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <!-- disable surefire -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.7</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
                <!-- enable scalatest -->
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <!-- see http://davidb.github.com/scala-maven-plugin -->
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.1.7-SNAPSHOT</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>testCompile</goal>
                            </goals>
                            <configuration>
                                <args>
                                    <arg>-make:transitive</arg>
                                    <arg>-dependencyfile</arg>
                                    <arg>${project.build.directory}/.scala_dependencies</arg>
                                </args>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多