本文整理汇总了Scala中org.openqa.selenium.WebDriver类的典型用法代码示例。如果您正苦于以下问题:Scala WebDriver类的具体用法?Scala WebDriver怎么用?Scala WebDriver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
示例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))
}
}
示例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
}
示例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")
}
}
}
示例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()
}
}
示例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
}
示例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
}
示例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))))
示例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
}
}
示例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")
}
}
示例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
}
}
示例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()
}
}
示例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
}
示例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
}