0

Expert just wondering why is it always NaN will be the output value using parseInt. I need help with your idea how parse the string converting to a number output. I'm trying to run a test using webdriver.io framework. Thank you.

sql query:

async function getUserRecords(userLogin) {
    var result = {};
    const query = statements.getUserTotalRecords(userLogin);
    console.log('~ checkDB ~ query', query);
    result = await db.executeQuery(query);
    return result[0].userValue;
}

test case:

it('Verify user records', function () {
        if (browser.options.regionLength == 1) 
{
            this.skip();
        } else {
            var result1 =  getUserRecords('testuser');
            var result2 =  Number(result1, 10);
            console.log('User Records: ' + result2);
        }
    });

Output: Alert Records: NaN Expected: 23

QA Tester
  • 23
  • 3
  • We can't tell you without knowing what `await db.executeQuery(query)` results in. Clearly, though, it isn't something where `result[0].userValue` is a number or numeric string. Your best bet is to [debug it](https://stackoverflow.com/questions/25385173/) to find out why. More about debugging: https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – T.J. Crowder May 24 '23 at 09:34
  • Note: The `Number` function ignores any arguments you give it after the first one, so `Number(result1, 10)` is just like `Number(result1)`. (I'm guessing it was originally `parseInt` but the you tried `Number` in hopes it would work.) – T.J. Crowder May 24 '23 at 09:35
  • 1
    `getUserRecords` returns a promise, not the user value. You need to deal with the fact that the user value is only available in the future, so you need to await that. – trincot May 24 '23 at 09:41
  • Hi @T.J.Crowder thank you for your prompt response, right when I try to put await it will return value of 23 as expected. I've just tried to parse string to integer without using async/await because of the existing script will fail the test script commands of webdriverio. – QA Tester May 24 '23 at 10:22

0 Answers0