• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala WebDriver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.openqa.selenium.WebDriver的典型用法代码示例。如果您正苦于以下问题:Scala WebDriver类的具体用法?Scala WebDriver怎么用?Scala WebDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WebDriver类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: MessagesPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class MessagesPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)

  @FindBy(css = "#logoutLink")
  val logoutLink: WebElement = null

  @FindBy(css = ".alert-info")
  val infoAlert: WebElement = null

  @FindBy(css = ".alert-danger")
  val errorAlert: WebElement = null

  @FindBy(css = "textarea")
  val messageField: WebElement = null

  @FindBy(css = "input[type=submit]")
  val sendButton: WebElement = null

  def logout() {
    logoutLink.click()
    sc.waitForFinishLoading()
  }

  def isUserLogged(user: String): Boolean = {
    sc.waitForElementVisible(By.linkText("Logged in as " + user))
    true
  }

  def isUMessageDisplayed(message: String): Boolean = {
    val escapedMessage = message.replace("\"", "\\\"")
    sc.waitForElementVisible(By.xpath(s"""//span[contains(., "$escapedMessage")]"""))
    true
  }

  def getInfoText: String = {
    sc.waitForElementVisible(By.cssSelector(".alert-info"))
    infoAlert.getText
  }

  def getErrorText: String = {
    sc.waitForElementVisible(By.cssSelector(".alert-danger"))
    errorAlert.getText
  }
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:53,代码来源:MessagesPage.scala


示例2: SeleniumCommands

//设置package包名称以及导入依赖的类
package uitest.commands

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.FluentWait
import org.openqa.selenium.support.ui.Wait

import java.util.concurrent.TimeUnit

class SeleniumCommands(driver: WebDriver) {
  final val URL = "http://localhost:8080/#/"

  var fluentwait: Wait[WebDriver] = new FluentWait[WebDriver](driver)
    .withTimeout(20, TimeUnit.SECONDS)
    .pollingEvery(100, TimeUnit.MILLISECONDS)

  def waitForFinishLoading() {
    waitForElementInvisible(By.cssSelector("#loading-indicator"))
  }

  def waitForElementClickable(locator: By) {
    fluentwait.until(ExpectedConditions.elementToBeClickable(locator))
  }

  def waitForElementVisible(element: WebElement) {
    fluentwait.until(ExpectedConditions.visibilityOf(element))
  }

  def waitForElementVisible(locator: By) {
    fluentwait.until(ExpectedConditions.visibilityOfElementLocated(locator))
  }

  def waitForElementInvisible(locator: By) {
    fluentwait.until(ExpectedConditions.invisibilityOfElementLocated(locator))
  }

  def waitForElementPresent(locator: By) {
    fluentwait.until(ExpectedConditions.presenceOfElementLocated(locator))
  }
} 
开发者ID:OOSINT,项目名称:NorthendLink-Site,代码行数:43,代码来源:SeleniumCommands.scala


示例3: DriverContainer

//设置package包名称以及导入依赖的类
package com.github.cuzfrog.webdriver

import org.openqa.selenium.{WebDriver, WebElement}

private[webdriver] sealed trait Container {
  val driver: Driver
}
private[webdriver] case class DriverContainer(driver: Driver, seleniumDriver: WebDriver) extends Container {
  val elements = scala.collection.mutable.ArrayBuffer.empty[Long]
}
private[webdriver] case class ElementContainer(element: Element, seleniumElement: WebElement) extends Container {
  val driver = element.driver
}
private[webdriver] case class WindowContainer(window: Window, seleniumDriver: WebDriver) extends Container {
  val driver = window.driver
} 
开发者ID:cuzfrog,项目名称:WebDriverServ,代码行数:17,代码来源:Container.scala


示例4: step

//设置package包名称以及导入依赖的类
import org.openqa.selenium.{JavascriptExecutor, WebDriver, WebElement}
import org.slf4j.LoggerFactory

import scala.concurrent.duration._

package object tools {

  val logger = LoggerFactory.getLogger("tools")

  def step(caption: String)(lambda: WebDriver => StepResult) =
    Step(caption, lambda)

  def scenario(name: String)(steps: Step*): Scenario =
    Scenario(name, steps)

  def assert(message: String, f: => Boolean) = {
    if (!f) {
      val exception = new AssertionError(message)
      throw exception
    } else {
      StepResult.Ok
    }
  }

  def fail(message: String): Unit = {
    throw new AssertionError(message)
  }

  def sleep(duration: FiniteDuration): Unit = {
    Thread.sleep(duration.toMillis)
  }

  implicit final class WebElementOps(val el: WebElement) extends AnyVal {
    def scrollTo()(implicit webDriver: WebDriver): Unit = webDriver match {
      case executor: JavascriptExecutor =>
        executor.executeScript("arguments[0].scrollIntoView(true);", el)
        ()
      case _ =>
        throw new UnsupportedOperationException("WebDriver is not javascript executor")
    }
  }
} 
开发者ID:fomkin,项目名称:korolev,代码行数:43,代码来源:package.scala


