2013-10-25 44 views
1

我是scala新手,但非常想在Selenium中使用ScalaTest。我直接从http://www.scalatest.org/user_guide/using_selenium复制并粘贴示例。但得到语句中的错误下面scalatest selenium示例编译错误

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

的错误是在“在”关键字之前“{”,其中说:

多个标记在该行 - 隐式转换发现:“博客应用程序主页”应该“有正确的标题”=> convertToInAndIgnoreMethods(“博客应用程序主页”应该“有正确的标题”) - 重载的方法值与替代方案:(testFun:BlogSpec.this .FixtureParam =>任意)单位 (testFun:()=> Any)单位不适用(单位)(testFun:BlogSpec.this.FixtureParam => Any)单元 (testFun:()=> Any)单元不能应用于(单元) - 发现隐式转换:“博客应用程序主页” => convertToStringShouldWrapper(以下简称‘ 博客应用程序主页’)

我相信我通过行家拿起了所有正确的版本:

<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错误未能得到该运行。

回答

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> 
+0

非常感谢您的回答。非常感激! – RayCh