开发者

Selenium, specs and scala

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


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