示例5: LoginPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class LoginPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url = sc.URL + "login"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val loginButton: WebElement = null

  def login(login: String, password: String) {
    loginField.sendKeys(login)
    passwordField.sendKeys(password)
    loginButton.click()
    sc.waitForFinishLoading()
  }

  def openLoginPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:33,代码来源:LoginPage.scala


示例6: RegistrationPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class RegistrationPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url = sc.URL + "register"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "email")
  val emailField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val registerButton: WebElement = null

  @FindBy(id = "regPassDontMatch")
  val registerPassErrorText: WebElement = null

  def register(login: String, email: String, password: String, repeatedPassword: Option[String] = None) {
    openRegistrationPage()
    loginField.sendKeys(login)
    emailField.sendKeys(email)
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword.getOrElse(password))
    registerButton.click()
    sc.waitForFinishLoading()
  }

  def openRegistrationPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }

  def getPassErrorText = registerPassErrorText.getText
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:47,代码来源:RegistrationPage.scala


示例7: PasswordResetPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.{By, WebDriver, WebElement}
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class PasswordResetPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  def url(code: String) = s"${sc.URL}password-reset?code=$code"

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(id = "repeatNotMatching")
  val repeatErrorText: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val resetButton: WebElement = null

  def resetPassword(password: String, repeatedPassword: String) {
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword)
    resetButton.click()
    sc.waitForFinishLoading()
  }

  def openPasswordResetPage(code: String) {
    driver.get(url(code))
    sc.waitForFinishLoading()
  }

  def getErrorText = repeatErrorText.getText
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:37,代码来源:PasswordResetPage.scala


示例8: Driver

//设置package包名称以及导入依赖的类
package rnrb.driver

import java.util.concurrent.TimeUnit

import org.apache.commons.lang3.StringUtils
import org.openqa.selenium.WebDriver
import rnrb.driver.Browser._

import scala.util.Try

object Driver extends Driver

class Driver {
  val systemProperties = System.getProperties

  val webDriver: WebDriver = {
    sys addShutdownHook {
      Try(webDriver.quit())
    }

    val selectedDriver = if (!StringUtils.isEmpty(System.getProperty("browser"))) {
      val targetBrowser = systemProperties.getProperty("browser").toLowerCase
      targetBrowser match {

        case "firefox"                  => createFirefoxDriver()
        case "chrome"                   => createChromeDriver()
        case "phantomjs"                => createPhantomJsDriver()
        case "gecko"                    => createGeckoDriver()
        case _                          => throw new IllegalArgumentException(s"Browser type not recognised")
      }
    }
    else {
      createFirefoxDriver()
    }
    selectedDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS)
    selectedDriver
  }
} 
开发者ID:hmrc,项目名称:inheritance-tax-residence-nil-rate-band-calculator-acceptance-tests,代码行数:39,代码来源:Driver.scala


示例9: MockedApplication

//设置package包名称以及导入依赖的类
import org.openqa.selenium.WebDriver
import play.api.test._
import play.api.{ApplicationLoader, Environment, Mode}

class MockedApplication
    extends WithApplicationLoader(
      new MockedApplicationLoader)

class MockedApplicationWithBrowser[W <: WebDriver]
    extends WithBrowser[W](
      app = new MockedApplicationLoader().load(
        ApplicationLoader.createContext(
          new Environment(
            new java.io.File("."),
            ApplicationLoader.getClass.getClassLoader,
            Mode.Test)))) 
开发者ID:leanovate,项目名称:contoso-conference-manager,代码行数:17,代码来源:MockedApplication.scala


示例10: MbankService

//设置package包名称以及导入依赖的类
package services

import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.{WebDriverWait, ExpectedCondition}
import org.openqa.selenium.{WebElement, By, WebDriver}
import play.api.Play

class MbankService {

  var currentBalance: Double = 0

  def getCurrentBalance: Double = {
    if (currentBalance == 0) {
      implicit val driver: WebDriver = new FirefoxDriver()

      driver.get(getConfig("loginPage"))
      driver.findElement(By.id("userID")).sendKeys(getConfig("userId"))
      driver.findElement(By.id("pass")).sendKeys(getConfig("pass"))
      driver.findElement(By.id("submitButton")).click()

      val accountBalanceElement = new WebDriverWait(driver, 10).until(
        new ExpectedCondition[WebElement] {
          override def apply(d: WebDriver) = d.findElement(By.id("currentAccBalance"))
        })

      currentBalance = accountBalanceElement.getText.replace(',','.').toDouble
    }

    currentBalance
  }

  def getConfig(key: String): String = {
    val configNamespace: String = "app.services.mbank"
    val configKey: String = configNamespace + "." + key

    Play.current.configuration.getString(configKey).orNull
  }
} 
开发者ID:soomalx,项目名称:bigspender,代码行数:39,代码来源:MbankService.scala


