0

cellsData have array like below in global variable

 [   { id: 2,
    cellId: 'R2C3',
    row: '2',
    col: '3',
    value: '202',
    rawValue: '202.0',
    numValue: '$202' },
  { id: 3,
    cellId: 'R2C4',
    row: '2',
    col: '4',
    value: '2034',
    rawValue: '2034.0',
    numValue: '$2,034' }]

I have a soda script in which I want to verify the data after reading from this array problem is it gives error on cellsData[startRowId].numValue as, 27 undefined

I tried global.cellsData also but no working

error

.keyYears table tbody tr:nth-child('+i+') td:nth-child(3)',''+ cellsData[startRowI ^

TypeError: Cannot read property '27' of undefined

    var browser = soda.createClient({
    .....
    });

// Retrieving data from Excel sheet    
testsheet.setAuth( 'user', 'pass', function(err){

if (err) console.log(err);

testsheet.getCells( 1, function(err, cellsObj){

    if (err) console.log(err);   

    cellsData = cellsObj.cells;
    rowcount = cellsObj.RowCount;
});

})


browser 
    .chain
    .session()  
    .setSpeed(speed)
    .setTimeout(2000)
    .open('/')
    .and(login('dev@dev.com', 'x1212GQsdtpS'))
    .and(verifyData())
    .end(function(err){
        console.log('error');

    });

function login(user, pass) {
  return function(browser) {
    browser
    .click('css=a#loginButton')
    .type('css=input.input-medium.email',user)
    .type('css=input.input.pwd',pass)
    .clickAndWait('css=a.btn.login')
    .assertTextPresent('Clients',function(){ console.log('logged in ok')})
  }
}


function verifyData() {
            var startRowId=27
    console.log('inside TestingSpreaddsheet')
    var totalLoop=(rowcount-5)+1
  return function(browser) {
    browser
    for (var i = 1; i <= 4; i++) {
    browser.assertText('css=div.keyYears table tbody tr:nth-child('+i+') td:nth-child(3)',''+ cellsData[startRowId].numValue +'',function(){ console.log('looks good')})
    .assertText('css=div.keyYears table tbody tr:nth-child('+i+') td:nth-child(5)',''+ cellsData[startRowId].numValue +'')
    .assertText('css=div.keyYears table tbody tr:nth-child('+i+') td:nth-child(6)',''+ cellsData[startRowId].numValue +'')
    .assertText('css=div.keyYears table tbody tr:nth-child('+i+') td:nth-child(7)',''+ cellsData[startRowId].numValue +'')

    }
  }
}

UPDATE Soda is running the chain before fetching my ExcelSheet Data. How to control chain ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dev G
  • 1,387
  • 4
  • 26
  • 43
  • is it `celldata` or `cellsdata` ? – user568109 Apr 28 '13 at 09:50
  • that is a typo i corrected in the post but the issue is something different – Dev G Apr 28 '13 at 17:24
  • it is throwing error because I am trying to access cells data before it is defined...how to take care it in nodejs? – Dev G Apr 29 '13 at 03:11
  • Try to initialize it with a dummy value, e.g. intialize with empty string or array. But always check for `undefined` value before actually using it. See http://stackoverflow.com/questions/858181/how-to-check-a-not-defined-variable-in-javascript – user568109 Apr 29 '13 at 17:10
  • But how to get value of cellsData prior to rest chain execution ? I have tried moving logic of Retrieving data from Excel Cell in function itself still instead of executing that first it is parsing rest of data – Dev G Apr 30 '13 at 02:59
  • `getCells` passes a function as an argument. Is that argument actually being executed ever? Can we see the definition for `getCells`? – Owen Allen May 02 '13 at 01:51
  • yes it get executed but before that Soda chain get executed hence it never find the cellsdata and hence error :( – Dev G May 02 '13 at 03:54

1 Answers1

0

in node, most things are async, not sync. the data hasn't arrived yet hence rest process breaking.

the only place in code where I have the data is inside testsheet function so i moved my test code there and it fixed this issue.

Dev G
  • 1,387
  • 4
  • 26
  • 43