Last active
April 2, 2023 10:13
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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