簡體   English   中英

使用phantomjs運行功能性qUnit測試

[英]Running functional qUnit tests with phantomjs

我正在嘗試測試大量頁面的功能(例如,模擬點擊,檢查類追加等),並發現phantomjs將是我的測試的好主機。

盡管我無法終生,但仍想出如何組合qunit和phantomjs。 (我也在嘗試通過Grunt的qunit模塊運行它)

我以為我可以做這樣的事情以及混合幻象和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');
    });
});

但這顯然是錯誤的。

是否將我的頁面內容注入到test.html文件中的qunit-fixture div中? 還是我完全以錯誤的方式去做?

grunt-contrib-qunit模塊實際上將phantomjs安裝為依賴項。 當您設置grunt任務以運行您的qunit測試時,它將生成一個phantomjs實例。 因此,例如,我設置了如下任務:

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

然后像這樣運行我的測試:

grunt qunit:search

或運行所有測試:

grunt qunit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM