当前位置: 首页>>代码示例>>Scala>>正文


Scala WebBrowser类代码示例

本文整理汇总了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")
  }
} 
开发者ID:hmrc,项目名称:soft-drinks-industry-levy-frontend,代码行数:62,代码来源:NavigationSugar.scala

示例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
  }
} 
开发者ID:ovotech,项目名称:comms-audit-log,代码行数:31,代码来源:BrowserTesting.scala

示例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
} 
开发者ID:shogowada,项目名称:scalajs-reactjs,代码行数:26,代码来源:BaseTest.scala

示例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!") )
  }
} 
开发者ID:whunmr,项目名称:ScalaTestDemo,代码行数:22,代码来源:WebTestDemoFunSuiteStyle.scala


注:本文中的org.scalatest.selenium.WebBrowser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。