Results 1 to 5 of 5

Thread: ST API - examine xhr content

  1. #1
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    125
    Vote Rating
    6
      0  

    Default Answered: ST API - examine xhr content

    Hiya,

    I am a beginner in Sencha Test and evaluating the product. I would like to know whether the ST API can examine the content of XHR result like in Cypress?

    Many thanks
    Joe

  2. You could try something like this:

    Code:
    describe('Ajax request tests', function() {
        beforeAll(function() {
            var me = this;
            me.ajaxResponses = [];
            
            // Listen for all Ajax responses
            Ext.Ajax.on('requestcomplete', function(connection, response, options) {
                me.ajaxResponses.push({
                    url: options.url,
                    response: JSON.parse(response.responseText)
                });
            });
        });
        
        it('should click button then wait for and inspect the Ajax response', function() {
            var me = this;
            
    
            ST.button('button[text="Login"]')
                .click()
                .wait('for Ajax response', function(cmp) {
                    // Wait for there to be an Ajax response as a result of the button click
                    return me.ajaxResponses.length > 0;
                })
                .and(function() {
                    // Write a test against the response
                    var response = me.ajaxResponses[0].response;
                    
                    expect(response.emailAddress).toBe('test@test.com');
                });
        });
    });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    253
    Answers
    32
    Vote Rating
    31
      0  

    Default

    You can write a test for an Ajax request, for example:

    Code:
    describe('Ajax request', function() {
        it('should check data can be loaded', function(done) {
            Ext.Ajax.request({
                url: '/KitchenSink/BigData',
                callback: function(request, success, response) {
                    if (success) {
                        // test for success
                        var data = JSON.parse(response.responseText);
                        
                        expect(data.length).toBe(500);
                    } else {
                        // test for failure
                    }
                    
                    done();
                }
            });
        });
    });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  4. #3
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    125
    Vote Rating
    6
      0  

    Default

    Hi Daniel,

    What I would like to do is to capture the XHR content from an action (clicking a button) initiated in the test. E.g. the XHR result of Login Ajax query.

    Thanks
    Joe

  5. #4
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    253
    Answers
    32
    Vote Rating
    31
      0  

    Default

    You could try something like this:

    Code:
    describe('Ajax request tests', function() {
        beforeAll(function() {
            var me = this;
            me.ajaxResponses = [];
            
            // Listen for all Ajax responses
            Ext.Ajax.on('requestcomplete', function(connection, response, options) {
                me.ajaxResponses.push({
                    url: options.url,
                    response: JSON.parse(response.responseText)
                });
            });
        });
        
        it('should click button then wait for and inspect the Ajax response', function() {
            var me = this;
            
    
            ST.button('button[text="Login"]')
                .click()
                .wait('for Ajax response', function(cmp) {
                    // Wait for there to be an Ajax response as a result of the button click
                    return me.ajaxResponses.length > 0;
                })
                .and(function() {
                    // Write a test against the response
                    var response = me.ajaxResponses[0].response;
                    
                    expect(response.emailAddress).toBe('test@test.com');
                });
        });
    });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  6. #5
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    125
    Vote Rating
    6
      0  

    Default

    Cool. Of course. You are star.

Similar Threads

  1. Replies: 1
    Last Post: 31 Jan 2015, 6:54 PM
  2. how to examine dom is null or not?
    By nigde51 in forum Ext: Q&A
    Replies: 1
    Last Post: 17 Dec 2013, 6:36 AM
  3. Replies: 10
    Last Post: 17 Jun 2009, 7:40 AM
  4. Do you have the software that can examine JAVASCRIPT variable quantity in IE?
    By yanji94521 in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 10 Nov 2008, 8:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •