本文整理汇总了Scala中org.scalatest.selenium.WebBrowser类的典型用法代码示例。如果您正苦于以下问题:Scala WebBrowser类的具体用法?Scala WebBrowser怎么用?Scala WebBrowser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebBrowser类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: goOn
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.softdrinksindustrylevyfrontend.util
import java.awt.Robot
import org.openqa.selenium.support.ui.{ExpectedCondition, ExpectedConditions, WebDriverWait}
import org.openqa.selenium.{By, WebDriver, WebElement}
import org.scalatest.concurrent.{Eventually, IntegrationPatience}
import org.scalatest.selenium.WebBrowser
import org.scalatest.{Assertions, Matchers}
import uk.gov.hmrc.softdrinksindustrylevyfrontend.generic.WebPage
trait NavigationSugar extends WebBrowser with Eventually with Assertions with Matchers with IntegrationPatience {
val robot = new Robot()
def goOn(page: WebPage)(implicit webDriver: WebDriver) = {
goTo(page)
on(page)
}
def on(page: WebPage)(implicit webDriver: WebDriver) = {
val wait = new WebDriverWait(webDriver, 5)
wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")))
assert(page.isCurrentPage, s"Page was not loaded: ${page.currentUrl}")
}
def notOn(page: WebPage)(implicit webDriver: WebDriver) = {
eventually {
webDriver.findElement(By.tagName("body"))
}
assertResult(false, s"\nDid not expect ${page.currentUrl} to be loaded") {
page.isCurrentPage
}
}
def loadPage()(implicit webDriver: WebDriver) = {
val wait = new WebDriverWait(webDriver, 15)
wait.until(
new ExpectedCondition[WebElement] {
override def apply(d: WebDriver) = d.findElement(By.tagName("body"))
}
)
}
def anotherTabIsOpened()(implicit webDriver: WebDriver) = {
webDriver.getWindowHandles.size() should be(2)
}
def browserGoBack()(implicit webDriver: WebDriver) = {
webDriver.navigate().back()
}
def switchToTabWith(marker: => Boolean)(implicit webDriver: WebDriver): Any = {
windowHandles.foreach { newTab: String =>
switch to window(newTab)
if (marker) return
}
fail(s"Marker evaluation resolves false for current page")
}
}
示例2: withFixture
//设置package包名称以及导入依赖的类
package servicetest.helpers
import java.io.File
import com.machinepublishers.jbrowserdriver.{JBrowserDriver, Settings, Timezone}
import org.apache.commons.io.FileUtils
import org.openqa.selenium.OutputType.BYTES
import org.openqa.selenium.{TakesScreenshot, WebDriver}
import org.scalatest.selenium.WebBrowser
import org.scalatest.{Outcome, TestSuite}
trait BrowserTesting extends TestSuite with WebBrowser {
implicit val webDriver: WebDriver = new JBrowserDriver(Settings.builder().timezone(Timezone.UTC).build())
private val testScreenshotsDir = sys.env.getOrElse("CIRCLE_ARTIFACTS", "target/screenshots")
override protected def withFixture(test: NoArgTest): Outcome = {
val outcome = test()
if (outcome.isExceptional) {
webDriver match {
case driver: TakesScreenshot =>
val bytes = driver.getScreenshotAs(BYTES)
FileUtils.writeByteArrayToFile(new File(s"$testScreenshotsDir/${test.name}.png"), bytes)
}
}
outcome
}
}
示例3: BaseTest
//设置package包名称以及导入依赖的类
package io.github.shogowada.scalajs.reactjs.example
import org.openqa.selenium.UnexpectedAlertBehaviour
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.remote.{CapabilityType, DesiredCapabilities}
import org.scalatest.concurrent.Eventually
import org.scalatest.selenium.{Driver, WebBrowser}
import org.scalatest.{Matchers, path}
object BaseTest {
val webDriver = {
val capabilities = new DesiredCapabilities()
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE)
new ChromeDriver(capabilities)
}
Runtime.getRuntime.addShutdownHook(new Thread(() => webDriver.quit()))
}
trait BaseTest extends path.FreeSpec
with WebBrowser with Driver
with Matchers
with Eventually {
override implicit val webDriver = BaseTest.webDriver
}
示例4: WebTestDemoFunSuiteStyle
//设置package包名称以及导入依赖的类
package org.whunmr.scalatestdemo
import org.openqa.selenium._
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.selenium.WebBrowser
import org.scalatest.{FunSuite, Matchers}
class WebTestDemoFunSuiteStyle extends FunSuite with Matchers with WebBrowser {
implicit val webDriver: WebDriver = new HtmlUnitDriver
val host = "http://www.baidu.com"
test("Google browser works!") {
go to (host)
click on "kw"
textField("kw").value = "Cheese!"
submit()
assert (pageTitle contains ("Cheese!") )
}
}