Search code examples
javascriptasynchronousimportwebdriver-io

how to import async modules with JS


Maybe i asked wrong question.

i'm trying to test some site, and have this throw in terminal

terminal output

it's obvious, that function returns uuid after it was called in code. it work's normaly, when i take element right in code, so the reason, i think, in uncorrect import

here's my code :

file.js

describe('final homeTask', () => {
    it('firstassigment', async () => {
        let mainPage = require('../page/main.pageHW.js')
        await browser.url('https://github.com/')

        let signUpButton = await mainPage.topSignUpBtn()
        await signUpButton.click()
    })
})

main.pageHW.js

class MainPage {
    get topSignUpBtn () { return $('a.btn-mktg:nth-child(1)') }
}

module.exports = new MainPage()

Solution

  • It is a problem with Javascript, not about webdriver, you are using a property in the MainPage class:

      class MainPage {
          /// The get word make it a property
          get topSignUpBtn () { return $('a.btn-mktg:nth-child(1)') }
      }
    
      module.exports = new MainPage()
    

    That means you DON'T need parentheses to use it, so, replace:

      let signUpButton = await mainPage.topSignUpBtn()
    

    By

      let signUpButton = await mainPage.topSignUpBtn;
    

    Also, the property doesn't need the await clause.

    If you want more info you can check this link.