Selenium,规格和标量

发布于 2024-10-04 17:43:38 字数 70 浏览 4 评论 0原文

我正在寻找使用 scala 规范进行硒测试的信息或一些项目。 如何从我的 scala 规范代码中调用 selenium 测试?

I'm looking an info or some project for selenium testing with scala specs.
How can I call selenium tests from my scala specs code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李不 2024-10-11 17:43:38

我刚刚写了一些可能有帮助的代码。这还没有为 selenium 使用任何 scala DSL。

class EnrollTest extends FlatSpec with ShouldMatchers{

  var driver = new FirefoxDriver
  driver.manage.timeouts.implicitlyWait(10, TimeUnit.SECONDS)


  val beginnersPage = BeginnersPage.open(driver)

  "Enroll button" should "open enroll page" in {
    try {
      val timeOfFirstCourse = beginnersPage.enrollForTheFirstCourse
      val enrollPage = new EnrollPage(driver)

      enrollPage.shouldBeOpen
      enrollPage.courseDetails should include(timeOfFirstCourse)
    }
    finally{
      driver.quit
    }
  }

}

和页面类:

object BeginnersPage{
  val url = "http://"+System.getProperty("testUrl", "www.2ndlanguage.co.uk")+"/beginners.action"

  def open(driver : WebDriver) : BeginnersPage = {
    driver.get(url)
    new BeginnersPage(driver)
  }

}

class BeginnersPage(driver : WebDriver){
  private var firstEnrollButton: WebElement = driver.findElement(By.xpath("//div[@class='newPriceBoxRight']/a/div"))
  private var firstCourseTime: WebElement = driver.findElement(By.xpath("//div[@class='newPriceBoxLeft']//span[@id='time']"))

  def enrollForTheFirstCourse : String = {
    val time = firstCourseTime.getText
    firstEnrollButton.click
    time
  }
}

class EnrollPage(driver : WebDriver){
  def isOpen = driver.getCurrentUrl startsWith "http://www.2ndlanguage.co.uk/offer.action"
  def courseDetails = driver.findElement(By.id("courseDetailsTextArea")).getText
}

I just wrote some code which might be of help. This isn't using any scala DSL for selenium yet.

class EnrollTest extends FlatSpec with ShouldMatchers{

  var driver = new FirefoxDriver
  driver.manage.timeouts.implicitlyWait(10, TimeUnit.SECONDS)


  val beginnersPage = BeginnersPage.open(driver)

  "Enroll button" should "open enroll page" in {
    try {
      val timeOfFirstCourse = beginnersPage.enrollForTheFirstCourse
      val enrollPage = new EnrollPage(driver)

      enrollPage.shouldBeOpen
      enrollPage.courseDetails should include(timeOfFirstCourse)
    }
    finally{
      driver.quit
    }
  }

}

And the page classes:

object BeginnersPage{
  val url = "http://"+System.getProperty("testUrl", "www.2ndlanguage.co.uk")+"/beginners.action"

  def open(driver : WebDriver) : BeginnersPage = {
    driver.get(url)
    new BeginnersPage(driver)
  }

}

class BeginnersPage(driver : WebDriver){
  private var firstEnrollButton: WebElement = driver.findElement(By.xpath("//div[@class='newPriceBoxRight']/a/div"))
  private var firstCourseTime: WebElement = driver.findElement(By.xpath("//div[@class='newPriceBoxLeft']//span[@id='time']"))

  def enrollForTheFirstCourse : String = {
    val time = firstCourseTime.getText
    firstEnrollButton.click
    time
  }
}

class EnrollPage(driver : WebDriver){
  def isOpen = driver.getCurrentUrl startsWith "http://www.2ndlanguage.co.uk/offer.action"
  def courseDetails = driver.findElement(By.id("courseDetailsTextArea")).getText
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文