2014-06-23 16 views
5

Sto tentando di creare un test automatico con Nightwatch.js per verificare che i collegamenti per il download del software funzionino correttamente. Non voglio scaricare i file, poiché sono piuttosto grandi, voglio solo verificare che il link corrispondente restituisca una risposta HTTP 200 per assicurarsi che i link puntino al posto giusto.Test dei collegamenti di download con Nightwatch.js

Qualche idea su come testare i collegamenti ai file scaricabili con Nightwatch.js?

Ecco quello che ho attualmente:

/** 
* Test Software Downloads 
* 
* Verify that software downloads are working 
*/ 

module.exports = { 
    "Download redirect links": function (browser) { 

     // download links 
     var downloadLinks = { 
      "software-download-latest-mac": "http://downloads.company.com/mac/latest/", 
      "software-download-latest-linux": "http://downloads.company.com/linux/latest/", 
      "software-download-latest-win32": "http://downloads.company.com/windows/32/latest/", 
      "software-download-latest-win64": "http://downloads.company.com/windows/64/latest/" 
     }; 

     // loop through download links 
     for (var key in downloadLinks) { 
      if (downloadLinks.hasOwnProperty(key)) { 

       // test each link's status 
       browser 
        .url(downloadLinks[key]); 
      } 
     } 

     // end testing 
     browser.end(); 
    } 
}; 

risposta

5
  1. utilizzare il modulo nodo http e fare una "testa" richiesta
  2. Per esempio: affermare la dimensione del file

test.js

var http = require("http"); 

module.exports = { 
    "Is file avaliable" : function (client) { 
    var request = http.request({ 
     host: "www.google.com", 
     port: 80, 
     path: "/images/srpr/logo11w.png", 
     method: "HEAD" 
    }, function (response) { 
     client 
     .assert.equal(response.headers["content-length"], 14022, 'Same file size'); 
     client.end(); 
    }).on("error", function (err) { 
     console.log(err); 
     client.end(); 
    }).end(); 
    } 
}; 

Riferimenti

+0

perfetto, grazie @mrzmyr –

Problemi correlati