wwag110465 / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

Retrieve empty string when testing Ajax call #257

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I use js-test-driver as our ultimate solution to setting up javascript ut 
framework for our project. When I came to write test case for ajax call, 
problem emerged. I saw your Asynchronized Test wiki page, and tried to copy 
those example code into our testing script, sending out a request to run a Perl 
CGI. The request I sent returned with status of 200, but with empty string 
simultaneously(readyState is 4)

So I'm wondering whether the request really sent or the framework simply 
simulate the send action only? Is there any way that I can get the real output 
of cgi. I'm looking forward to your reply. Thanks in advance.

The directory structure is like 

cgi:
/pts-dev/proposal_editor/cgi/get_hp_name.pl

test script:
/pts-dev/t/js_ut/ut_proposal_editor_ajax.js

Here's the code:

async.prototype.testRequestHpName = function(queue){
    var xhr = new XMLHttpRequest();
    proposalNumber=10015;
    xhr.open("get", "../../proposal_editor/cgi/get_hp_name.pl?"+"10015");
    queue.call("Step1:send out the request",function(callbacks){
        var invokeFunction = callbacks.add(function(){
            requestHpName();
        });
        var onBodyRecieved = callbacks.add(function(body){
            requestBodyExpected = body;
        });
        var onStatusReceived = callbacks.add(function(status){
            assertEquals(200,status);
        });
        invokeFunction();
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 2){
                onStatusReceived(xhr.status);
            }
            else if(xhr.readyState == 4){
                onBodyRecieved(xhr.responseText);
            }
        }
        xhr.send(null);
    });
    queue.call("Step2:'Step2: assert the response body matches what we expect. '",function(callbacks){
        assertEquals(requestBodyExpected,document.getElementById("txtHpNameFull").innerHTML);
    }); 
}

Original issue reported on code.google.com by metellu....@gmail.com on 26 Jul 2011 at 8:48

GoogleCodeExporter commented 8 years ago
So, the issue is that the perl script is not getting called. The first issue is 
that you need to be running a webserver that supports perl. JsTD server being 
jetty does not.

So you need to start a webserver, and configure JsTD to proxy calls to the web 
server. See http://code.google.com/p/js-test-driver/wiki/Proxy. Feel free to 
email the mailing list for more help.

I'm closing this bug as invalid, as it isn't a bug, more of a setup issue for 
the test.

Original comment by corbinrs...@gmail.com on 28 Jul 2011 at 3:05