1

私は scala を初めて使用しますが、Selenium で ScalaTest を使用したいと思っています。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」キーワードにあります。

この行に複数のマーカー - 暗黙の変換が見つかりました: "The blog app home page" should "have the right title" => convertToInAndIgnoreMethods("The blog app home page" should "have the correct title") - オーバーロードされたメソッド値と代替手段: (testFun: BlogSpec.this.FixtureParam => Any)Unit (testFun: () => Any)Unit を (Unit) に適用することはできません - オーバーロードされたメソッドの値に代替手段があります: (testFun: BlogSpec.this.FixtureParam => Any) )Unit (testFun: () => Any)Unit を (Unit) に適用できません - 暗黙の変換が見つかりました: "The blog app home page" => convertToStringShouldWrapper("The blog app home page")

私は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 エラーのために実行できませんでした。

4

1 に答える 1

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>
于 2014-09-01T08:23:51.027 に答える