diff --git a/build.sbt b/build.sbt index b74d595..d81c077 100644 --- a/build.sbt +++ b/build.sbt @@ -25,7 +25,7 @@ developers := List( Developer(id="darkfrog", name="Matt Hicks", email="matt@matthicks.com", url=url("https://matthicks.com")) ) -val seleniumVersion = "4.6.0" +val seleniumVersion = "4.7.2" libraryDependencies ++= Seq( "com.outr" %% "scribe-slf4j" % "3.10.5", diff --git a/src/test/scala/spec/MultiTabBrowserSpec.scala b/src/test/scala/spec/MultiTabBrowserSpec.scala new file mode 100644 index 0000000..6688f07 --- /dev/null +++ b/src/test/scala/spec/MultiTabBrowserSpec.scala @@ -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() + } + } +} diff --git a/src/test/scala/spec/RoboBrowserSpec.scala b/src/test/scala/spec/RoboBrowserSpec.scala index 38d134b..75820e2 100644 --- a/src/test/scala/spec/RoboBrowserSpec.scala +++ b/src/test/scala/spec/RoboBrowserSpec.scala @@ -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") @@ -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")))