Results 1 to 7 of 7

Thread: Get rowcount and columncount for a Grid

  1. #1
    Sencha User
    Join Date
    Nov 2016
    Posts
    13
    Vote Rating
    0
      0  

    Default Get rowcount and columncount for a Grid

    Hi Team,

    I am testing a grid which gets a new row every time I add an entry. To check if the new row was added, I am planning to check difference in number of rows. How can get the rowcount of the grid?


    TIA.
    -Arun

  2. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    120
    Answers
    6
    Vote Rating
    19
      0  

    Default

    Are you trying to do this for a WebDriver scenario or In Browser scenario?
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  3. #3
    Sencha User
    Join Date
    Nov 2016
    Posts
    13
    Vote Rating
    0
      0  

    Default

    Daniel,

    I am doing this in browser scenario currently, but it would really help if you could explain it for both scenarios.


    Thanks,
    Arun

  4. #4
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    120
    Answers
    6
    Vote Rating
    19
      0  

    Default

    So for WebDriver scenarios, you are only able to make use of the Sencha Test Futures APIs - the "ST." APIs, not the "Ext." APIs, as the tests run separate from the browser. In a WebDriver scenario, you could check that a row exists by doing something like this:

    Code:
        it('Should contain the newly added row', function() {
            ST.grid('mainlist').rowWith('name', 'Jean Luc');
        });
    What that is doing is using the "rowWith" API that's included in Sencha Test, to search for a grid row where the data index matches a specified value, so you can use that to see if your new row has been successfully added. If the row doesn't exist, or cannot be found within the default timeout period, that will cause a test failure.

    For In-Browser scenarios, the tests run in the context of the browser, so you can use "Ext." APIs along with the Futures APIs, so the example above will also work for an In Browser scenario.

    Because you can use Ext JS APIs within In Browser scenarios, you can check the number of visible grid columns like this and assert that it matches a particular number:

    Code:
        it('Visible columns should equal 3', function() {
            var grid = Ext.ComponentQuery.query('mainlist')[0],
                columns = grid.getColumns(),
                visibleColumns = 0;
                
            for (var column of columns) {
                if (column.isVisible()) {
                    visibleColumns ++;
                }
            }
            
            expect(visibleColumns).toEqual(3);
        });
    Or get the row count like this, and assert that it equals a particular number:

    Code:
        it('Row count should equal 4', function() {
            var grid = Ext.ComponentQuery.query('mainlist')[0],
                store = grid.getStore(),
                itemCount = store.getCount();
                
            expect(itemCount).toEqual(4);
        });
    Hope that helps.
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  5. #5
    Sencha User
    Join Date
    Sep 2017
    Posts
    11
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by daniel.gallo View Post
    So for WebDriver scenarios, you are only able to make use of the Sencha Test Futures APIs - the "ST." APIs, not the "Ext." APIs, as the tests run separate from the browser. In a WebDriver scenario, you could check that a row exists by doing something like this:

    Code:
        it('Should contain the newly added row', function() {
            ST.grid('mainlist').rowWith('name', 'Jean Luc');
        });
    What that is doing is using the "rowWith" API that's included in Sencha Test, to search for a grid row where the data index matches a specified value, so you can use that to see if your new row has been successfully added. If the row doesn't exist, or cannot be found within the default timeout period, that will cause a test failure.

    For In-Browser scenarios, the tests run in the context of the browser, so you can use "Ext." APIs along with the Futures APIs, so the example above will also work for an In Browser scenario.

    Because you can use Ext JS APIs within In Browser scenarios, you can check the number of visible grid columns like this and assert that it matches a particular number:

    Code:
        it('Visible columns should equal 3', function() {
            var grid = Ext.ComponentQuery.query('mainlist')[0],
                columns = grid.getColumns(),
                visibleColumns = 0;
                
            for (var column of columns) {
                if (column.isVisible()) {
                    visibleColumns ++;
                }
            }
            
            expect(visibleColumns).toEqual(3);
        });
    Or get the row count like this, and assert that it equals a particular number:

    Code:
        it('Row count should equal 4', function() {
            var grid = Ext.ComponentQuery.query('mainlist')[0],
                store = grid.getStore(),
                itemCount = store.getCount();
                
            expect(itemCount).toEqual(4);
        });
    Hope that helps.
    Hi Danilo! Would you know if there's any way of getting the store count (number of rows) for a WebDriver scenario? Thanks!

  6. #6
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    120
    Answers
    6
    Vote Rating
    19
      1  

    Default

    @dayanef: To get the Store count, you can use the execute API to run some code in the context of the browser to return the count of records:

    Code:
    ST.grid('array-grid')
        .execute(function(grid) {
            return grid.getStore().getCount();
        })
        .and(function(future) {
            // Expect the store to contain 100 records
            expect(future.data.executeResult).toBe(100);
        });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  7. #7
    Sencha User
    Join Date
    Sep 2017
    Posts
    11
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by daniel.gallo View Post
    @dayanef: To get the Store count, you can use the execute API to run some code in the context of the browser to return the count of records:

    Code:
    ST.grid('array-grid')
        .execute(function(grid) {
            return grid.getStore().getCount();
        })
        .and(function(future) {
            // Expect the store to contain 100 records
            expect(future.data.executeResult).toBe(100);
        });

    That did the trick, Danilo! Thank you

Similar Threads

  1. Detecting rowcount in Ext-Grid using QTP
    By sjaideep in forum Community Discussion
    Replies: 1
    Last Post: 25 Feb 2010, 12:50 PM
  2. display rowcount on grid bottom bar
    By SunWuKung in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 11 Feb 2010, 4:12 AM

Tags for this Thread

Posting Permissions

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