ulixee / hero

The web browser built for scraping
MIT License
657 stars 32 forks source link

Adjust FlowCommand syntax #101

Closed blakebyrnes closed 2 years ago

blakebyrnes commented 2 years ago

FlowCommands now take only 2 parameters. You can either provide 2 parameters where the exitState is a callback:

await hero.flowCommand(async () => {
  const field = await hero.querySelector('#text').$waitForVisible();
  await field.$type('test');
}, (assert) => {
    assert(hero.querySelector('#text').value, 'test');
});

or 2 parameters where the second parameter is an object with options:

await hero.flowCommand(async () => {
  const field = await hero.querySelector('#text').$waitForVisible();
  await field.$type('test');
 }, {
  maxRetries: 2,
  exitState(assert) {
    assert(hero.querySelector('#text').value, 'test');
  },
});
blakebyrnes commented 2 years ago

It’s not needed since domstate implements IDomState

On Mar 6, 2022, at 6:06 AM, Caleb Clark @.***> wrote:

 @calebjclark commented on this pull request.

In client/lib/Hero.ts:

  • exitState?: IDomState | DomState | IDomStateAllFn,
  • options?: IFlowCommandOptions,
  • optionsOrExitState?: IDomStateAllFn | IFlowCommandOptions, Shouldn't optionsOrExitState also accept an instance of DomState?

I'm going to go ahead and merge. We can figure this out later, but I wanted to at least put it out there.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

calebjclark commented 2 years ago

Although this is allowed:

await hero.flowCommand(async () => {
  const field = await hero.querySelector('#text').$waitForVisible();
  await field.$type('test');
 }, {
  maxRetries: 2,
  exitState: new DomState({...}),
});

This does not seem to be allowed:

await hero.flowCommand(async () => {
  const field = await hero.querySelector('#text').$waitForVisible();
  await field.$type('test');
 }, new DomState({...}));