【问题标题】:Using jquery with casperJs test使用 jquery 和 casperJs 测试
【发布时间】:2012-10-16 18:09:03
【问题描述】:

我有一个不依赖 jquery 的 Web 应用程序。

感谢(伟大的 :))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;
           }));  
   });
});

我删除了测试,因为它不是重点......

谢谢!

【问题讨论】:

  • 路径../绝对正确吗?您是否收到任何错误消息?
  • 是的,我可以看到指定文件夹中的文件,并且完全没有错误。只是控制台日志返回 'element : null'

标签: javascript unit-testing phantomjs casperjs


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多