CasperJS在点击事件和使用CoffeeScript的assertEquals上失败

时间:2012-12-19 18:51:58

标签: unit-testing coffeescript playframework-2.0 casperjs

我有一些CoffeeScript文件,我试图在Play中使用CasperJS进行测试!带有Java的框架。几个不同的测试都失败了,我无法弄清楚原因。第一种测试是处理click事件。我们正在使用:

casper.start(casper.uri("/starting/url"))
casper.then ->
  casper.click "#start-hsa-app-button"

这给了我错误:

CasperError: Cannot dispatch click event on nonexistent selector: #start-hsa-app-button

id #start-hsa-app-button的链接确实存在。

第二个错误是使用assertEquals。上述步骤之后的第二步是:

casper.then ->
  @test.comment "US / non-US address switching"
  @assertNotVisible  "#address3"
  @assertVisible "#city"
  @assertVisible "#state"
  @assertVisible "#zip"
  @test.comment "click #nonUsAddress on"
  @click "#nonUsAddress"
  @assertVisible "#address3"
  @assertNotVisible "#city"
  @assertNotVisible "#state"
  @assertNotVisible "#zip"
  @test.comment "click #nonUsAddress off"
  @click "#nonUsAddress"

对于所有断言返回null

# US / non-US address switching
FAIL #address3 not visible
#    type: assertEquals
#    subject: null
#    expected: false
FAIL #city visible
#    type: assertEquals
#    subject: null
#    expected: true
FAIL #state visible
#    type: assertEquals
#    subject: null
#    expected: true
FAIL #zip visible
#    type: assertEquals
#    subject: null
#    expected: true
# click #nonUsAddress on
FAIL #coverageType_I not checked
#    type: assertEquals
#    subject: null
#    expected: false
FAIL #coverageGroupName not visible
#    type: assertEquals
#    subject: null
#    expected: false
FAIL #coverageGroupNumber not visible
#    type: assertEquals
#    subject: null
#    expected: false

所以对我而言,似乎asserts正在返回null而不是预期值。我的CoffeeScript有任何错误吗?我刚开始使用它,所以我不能说我确定我正在做正确的事情。或者是Play!,CasperJS和CoffeeScript之间的其他互动?

1 个答案:

答案 0 :(得分:1)

事实证明,当我正在研究这个时,另一个开发人员正在研究我试图使用的测试。一旦他完成一切,最终工作。 *脸部棕榈*