Our first custom wrapper method – global.log()
Question: what is a wrapper?
A wrapper is a bespoke method or function that is almost identical in signature to an intrinsic method but with added functionality. In our first example, we will create a global wrapper for console.log()
.
While the console.log()
method is good for outputting information to the console window, it can be enhanced and shortened. Let’s build our first log()
wrapper at the end of the wdio.config.ts
file:
/** * log wrapper * @param text to be output to the console window */ global.log = async (text: any) => { console.log(`---> ${text}`) }
This global.log()
wrapper is almost identical to console.log
except it has some text formatting that stands out. Let’s look at this by adding some examples to the test:
console.log (`Entering password`) [0-0] Entering password await global.log (`Entering password`) [0-0] ---> Entering password
This...