Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin support? #9

Open
gtarsia opened this issue May 29, 2019 · 9 comments
Open

Plugin support? #9

gtarsia opened this issue May 29, 2019 · 9 comments

Comments

@gtarsia
Copy link

gtarsia commented May 29, 2019

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.

@g-plane
Copy link
Owner

g-plane commented May 30, 2019

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

@gtarsia
Copy link
Author

gtarsia commented May 30, 2019

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.

@g-plane
Copy link
Owner

g-plane commented May 30, 2019

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

@gtarsia
Copy link
Author

gtarsia commented May 30, 2019

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

@g-plane
Copy link
Owner

g-plane commented May 30, 2019

What feature do you want to build in specifically?

@gtarsia
Copy link
Author

gtarsia commented May 30, 2019

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

@g-plane
Copy link
Owner

g-plane commented May 30, 2019

Does the waitForLog method just print or log something?

@gtarsia
Copy link
Author

gtarsia commented May 30, 2019

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

@g-plane
Copy link
Owner

g-plane commented May 30, 2019

You may consider the execute method to achieve that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants