Results 1 to 3 of 3

Thread: Can I delay evaluation of a variable used in a playable() object?

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    18
    Vote Rating
    0
      0  

    Default Answered: Can I delay evaluation of a variable used in a playable() object?

    I want to run this sequence as part of an e2e test.

    1) Add a row to a grid
    2) Delete the final row in the grid, after the new row is added

    The issue I'm running into is that the value I'm trying to pass to my locator for a 'tap' appears to be calculated before any of the playable events run. Is there an easy way around this to delay the variable evaluation?

    I realize there are other ways besides using the tap() method to set the selected row in a grid (something along the lines of setting selectedRow on the view model) but in general I'm interested in finding out whether this method is feasible at all since the combo of locators/playable events is so easy to work with.

    Pseudocode:

    Code:
    var lastRowIndex = -1;
    ST.play([            
                 { type: "tap", target: "treelistitem[text=\"Add Row to Grid\"]" },
    
    
                 { fn:function (next) {
                   lastRowIndex = Ext.ComponentQuery.query('grid[reference=wrgrid]')[0].getStore().totalCount -1;
                   next();
                 }},
    
    
                 //lastRowIndex is evaluating to -1 here instead of the number of rows evaluated in the previous playable event
                 { type: "tap", target: "grid[reference=\"wrgrid\"] => [data-recordindex=\"" + lastRowIndex + "\"]" }   
    ]);
    Thanks!
    -Joe

  2. The problem here is the array of actions passed in to ST.play is evaluated before lastRowIndex is set within the function.

    I'd recommend doing something like the example below, which is based on this Kitchen Sink demo: http://examples.sencha.com/extjs/6.5...c#cell-editing.

    Code:
    describe('Add and Delete Rows', function() {
        it('Should add a new row to grid', function() {
            ST.button('button[text=Add Plant]')
                .click();
            
            // Add new record title
            ST.textField('[allowBlank=false]')
                .setValue('AAA');
                
            // Lose focus of the cell, to commit new record changes
            ST.grid('[title=Cell Editing Plants]')
                .focus();
        });
        
        it('Should delete the last row in the grid', function() {
            ST.execute(function() {
                // Get the total count of records from the underlying Store.
                // Using "execute" allows you to run this function in the context of the browser.
                return Ext.ComponentQuery.query('[title=Cell Editing Plants]')[0].getStore().getTotalCount();
            })
            .and(function(future) {
                ST.grid('[title=Cell Editing Plants]')
                    .rowAt(future.data.executeResult)
                    .cellAt(5)
                    .click();   // Click the delete button in the grid's action column
            });
        });
    });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    192
    Answers
    18
    Vote Rating
    23
      1  

    Default

    The problem here is the array of actions passed in to ST.play is evaluated before lastRowIndex is set within the function.

    I'd recommend doing something like the example below, which is based on this Kitchen Sink demo: http://examples.sencha.com/extjs/6.5...c#cell-editing.

    Code:
    describe('Add and Delete Rows', function() {
        it('Should add a new row to grid', function() {
            ST.button('button[text=Add Plant]')
                .click();
            
            // Add new record title
            ST.textField('[allowBlank=false]')
                .setValue('AAA');
                
            // Lose focus of the cell, to commit new record changes
            ST.grid('[title=Cell Editing Plants]')
                .focus();
        });
        
        it('Should delete the last row in the grid', function() {
            ST.execute(function() {
                // Get the total count of records from the underlying Store.
                // Using "execute" allows you to run this function in the context of the browser.
                return Ext.ComponentQuery.query('[title=Cell Editing Plants]')[0].getStore().getTotalCount();
            })
            .and(function(future) {
                ST.grid('[title=Cell Editing Plants]')
                    .rowAt(future.data.executeResult)
                    .cellAt(5)
                    .click();   // Click the delete button in the grid's action column
            });
        });
    });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  4. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    18
    Vote Rating
    0
      0  

    Default

    got it. Using a function to delay evaluation makes sense. thanks!

Similar Threads

  1. Playable - fn config
    By firefoxSafari in forum Q&A
    Replies: 3
    Last Post: 16 Nov 2016, 10:47 AM
  2. Sync futures and playable
    By Wilky in forum Q&A
    Replies: 2
    Last Post: 12 Sep 2016, 12:23 AM
  3. Json object as a variable
    By jedihua in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 21 Dec 2010, 12:35 PM
  4. Replies: 7
    Last Post: 9 Apr 2009, 10:17 AM
  5. Replies: 7
    Last Post: 9 Apr 2009, 10:17 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
  •