Results 1 to 3 of 3

Thread: code flow problems with ST

  1. #1

    Default Answered: code flow problems with ST

    So I have this piece of code that tests whether a grid gets updated after having made a change to one of its records or not.

    The alert()-method clearly prints out the correct rowIndex and I've used the getRowIndex method several times before without a problem.

    After clicking 'OK' on the alert-popup the test fails with the following error: Timeout waiting for event to be ready for ST.future.Row

    I suppose the rowAt()-method is using the state of the rowIndex variable at the beginning of the it-block(), therefore trying to reference a row with an undefined value.

    How do I solve this?

    Code:
    it("check the grid for the updated record", function () {
                let rowIndex;
    
    
                ST.wait(4000)
                    .and(function () {
                         // iterates through the grids store and finds the records row index based of 5 criteria that are defined in a parent-describe()
                        getRowIndex(recordOne.contractId, recordOne.origin, recordOne.destination, recordOne.container, recordOne.commodity)
                            .then(function (returnedRowIndex) {
                                rowIndex = returnedRowIndex;
                            });
                    });
    
    
                stpo.p2pRateBuyFcl.searchGridElementsGrid()
                    .and(function () {
                        alert("row index: " + rowIndex); // -> visually prints out 9 as the rowIndex
                    })
                    .rowAt(rowIndex)
                    .cellWith('dataIndex', "buy_rate_local")
                    .focus()
                    .get('innerText')
                    .and(function (el) {
                        alert("cells inner text " + el.data.innerText)
                    });
            });
    Btw. substituting the .rowAt(rowIndex) with for example .rowAt(3) works and the test completes.

  2. Okay after trying out your suggestions this seemed to work out:

    Code:
    it("check the grid for the updated record", function (done) {
          ST.wait(4000)
              .and(function () {
                     getRowIndex(recordOne.contractId, recordOne.origin, recordOne.destination, recordOne.container, recordOne.commodity)
                          .then(function (returnedRowIndex) {
                                stpo.p2pRateBuyFcl.searchGridElementsGrid()
                                    .rowAt(returnedRowIndex)
                                    .cellWith('dataIndex', "buy_rate_local")
                                    .focus()
                                    .get('innerText')
                                    .and(function (el) {
                                        expect(el.data.innerText).toMatch(recordOne.newBuyRate.toString());
                                        done();
                                    });
                         });
                    });
            });
    });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    394
    Answers
    74

    Default

    When a test is executed, it is first parsed and all of the Future APIs are queued up, so the "rowIndex" will be undefined at the point when all of the actions are added to the queue. In order to incorporate the row index, you would nest your Future API calls inside of the "and", so that these get added to the queue after the row index is set. A simple example:

    Code:
    it('should do something with the grid', function() {
        let rowIndex;
    
    
        ST.wait(1000)
            .and(function () {
                // Hard-coded row index for demo purposes
                rowIndex = 2;
                
                // Place the code that needs to make use of the dynamic row index inside here
                ST.grid('cell-editing')
                    .rowAt(rowIndex);
            });
    });
    In your case, you would probably want to place the code that makes use of the row index inside of your "then", something like this:

    Code:
    it("check the grid for the updated record", function () {
        ST.wait(4000)
            .and(function () {
                getRowIndex(recordOne.contractId, recordOne.origin, recordOne.destination, recordOne.container, recordOne.commodity)
                    .then(function (returnedRowIndex) {
                        stpo.p2pRateBuyFcl.searchGridElementsGrid()
                            .rowAt(returnedRowIndex)
                            .cellWith('dataIndex', "buy_rate_local")
                            .focus()
                            .get('innerText')
                            .and(function (el) {
                                alert("cells inner text " + el.data.innerText);
                            });
                    });
            });
    });
    I don't recall without testing this, but you may also need to make use of "done" if your test completes too soon and proceeds to the next test, in order to tell it when it's actually finished due to the use of the promise - see below for an example. Try the above first though, to see if that works.

    Code:
    it("check the grid for the updated record", function (done) {
        ST.wait(4000)
            .and(function () {
                getRowIndex(recordOne.contractId, recordOne.origin, recordOne.destination, recordOne.container, recordOne.commodity)
                    .then(function (returnedRowIndex) {
                        stpo.p2pRateBuyFcl.searchGridElementsGrid()
                            .rowAt(returnedRowIndex)
                            .cellWith('dataIndex', "buy_rate_local")
                            .focus()
                            .get('innerText')
                            .and(function (el) {
                                alert("cells inner text " + el.data.innerText);
                            })
                            .and(done);
                    });
            });
    });
    Daniel Gallo
    Sales Engineer
    Sencha

  4. #3

    Default

    Okay after trying out your suggestions this seemed to work out:

    Code:
    it("check the grid for the updated record", function (done) {
          ST.wait(4000)
              .and(function () {
                     getRowIndex(recordOne.contractId, recordOne.origin, recordOne.destination, recordOne.container, recordOne.commodity)
                          .then(function (returnedRowIndex) {
                                stpo.p2pRateBuyFcl.searchGridElementsGrid()
                                    .rowAt(returnedRowIndex)
                                    .cellWith('dataIndex', "buy_rate_local")
                                    .focus()
                                    .get('innerText')
                                    .and(function (el) {
                                        expect(el.data.innerText).toMatch(recordOne.newBuyRate.toString());
                                        done();
                                    });
                         });
                    });
            });
    });

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
  •