我试图用CoffeeScript/Javascript为我的站点上的每个页面编写无头集成测试,并在一个命令中运行它们。我尝试过使用casperjs,但是当我试图在一个请求循环中运行多个测试套件时,我一直会遇到问题。
理想情况下,我想做这样的事情:
for page in ['/products','/about', '/contact']
open(page, ->
require("tests/#{page}/test.coffee").execute()其中的测试文件看起来类似于:
exports.execute ->
test.assert(pageTitleIs('about us'))这样我就可以将每个页面的测试保存在单独的文件中,但是只需使用一个命令就可以随意运行它们。
发布于 2014-02-05 18:50:33
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。这很麻烦,我遇到了许多与测试范围有关的问题,但是它是有效的。
发布于 2014-02-01 12:54:57
字符串插值不适用于单引号。你得用双引号。见不同之处:
require('tests/#{page}/test.coffee').execute()
# becomes: require('tests/#{page}/test.coffee').execute();
require("tests/#{page}/test.coffee").execute()
# becomes: require("tests/" + page + "/test.coffee").execute();https://stackoverflow.com/questions/21491845
复制相似问题