Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

Protractor wait for async requests

I am working on an application where the data is saved asynchronously while it is being edited. As soon as a specific action is performed, protractor quits the test which leads to unsaved data. How to make protractor wait till all the requests are finished?

question from:https://stackoverflow.com/questions/66059423/protractor-wait-for-async-requests

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

https://stackoverflow.com/a/66072132/6793637

You can read this answer on how to use protractor

you can use await with any promise , but for call back function you have to make it a promise as you cannot use await with callback functions

Example:

const readFilePromise = () => {
  return new Promise((resolve, reject) => {
    fs.readFile(filePath, options, (err, data) => {
      if (err) return reject(err)
      resolve(data)
    })
  })
}

so we created a file read promise that resolves only after the call back is resolved

Now you can await it as

await readFilePromise ()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...