javascript - Headless JS 站点测试,每个页面都进行测试

标签 javascript coffeescript phantomjs casperjs headless

我正在尝试使用 CoffeeScript/Javascript 为我网站上的每个页面编写 headless (headless)集成测试,并在一个命令中运行它们。我尝试过使用 casperjs 但我不断遇到 issues当尝试在请求循环中运行多个测试套件时。

理想情况下我想做这样的事情:

for page in ['/products','/about', '/contact']
   open(page, ->
       require("tests/#{page}/test.coffee").execute()

测试文件如下所示:

exports.execute ->
    test.assert(pageTitleIs('about us'))

这样我就可以将每个页面的测试保存在单独的文件中,但可以用一个命令不经意地运行它们。

最佳答案

casper.thenOpen( url, ->
  @CurrentUrl = url
  @currentRoute = route
  @test.currentSuite = @test.running = @test.started = false # Hack. If we don't do this and a test fails, no tests after it will be executed
  @test.info("Testing #{urlPath}");
  path = currentDirectory+'/root'+route;
  if(fs.isDirectory(path))
    for file in fs.list(path)
      if(file.indexOf('.spec')!=-1)
        @echo 'executing file: ' + path + '/'+ file
        @test.exec(path + '/'+ file);
  @test.exec currentDirectory+"/smoke.test.js"
  @waitFor ->
    if test_done #Hack. If we don't do this, new tests will start before old ones finished.
      return true
    test_done = false
)

这是我想出的解决方案,其中每个页面都会执行smoke.test.js。这非常糟糕,我遇到了许多与测试范围相关的问题,但它确实有效。

关于javascript - Headless JS 站点测试,每个页面都进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21491845/

相关文章:

javascript - 无法读取 CoffeeScript 全局变量

macos - 在 mac 10.7.2 上安装 coffeescript 时出错

coffeescript - 对象的解构赋值 - 有没有办法匹配对象的其余部分?类似于解构数组时的 splat

javascript - 来自指令模板 AngularJS 的事件

javascript - 将参数添加到url javascript

javascript - 是否有任何 javascript 函数,甚至在 jQuery 库中与 PHP print_r() 功能相同?

javascript - 通过 exec 将变量传递给 PhantomJS

javascript - PhantomJS 中 evaulate 内部的属性未定义

node.js - 如何生成新进程并从 node.js 脚本退出?

javascript - 向 d3 水平条形图添加标签?