简体   繁体   English

使用phantomjs运行功能性qUnit测试

[英]Running functional qUnit tests with phantomjs

I'm trying to test a bunch of pages for functionality (eg simulating clicks, checking classes append etc.) and figured that phantomjs would be a good host for my tests. 我正在尝试测试大量页面的功能(例如,模拟点击,检查类追加等),并发现phantomjs将是我的测试的好主机。

Though I can't for the life in me figure out how to combine qunit and phantomjs. 尽管我无法终生,但仍想出如何组合qunit和phantomjs。 (I'm also trying to run it through Grunt's qunit module) (我也在尝试通过Grunt的qunit模块运行它)

I thought I could do something like this and kind of mix phantom and qunit syntax... 我以为我可以做这样的事情以及混合幻象和qunit语法...

var page = require('webpage').create();
page.viewportSize = { width: 1280, height: 1024 };
page.onConsoleMessage = function (msg) {
    console.log(msg);
};

page.open('home.html', function () {
    module("tests");
    test('test', 1, function(){
        $('#button').on('click', function(){
            ok(true, 'button was clicked!');
        });
        $('#button').trigger('click');
    });
});

But obviously that's really wrong. 但这显然是错误的。

Is it a case of injecting my page contents into the qunit-fixture div in my test.html file? 是否将我的页面内容注入到test.html文件中的qunit-fixture div中? Or am I going about it completely the wrong way? 还是我完全以错误的方式去做?

The grunt-contrib-qunit module actually installs phantomjs as a dependency. grunt-contrib-qunit模块实际上将phantomjs安装为依赖项。 When you set up the grunt task to run your qunit tests, it will spawn a phantomjs instance. 当您设置grunt任务以运行您的qunit测试时,它将生成一个phantomjs实例。 So for example, I set up my grunt tasks like so: 因此,例如,我设置了如下任务:

...
qunit: {
  nav: [ "tests/nav.html", "tests/footer.html" ],
  search: [ "tests/search-tests.html" ]
}

And then run my tests like so: 然后像这样运行我的测试:

grunt qunit:search

Or to run all tests: 或运行所有测试:

grunt qunit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM