2012-10-16 31 views
4

我有一个不依赖于jquery的web应用程序。与casperJs测试一起使用jquery

我正在做功能测试感谢(伟大的:))casperjs。

现在我想在我的测试中使用jquery。所以我试图注入它,如http://casperjs.org/faq.html#faq-jquery所示。那么,它不工作。

这是我的代码,如果你能帮助我 - 有什么问题吗? :

casper.start('http://localhost:8080/xxxxxx/xxxxxDialogTests.html'); 

casper.echo("page = " + casper.page); // -> it works, the page is there 
casper.page.injectJs("../tools/jquery-1.7.2.js"); 

casper.waitFor(function check() 
{ 
    return this.visible('#button_create'); 
}, 
function then() 
{ 
    this.click('#button_create'); 
    casper.waitFor(function check() 
    { 
     return this.visible('#dialog_document_name'); 
    }, 
    function then() 
    { 
      console.log("element : ", this.evaluate(function() 
      { 
       var el = $("input#dialog_document_name"); 

       return el; 
      })); 
    }); 
}); 

我删除了测试,因为它是不是问题的关键...

的感谢!

+0

路径../绝对正确吗?你是否收到任何错误信息? – DaveHogan

+0

是的,我可以看到指定文件夹中的文件,根本没有错误。只是控制台日志正在返回'element:null' – unludo

回答

3

尝试在测试脚本的顶部添加casper.options.clientScripts = ["../tools/jquery-1.7.2.js"]

也尝试设置绝对传递给jQuery脚本,例如。 /Users/foo/Work/project/tools/jquery-1.7.2.js

相关问题