我正在尝试使用 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/