Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to consecutively call asynchronous functions in Javascript

everyone, in my school, i have a project that i code javascript to automated test a page
i use webdriver to text
but i have a error : TypeError: loginPageInstance.inputUsername(…).inputPassword is not a function
at Context. (D:\PVD_HOCTAP\Back End\Javascript\Automated_Testing_demo\test\pageObject2\testScript/testLogin.js:18:67)
I still don’t know how to fix it. I hope everyone will help me. Sorry for my poor English, I hope everyone will forgive meenter image description hereenter image description here

I want my testcase must be setValue username and password before click

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since each of your functions return promises, you will need to await each one before you can call the next function. This make function chaining very cumbersome:

const loginPageInstance = new loginPage();
await (
  await (
    await loginPageInstance.inputUsername(loginData.correctCredentials.username)
  ).inputPassword(loginData.correctCredentials.password)
).clickOnLoginBtn();

Since the promise resolves to the same instance you started with, i would instead recommend doing it like this:

await loginPageInstance.inputUsername(loginData.correctCredentials.username)
await loginPageInstance.inputPassword(loginData.correctCredentials.password)
await loginPageInstance.clickOnLoginBtn();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading