Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/c03246839a404f8cba8578dd61433bb3 to your computer and use it in GitHub Desktop.
Save dacr/c03246839a404f8cba8578dd61433bb3 to your computer and use it in GitHub Desktop.
Playing with scalatest selenium integration to test remote sites. / published by https://github.com/dacr/code-examples-manager #b28bd758-e932-45ab-90b0-baeea5b28d50/dbd0826cf0095e5786693f4892855eadec0a3ab7
// summary : Playing with scalatest selenium integration to test remote sites.
// keywords : scala, scalatest, selenium
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : b28bd758-e932-45ab-90b0-baeea5b28d50
// created-on : 2020-05-31T19:54:52Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
import $ivy.`org.scalatest::scalatest:3.2.6`
import $ivy.`org.scalatestplus::selenium-3-141:3.2.5.0`
// Mandatory because by default selenium tools are very verbose...
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.SEVERE)
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(java.util.logging.Level.SEVERE)
import org.scalatest._, matchers._
import org.scalatestplus.selenium._
import org.openqa.selenium.WebDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
class ThatSpec extends flatspec.AnyFlatSpec with should.Matchers with WebBrowser {
override def suiteName="ThatSpec"
implicit val driver: WebDriver = new HtmlUnitDriver()
"selenium" should "check httpbin.org home page" in {
val home = "https://httpbin.org"
go to (home)
pageTitle shouldBe "httpbin.org"
pageSource should include ("the developer - Website")
}
it should "navigate on httpbin.org" in {
val home = "https://httpbin.org"
go to (home)
pageTitle should be ("httpbin.org")
click on linkText("the developer - Website")
pageTitle should be ("httpbin.org")
pageSource should include ("uncomment to enable the green top header")
}
it should "navigate on wikipedia" in {
val wikihome= "https://en.wikipedia.org/wiki/Selenium_(software)"
go to (wikihome)
pageTitle should be ("Selenium (software) - Wikipedia")
click on linkText("Software testing")
pageTitle should be ("Software testing - Wikipedia")
pageSource should include ("stakeholders")
}
}
org.scalatest.tools.Runner.main(Array("-oDF", "-s", classOf[ThatSpec].getName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment