export class StepFrameContext{constructor(t,e=[]){this.path=e,this.target=t}toScript(){const t=StepFrameContext.getExpressionForTarget(this.target);let e="const frame = targetPage.mainFrame()";for(const i of this.path)e+=`.childFrames()[${i}]`;return e+=";",t.push(e),t}static getExpressionForTarget(t){return"main"===t?["const targetPage = page;"]:[`const target = await browser.waitForTarget(p => p.url() === ${JSON.stringify(t)});`,"const targetPage = await target.page();"]}}export class ConditionAddedEvent extends Event{constructor(t){super("condition-added",{}),this.data={condition:t}}}export class Step extends EventTarget{constructor(t){super(),this.action=t,this.condition=null}addCondition(t){this.condition=t,this.dispatchEvent(new ConditionAddedEvent(t))}}export class ClickStep extends Step{constructor(t,e){super("click"),this.context=t,this.selector=e}toScript(){return[...this.context.toScript(),this.condition?this.condition.toString():null,`const element = await frame.waitForSelector(${JSON.stringify(this.selector)});`,"await element.click();",this.condition?"await promise;":null]}}export class NavigationStep extends Step{constructor(t){super("navigate"),this.url=t}toScript(){return[`await page.goto(${JSON.stringify(this.url)});`]}}export class SubmitStep extends Step{constructor(t,e){super("submit"),this.context=t,this.selector=e}toScript(){return[...this.context.toScript(),this.condition?this.condition.toString():null,`const element = await frame.waitForSelector(${JSON.stringify(this.selector)});`,"await element.evaluate(form => form.submit());",this.condition?"await promise;":null]}}export class ChangeStep extends Step{constructor(t,e,i){super("change"),this.context=t,this.selector=e,this.value=i}toScript(){return[...this.context.toScript(),this.condition?this.condition.toString():null,`const element = await frame.waitForSelector(${JSON.stringify(this.selector)});`,`await element.type(${JSON.stringify(this.value)});`,this.condition?"await promise;":null]}}export class CloseStep extends Step{constructor(t){super("close"),this.target=t}toScript(){return[...StepFrameContext.getExpressionForTarget(this.target),"await targetPage.close();"]}}export class EmulateNetworkConditions extends Step{constructor(t){super("emulateNetworkConditions"),this.conditions=t}toScript(){return[`// Simulated network throttling (${"function"===typeof this.conditions.title?this.conditions.title():this.conditions.title})`,"const client = await page.target().createCDPSession();","await client.send('Network.enable');","await client.send('Network.emulateNetworkConditions', {","  // Network connectivity is absent",`  offline: ${!this.conditions.download&&!this.conditions.upload},`,"  // Download speed (bytes/s)",`  downloadThroughput: ${this.conditions.download},`,"  // Upload speed (bytes/s)",`  uploadThroughput: ${this.conditions.upload},`,"  // Latency (ms)",`  latency: ${this.conditions.latency},`,"});"]}}