org.openqa.selenium.By Scala Examples
The following examples show how to use org.openqa.selenium.By.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: TodoListTest.scala From scala-json-rpc with MIT License | 5 votes |
package io.github.shogowada.scala.jsonrpc.example.e2e.websocket.integrationtest import io.github.shogowada.scala.jsonrpc.example.e2e.websocket.ElementIds import org.openqa.selenium.support.ui.{ExpectedCondition, ExpectedConditions, WebDriverWait} import org.openqa.selenium.{By, WebDriver} import org.scalatest.concurrent.Eventually import org.scalatest.selenium.{Chrome, Firefox} import org.scalatest.{Matchers, path} class TodoListTest extends path.FreeSpec with Chrome with Eventually with Matchers { def waitFor[T](condition: ExpectedCondition[T])(implicit webDriver: WebDriver): T = { new WebDriverWait(webDriver, 3).until[T](condition) } "given I am on TODO list" - { go to Target.url waitFor(ExpectedConditions.textToBe(By.id(ElementIds.Ready), "Ready!")) clearTodos() "when I add TODO item" - { val newTodoDescription = "Say hello" waitFor(ExpectedConditions.visibilityOfElementLocated(By.id(ElementIds.NewTodoDescription))) textField(id(ElementIds.NewTodoDescription)).value = newTodoDescription clickOn(id(ElementIds.AddTodo)) "then it should add the item" in { verifyTodoExists(newTodoDescription) } "and I reload the page" - { reloadPage() "then it should still show the item" in { verifyTodoExists(newTodoDescription) } } "and removed the item" - { find(cssSelector("li>button")).foreach(element => clickOn(element)) "then it should remove the item" in { eventually { findAll(tagName("li")) shouldBe empty } } } } } def clearTodos(): Unit = { findAll(cssSelector("li>button")).foreach(element => clickOn(element)) } def verifyTodoExists(description: String): Unit = { eventually { findAll(tagName("li")).exists(element => element.text.contains(description)) should equal(true) } } quit() }
Example 2
Source File: BulmaMarkdownComponentsTest.scala From hepek with Apache License 2.0 | 5 votes |
package ba.sake.hepek.bulma.component import ba.sake.hepek.selenium.HepekSeleniumTest import fixtures.static._ import org.openqa.selenium.By class BulmaMarkdownComponentsTest extends HepekSeleniumTest { "BulmaMarkdownComponents" should "render markdown properly" in { go to filePath(Bulma) val mdDiv = find(ids.md).get for (i <- 1 to 6) { val header = mdDiv.underlying.findElement(By.tagName(s"h$i")) header.getAttribute("class") should include(s"is-$i") header.getAttribute("class") should include("title") } } }
Example 3
Source File: Page.scala From renku with Apache License 2.0 | 5 votes |
package ch.renku.acceptancetests.pages import ch.renku.acceptancetests.pages.Page._ import ch.renku.acceptancetests.pages.RenkuPage.RenkuBaseUrl import ch.renku.acceptancetests.tooling._ import eu.timepit.refined.W import eu.timepit.refined.api.Refined import eu.timepit.refined.collection.NonEmpty import eu.timepit.refined.string._ import org.openqa.selenium.{By, WebDriver, WebElement} import org.scalatest.concurrent.Eventually import org.scalatest.time.{Seconds, Span} import org.scalatest.{Matchers => ScalatestMatchers} import org.scalatestplus.selenium.WebBrowser import scala.concurrent.duration._ import scala.language.{implicitConversions, postfixOps} abstract class Page[Url <: BaseUrl] extends ScalatestMatchers with Eventually with AcceptanceSpecPatience { val path: Path val title: Title def pageReadyElement(implicit webDriver: WebDriver): Option[WebElement] def url(implicit baseUrl: Url): String = s"$baseUrl$path" protected implicit def toWebElement(element: WebBrowser.Element): WebElement = element.underlying protected implicit def toMaybeWebElement(maybeElement: Option[WebBrowser.Element]): Option[WebElement] = maybeElement.map(_.underlying) protected implicit class ElementOps(element: WebBrowser.Element) { def parent: WebElement = element.findElement(By.xpath("./..")) def enterValue(value: String): Unit = value foreach { char => element.sendKeys(char.toString) sleep (100 millis) } } protected implicit class WebElementOps(element: WebElement) { def enterValue(value: String): Unit = value foreach { char => element.sendKeys(char.toString) sleep (100 millis) } } object sleep { def apply(duration: Duration): Unit = Page.SleepThread(duration) } protected implicit class OperationOps(unit: Unit) { def sleep(duration: Duration): Unit = Page.SleepThread(duration) } protected def waitUpTo(duration: Duration): PatienceConfig = PatienceConfig( // Wait up to 2 minutes for this operation timeout = scaled(Span(AcceptanceSpecPatience.WAIT_SCALE * duration.toSeconds, Seconds)), interval = scaled(Span(2, Seconds)) ) } object Page { type Path = String Refined StartsWith[W.`"/"`.T] type Title = String Refined NonEmpty // Use a unique name to avoid problems on case-insensitive and preserving file systems object SleepThread { def apply(duration: Duration): Unit = Thread sleep duration.toMillis } } abstract class RenkuPage extends Page[RenkuBaseUrl] object RenkuPage { case class RenkuBaseUrl(value: String Refined Url) extends BaseUrl(value) }
Example 4
Source File: HomepageSpec.scala From ScalaWebTest with Apache License 2.0 | 5 votes |
package org.scalawebtest.integration.doc._005 import org.openqa.selenium.By import org.scalawebtest.core.IntegrationFlatSpec class HomepageSpec extends IntegrationFlatSpec { config.useBaseUri("http://localhost:9090/scalawebtest") path = "/index.html" loginConfig.swallowJavaScriptErrors() config.enableJavaScript(throwOnError = true) "Our homepage" should "contain a succinct claim" in { webDriver .findElement(By.tagName("h2")) .getText shouldEqual "Reduce the effort needed to write integration tests" } }
Example 5
Source File: HomepageSpec.scala From ScalaWebTest with Apache License 2.0 | 5 votes |
package org.scalawebtest.integration.doc._001 import org.openqa.selenium.By import org.scalawebtest.core.IntegrationFlatSpec class HomepageSpec extends IntegrationFlatSpec { config.useBaseUri("http://localhost:9090/scalawebtest") path = "/index.html" "Our homepage" should "contain a succinct claim" in { webDriver .findElement(By.tagName("h2")) .getText shouldEqual "Reduce the effort needed to write integration tests" } } object ScastieScalaTestRunner extends App { org.scalatest.run(new HomepageSpec()) }