示例11: 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


示例12: 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


示例13: LoginPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class LoginPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url                          = sc.URL + "login"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val loginButton: WebElement = null

  def login(login: String, password: String) {
    loginField.sendKeys(login)
    passwordField.sendKeys(password)
    loginButton.click()
    sc.waitForFinishLoading()
  }

  def openLoginPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }
} 
开发者ID:Bii03,项目名称:students-clustering,代码行数:33,代码来源:LoginPage.scala


示例14: RegistrationPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class RegistrationPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url                          = sc.URL + "register"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "email")
  val emailField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val registerButton: WebElement = null

  @FindBy(id = "regPassDontMatch")
  val registerPassErrorText: WebElement = null

  def register(login: String, email: String, password: String, repeatedPassword: Option[String] = None) {
    openRegistrationPage()
    loginField.sendKeys(login)
    emailField.sendKeys(email)
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword.getOrElse(password))
    registerButton.click()
    sc.waitForFinishLoading()
  }

  def openRegistrationPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }

  def getPassErrorText = registerPassErrorText.getText
} 
开发者ID:Bii03,项目名称:students-clustering,代码行数:47,代码来源:RegistrationPage.scala


示例15: PasswordResetPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.{By, WebDriver, WebElement}
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class PasswordResetPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  def url(code: String)            = s"${sc.URL}password-reset?code=$code"

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(id = "repeatNotMatching")
  val repeatErrorText: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val resetButton: WebElement = null

  def resetPassword(password: String, repeatedPassword: String) {
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword)
    resetButton.click()
    sc.waitForFinishLoading()
  }

  def openPasswordResetPage(code: String) {
    driver.get(url(code))
    sc.waitForFinishLoading()
  }

  def getErrorText = repeatErrorText.getText
} 
开发者ID:Bii03,项目名称:students-clustering,代码行数:37,代码来源:PasswordResetPage.scala


示例16: FormElement

//设置package包名称以及导入依赖的类
package com.yukimt.scrape
package element

import org.openqa.selenium.{WebElement, WebDriver, JavascriptExecutor}

class FormElement(protected val element: WebElement, protected val driver: WebDriver)extends LinkElement {

  def setUri(newUri: String): Unit = {
    val code = s"arguments[0].setAttribute('action', '$newUri');"
    driver.asInstanceOf[JavascriptExecutor].executeScript(code, element)
  }

  def submit(): Unit = element.submit
  def addFormData(name: String, value: String) = {
    appendElement("input", Map("name"->name, "value"->value, "type"->"hidden"), None)
  }
} 
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:18,代码来源:FormElement.scala


示例17: ATagElement

//设置package包名称以及导入依赖的类
package com.yukimt.scrape
package element

import org.openqa.selenium.{WebElement, WebDriver, JavascriptExecutor}
import collection.JavaConversions._

class ATagElement(protected val element: WebElement, protected val driver: WebDriver)
  extends LinkElement {

  def openInNewWindow: Window = {
    val url = getFirst(ElementMethod.url)
    val oldWindows = driver.getWindowHandles
    val code = s"window.open('$url');"
    driver.asInstanceOf[JavascriptExecutor].executeScript(code)
    val newId = (driver.getWindowHandles -- oldWindows).head
    Window(newId)
  }

  def setUri(newUri: String): Unit = {
    val code = s"arguments[0].setAttribute('href', '$newUri');"
    driver.asInstanceOf[JavascriptExecutor].executeScript(code, element)
  }
} 
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:24,代码来源:ATagElement.scala


示例18: Parser

//设置package包名称以及导入依赖的类
package com.yukimt.scrape
package element

import org.openqa.selenium.{By, WebDriver}
import collection.JavaConversions._

class Parser(driver: WebDriver) {
  def getFirst(method:ParserMethod): HtmlElement = method(driver).head
  def tryFirst(method:ParserMethod): Option[HtmlElement] = {
    try {
      method(driver).headOption
    } catch {
      case e: Throwable =>
        println(e.getMessage)
        None
    }
  }
  def getAll(method:ParserMethod): Iterable[HtmlElement] = method(driver)
  def >>(method:ParserMethod) = getFirst(method)
  def >?>(method:ParserMethod) = tryFirst(method)
  def >>>(method:ParserMethod) = getAll(method)
}

object ParserMethod{
  def by(b: By): ParserMethod = {
    val method = (_b: By, driver: WebDriver) =>
      driver.findElements(_b).map(e => new HtmlElement(e, driver))
    method(b, _)
  }

  def css(cssQuery: String): ParserMethod = {
    val method = (query: String, driver: WebDriver) =>
      driver.findElements(By.cssSelector(query)).map(e => new HtmlElement(e, driver))
    method(cssQuery, _)
  }
} 
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:37,代码来源:Parser.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ZipInputStream类代码示例发布时间:2022-05-23
下一篇:
Scala min类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap