can't get cropper canvas - casperJS 1.1.0-beta3 | phantomJS 1.9.2

24 views
Skip to first unread message

guillaume bourbon

unread,
Apr 28, 2016, 4:04:45 AM4/28/16
to CasperJS
Hi, 

I use CasperJS  (v1.1.0-beta3) and PhamtomJS (v1.9.2) to upload some pictures with a jQuery Cropper but it doesn't upload when I click on the upload button.

Here my Casper script :

.then(function() {
    //Show and Hide Input File
    this.evaluate(function() {
        jQuery('#new_upload_image').css('display', 'block');
    });                  
                               
    this.fill('form#postform', {
        'upload_data': '".$image."'
    }, false);                          

    this.evaluate(function() {
        jQuery('#new_upload_image').css('display', 'none');
    });                          
})
.then(function() {
    if(this.exists('button#done')) {
        this.evaluate(function() {
            jQuery('#done').click();
        });
        //The click event is correctly fired
    }
    else {
        this.die('button dont exist', 1);
    }                            
})

And Here the upload script :

A.$done.click(function() {
    if (A.$cropper === null) {
        return false;
    }
    A.$loader.show();
    var E = A.$cropper.getCroppedCanvas({
        width: 840,
        height: 740,
        fillColor: "#fff"
    });
    var H = E.toDataURL("image/jpeg", 0.98);
    var F = new FormData();
    var C = A.convertToBlob(E, "image/jpeg", H);
    var D = {
        action: "upload"
    };
    var G = A.createParams(D);
    F.append("upload_data", C, A.file_name);
    F.append("params", JSON.stringify(G));
    xhr = new XMLHttpRequest();
    xhr.open("POST", A.url, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            A.success(JSON.parse(xhr.responseText));
            A.$loader.hide();
            A.$uploadBtn.show();
        } else {
            if (xhr.status === 404 || xhr.status === 500) {
                A.showErrorMessage(__("general_upload_fail_mobile"));
                A.$loader.hide();
                A.$uploadBtn.show();
                A.resetFormElement(A.$input);
            }
        }
    };
    xhr.send(F);
    $J("html, body").scrollTop(A.$header.offset().top);
    A.hideCropper();
});

The loader is active when I take a screenshot after the click but the cropper is not hide and no xhr request is done.

I think the problem is from the cropper "getCroppedCanvas" method, in can't confirm that. 

Is Canvas correctly supported by the 1.9.2 version of phantom  and casper ? or i did something wriong ?

thank for help.


Reply all
Reply to author
Forward
0 new messages