I want to get a value using page.evaluate (value is stored as a global variable on window) and do a custom matcher. Simply put it should replace something like:
const ret = await page.evalute((name) => window.myVar.name)
expect(name).toEqual(1);
// so I would like a custom expect like:
expect(name).toHaveValue(num)
Any useful tip? specifically - how can I get access to page on a custom matcher?
This thread is trying to answer question "How can I get access to page on a custom matcher in JavaScript?"
Hmmm, this might be tricky, my understanding javascript wont allow you to do reflection as you might in C#. You can't directly reference a variable like this. While i'm thinking you can have a method on your webpage that will work as a proxy, that method would reference a dictionary you've created for this purpose, pass in the key/variable name and you mapping/proxy function will return the value back... Then using PW's evaluate you should be able to get the value...
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].