Not able to run the test

170 views
Skip to first unread message

James L.

unread,
Oct 14, 2012, 8:44:01 AM10/14/12
to scalate...@googlegroups.com
It's interesting to test Scala code and my next step will be creating a simple suite for testing web browser with ScalaTest and Selenium, I was not able to run the test below?


import org.scalatest.FlatSpec
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.htmlunit.HtmlUnitDriver

class GoogleSearch extends FlatSpec {

    val driver = new HtmlUnitDriver
    driver.get("http://www.google.com")

    "Google" should "have the proper title" in {
      assert(driver.getTitle() === "Google")
    }
  }



Using Selenium standalone Jar

C:\Users\james\Desktop>scala -classpath scalatestm4.jar;selenium.jar GoogleSearch
Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: GoogleSearch
        at scala.sys.package$.error(package.scala:27)
        at scala.tools.nsc.GenericRunnerCommand.scala$tools$nsc$GenericRunnerCommand$$guessHowToRun(GenericRunnerCommand.scala:38)
        at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
        at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
        at scala.Option.getOrElse(Option.scala:108)
        at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:48)
        at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:17)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:33)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

Bill Venners

unread,
Oct 14, 2012, 8:59:20 AM10/14/12
to scalate...@googlegroups.com
Hi James,

I don't see anything wrong with your test class, so perhaps the
problem is in how you are attempting to run it. How are you trying to
run it?

Also, you may be interested in trying ScalaTest's Selenium DSL instead
of using Selenium directly:

http://www.scalatest.org/user_guide/using_selenium

Bill
> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest



--
Bill Venners
Artima, Inc.
http://www.artima.com

James L.

unread,
Oct 14, 2012, 9:33:49 AM10/14/12
to scalate...@googlegroups.com
I see, I have difficulty doing the test from your tutorial too?
Am I doing the import correctly?

import org.scalatest._
import org.openqa.selenium._
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.htmlunit.HtmlUnitDriver

class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser {

  implicit val webDriver: WebDriver = new HtmlUnitDriver

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


When compiled, it throws:

C:\Users\yanli\Desktop>scalac -classpath scalatestm4.jar;selenium.jar s.scala
s.scala:7: error: not found: type WebBrowser
class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser {
                                                         ^
s.scala:12: error: not found: value go
    go to (host + "index.html")
    ^
two errors found

Bill Venners

unread,
Oct 14, 2012, 9:39:32 AM10/14/12
to scalate...@googlegroups.com
Hi James,

You'll need to import WebBrowser from the org.scalatest.selenium
package, like this:

import org.scalatest.selenium.WebBrowser

Bill

James L.

unread,
Oct 14, 2012, 10:01:10 AM10/14/12
to scalate...@googlegroups.com
Great, was able to run REPL and the output does not display?

C:\Users\yanli\Desktop>scala -classpath selenium.jar;scalatestm4.jar s.scala

C:\Users\yanli\Desktop>scala -classpath selenium.jar;scalatestm4.jar;. s.scala

And this would generate an error, BlogSpec.class has been generated, I have no idea what to troubleshoot from here.

C:\Users\yanli\Desktop>scala -classpath selenium.jar;scalatestm4.jar;. BlogSpec
java.lang.NoSuchMethodException: BlogSpec.main([Ljava.lang.String;)
        at java.lang.Class.getMethod(Unknown Source)
        at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:74)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
        at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
        at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)

James L.

unread,
Oct 14, 2012, 10:13:19 AM10/14/12
to scalate...@googlegroups.com
Oh, I got the idea how to run the tests. Thank it works!

C:\Users\yanli\Desktop>scala -classpath selenium.jar;scalatestm4.jar;. org.scalatest.tools.Runner -p BlogSpec

Bill Venners

unread,
Oct 14, 2012, 11:58:24 AM10/14/12
to scalate...@googlegroups.com
Hi James,

Great. FYI, an even simpler way to run just one suite is:

scala -cp selenium.jar;scalatestm4.jar;. org.scalatest.run BlogSpec

Bill
Reply all
Reply to author
Forward
0 new messages