Skip to content

Commit

Permalink
Extracted tab testing into its own spec and updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Dec 26, 2022
1 parent a48f86e commit 11da805
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ developers := List(
Developer(id="darkfrog", name="Matt Hicks", email="[email protected]", url=url("https://matthicks.com"))
)

val seleniumVersion = "4.6.0"
val seleniumVersion = "4.7.2"

libraryDependencies ++= Seq(
"com.outr" %% "scribe-slf4j" % "3.10.5",
Expand Down
52 changes: 52 additions & 0 deletions src/test/scala/spec/MultiTabBrowserSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package spec

import com.outr.robobrowser.{By, ReadyState, WindowHandle}
import com.outr.robobrowser.browser.chrome.Chrome
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import spice.net._

import scala.concurrent.duration._

class MultiTabBrowserSpec extends AnyWordSpec with Matchers {
"Multi-tab Browser" should {
lazy val browser = Chrome.headless.create()

var googleTab: Option[WindowHandle] = None
var duckDuckGoTab: Option[WindowHandle] = None

"initialize and load the first tab" in {
browser.load(url"https://google.com")
browser.url should be(url"https://www.google.com")
browser.title should be("Google")
browser.readyState should be(ReadyState.Complete)
}
"create a new tab" in {
googleTab = Some(browser.window.handle) // Get a reference to the current tab
duckDuckGoTab = Some(browser.window.newTab())
googleTab shouldNot be(duckDuckGoTab)
}
"load duckduckgo.com" in {
browser.load(url"https://duckduckgo.com")
browser.url should be(url"https://duckduckgo.com")
browser.title should be("DuckDuckGo — Privacy, simplified.")
browser.readyState should be(ReadyState.Complete)
}
"do a Duck Duck Go search" in {
val input = browser.oneBy(By.css("#search_form_input_homepage"))
input.tagName should be("input")
input.sendKeys("robobrowser")
input.submit()
browser.waitFor(5.seconds)(browser.title == "robobrowser at DuckDuckGo")
browser.title should be("robobrowser at DuckDuckGo")
}
"switch back to Google tab" in {
browser.window.handles.size should be(2)
browser.window.switchTo(googleTab.getOrElse(fail()))
browser.title should be("Google")
}
"dispose the browser" in {
browser.dispose()
}
}
}
27 changes: 0 additions & 27 deletions src/test/scala/spec/RoboBrowserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class RoboBrowserSpec extends AnyWordSpec with Matchers {
}
lazy val eventManager = new EventManager(browser, Some(server))

var googleTab: Option[WindowHandle] = None
var duckDuckGoTab: Option[WindowHandle] = None

"load Google" in {
browser.load(url"https://google.com")
browser.url should be(url"https://www.google.com")
Expand All @@ -45,30 +42,6 @@ class RoboBrowserSpec extends AnyWordSpec with Matchers {
browser.screenshot(screenshot)
screenshot.length() should be > 0L
}
"create a new tab" in {
googleTab = Some(browser.window.handle) // Get a reference to the current tab
duckDuckGoTab = Some(browser.window.newTab())
googleTab shouldNot be(duckDuckGoTab)
}
"load duckduckgo.com" in {
browser.load(url"https://duckduckgo.com")
browser.url should be(url"https://duckduckgo.com")
browser.title should be("DuckDuckGo — Privacy, simplified.")
browser.readyState should be(ReadyState.Complete)
}
"do a Duck Duck Go search" in {
val input = browser.oneBy(By.css("#search_form_input_homepage"))
input.tagName should be("input")
input.sendKeys("robobrowser")
input.submit()
browser.waitFor(5.seconds)(browser.title == "robobrowser at DuckDuckGo")
browser.title should be("robobrowser at DuckDuckGo")
}
"switch back to Google tab" in {
browser.window.handles.size should be(2)
browser.window.switchTo(googleTab.getOrElse(fail()))
browser.title should be("robobrowser - Google Search")
}
// "verify logs are working" in {
// browser.logs.info("This is a test")
// browser.logs().map(_.copy(timestamp = 0L)) should be(List(LogEntry(LogLevel.Info, 0L, "This is a test")))
Expand Down

0 comments on commit 11da805

Please sign in to comment.