Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the best way to log in protractor?


Asked by Ariah Stevenson on Dec 10, 2021 FAQ



According to protractors documentation, .getText () returns a promise. Promise is an Object is javascript. So this is what you're logging. The best way to handle a promise, as of 2021, is to use async/await keywords.
In this manner,
To run a protractor test you need to type protractor config.js where config.js is the configuration file of your tests (will be discussed in the next section). But just to abbreviate it every time in the running, we map protractor path/to/configuration/file to a placeholder which is simply “test”.
Thereof, When user wants to log the expected and actual result in protractor always use then method implementation. verifyDisplayedText (locator: Locator, expectedText: string) { const text = this.getText (locator); try { text.then (function (value) { if (value.trim () === expectedText) { verifyLog ("VERIFICATION: PASSED.
Furthermore,
The best way to handle a promise, as of 2021, is to use async/await keywords. This will make Protractor 'freeze' and wait, until the promise is resolved before running the next command .then () can also be used, but using async/await will make your code a lot more readable and easier to debug.
Also Know,
We can find the elements on the webpage using few ways in protractor. We can find the element on the web page using element () method in the protractor, element () method will return only single element. If there are more elements are matching, then element () method will return only the first match.