Plugin support?
Hello,
I was wondering if there is any plugin support to add custom methods to rize.
My motive for this is that I was writing a module to add waiting for logs functionality For example, you could do something like:
const logs = record(page, 'console')
const goTo = await page.goto('https://github.com/GoogleChrome/puppeteer')
await waitForLog(logs, 'As part of an experiment, Chrome temporarily shows only the lock icon in the address bar. Your SSL certificate with Extended Validation is still valid.')
This way, you could wait for a specific console.log to happen, or any other event for that matter, for example, dialog.
So I was wondering if I could add these custom "wait for event" methods myself, so the resulting code would be like
rize
.goto('https://github.com/')
.waitForLog('As part of an experiment...')
.waitForNavigation()
.end()
Or even making this native to rize; because of how the way rize works, it can listen on events before a goto happens, and all of that can be handled internally.
I think this feature of waiting for events would make rize an ever stronger alternative to cypress.
I like this idea! But, can you describe the detail of "wait for event"?
I did this proof of concept to show how waiting for page events work. https://github.com/zzyyxxww/pupster
You can follow the readme instructions to run it.
Here's a rundown of how it happens:
- Before loading the page, I do a
page.on(event, ...)on the desired event to wait later on, in the example it's theconsoleevent. - The handler of this
onsaves every event in a list inside a instance of classRecorder(in the code, this is therecordmodule). - When I want to check if a specific event happened, the
Recorderclass has anuntilmethod thatshifts the events until one satisfies the condition passed.
Thisuntilmethod is also async, so if a new event happens that satifies the condition afteruntilwas called, then it resolves succesfully. - All in all, if this takes longer than x milliseconds, then this times out and rejects the
waitForLogoperation (in the code this is thesoon-promisemodule).
You can see with my code that there is some complexity because to first run the waitForLog you have to had run record(page, 'console'), while with rize it could potentially be just one call.
Hmm...I don't understand what's the relationship between plugin support of Rize and your concepts.
I could add this functionality with plugin support, but maybe it would make rize more versatile if it was built in.
What feature do you want to build in specifically?
I could implement waitForLog initially. I'm not entirely sure how to implement it, but I think it could be a good addition.
Does the waitForLog method just print or log something?
It expects a certain console.log to happen, comparing by either matching a regex or equality to a string.
You may consider the execute method to achieve that.