rize icon indicating copy to clipboard operation
rize copied to clipboard

Plugin support?

Open gtarsia opened this issue 6 years ago • 9 comments

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.

gtarsia avatar May 29 '19 14:05 gtarsia

I like this idea! But, can you describe the detail of "wait for event"?

g-plane avatar May 30 '19 02:05 g-plane

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 the console event.
  • The handler of this on saves every event in a list inside a instance of class Recorder (in the code, this is the record module).
  • When I want to check if a specific event happened, the Recorder class has an until method that shifts the events until one satisfies the condition passed.
    This until method is also async, so if a new event happens that satifies the condition after until was called, then it resolves succesfully.
  • All in all, if this takes longer than x milliseconds, then this times out and rejects the waitForLog operation (in the code this is the soon-promise module).

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.

gtarsia avatar May 30 '19 11:05 gtarsia

Hmm...I don't understand what's the relationship between plugin support of Rize and your concepts.

g-plane avatar May 30 '19 11:05 g-plane

I could add this functionality with plugin support, but maybe it would make rize more versatile if it was built in.

gtarsia avatar May 30 '19 11:05 gtarsia

What feature do you want to build in specifically?

g-plane avatar May 30 '19 11:05 g-plane

I could implement waitForLog initially. I'm not entirely sure how to implement it, but I think it could be a good addition.

gtarsia avatar May 30 '19 13:05 gtarsia

Does the waitForLog method just print or log something?

g-plane avatar May 30 '19 13:05 g-plane

It expects a certain console.log to happen, comparing by either matching a regex or equality to a string.

gtarsia avatar May 30 '19 15:05 gtarsia

You may consider the execute method to achieve that.

g-plane avatar May 30 '19 15:05 g-plane