尝试使用承诺传递查询结果时,我得到了以下错误[0-0](node:16336)未处理PromisejectionWarning

wfveoks0  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(148)

这是测试用例场景

describe('contacts page test',  function(){
    it('creating a new contact ',  function(){
        browser.url('/')
        login.doLogin(configData.username, configData.password)
        contacts.createNewContact('contact')
    })
})

createnewcontact函数

createNewContact = async (tableName)=>{
            console.log('inside createNewContact')
            //going to the contact page
            elementUtil.doClick(homePageElements.contactLink)
            elementUtil.doClick(homePageElements.secondaryContact)

            //clicking new button
            elementUtil.doClick(contactspageElements.newContactLink)

            var arr = []
            try{
                await db.retrieve(tableName).then(result=>{
                    arr = result
                    console.log('result')
                    console.log(result)
                }).catch(err=>{console.log(err)})
            }catch(err){
                console.log(err)
            }
            console.log('arr: ')
            console.log(arr)
            console.log(typeof arr[0].username)

            // //inserting values
            elementUtil.doPromiseSetValue(contactspageElements.userName, JSON.stringify(arr[0].username))
            elementUtil.doPromiseSetValue(contactspageElements.firstName, JSON.stringify(arr[0].firstname))
            elementUtil.doPromiseSetValue(contactspageElements.lastName, JSON.stringify(arr[0].lastname))
            console.log('reached the contact creation')
            //creating contact
            elementUtil.doClick(  contactspageElements.createContactButton ); 
            browser.pause(10000)
            //again goin to the contact page
            elementUtil.doClick(homePageElements.contactLink)
            elementUtil.doClick(homePageElements.secondaryContact)
            browser.pause(20000) 
        }

db.retrieve()函数

retrieve (tableName){
        const connection = this.getConnection()
        connection.connect()
        console.log('inside retrieve')       
        return new Promise((resolve, reject)=>{
            connection.query(`select * from ${tableName}`, function(err, result){
                connection.end()
                if(err) reject(err)
                else resolve(result)
            })
        }) 
    }

这就是我犯的错误

UnhandledPromiseRejectionWarning: TypeError: element.waitForDisplayed is not a function at ElementUtil.doClick (G:\javascript automation\New folder\wdio-test-framework\util\element.util.js:6:17)
at ContactsPage.createNewContact (G:\javascript automation\New folder\wdio-test-framework\src\pages\contacts.page.js:41:21)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:15156) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题