CasperJS and file upload via iFrame and JavaScript

I have a script to verify that - when clicked - it generates an iFrame that loads the file. How can I intercept an answer using CasperJS?

I have already tried the sequence:

casper.click('element');
casper.withFrame('frame', function(){
    console.log(this.getCurrentUrl()); // only return about:blank, but should have URL
    console.log("content: " + this.getHTML()); // Yep, empty HMTL

    this.on('resource.received', function(resource){
        console.log(resource.url); // never executed
    });
});

I need the contents of the file, but cannot create the URL without clicking the element or changing the script that I am testing.

Ideas?

0
source share
1 answer

I tried other events, but none were fired when loading via iframe. I found another solution that works, but if you have something better, I would like to try.

There he is:

// Check downloaded File
.then(function(){

    // Fetch URL via internals
    var url = this.evaluate(function(){
        return $('__saveReportFrame').src; // JavaScript function in the page
    });

    var file = fs.absolute('plaintext.txt');
    this.download(url, file);

    var fileString = fs.read(file);

    // Whatever test you want to make
    test.assert(fileString.match(/STRING/g) !== null, 'Downloaded File is good');
})
0
source

Source: https://habr.com/ru/post/1664362/


All Articles