Skip to content

Commit

Permalink
fix: access locators via a shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Jul 7, 2023
1 parent cde53a8 commit 5145546
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
68 changes: 34 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"mime": "3.0.0",
"mocha": "10.1.0",
"prettier": "2.7.1",
"puppeteer": "20.7.4",
"puppeteer-core": "20.7.4",
"puppeteer": "20.8.0",
"puppeteer-core": "20.8.0",
"rimraf": "3.0.2",
"rollup": "3.2.2",
"rollup-plugin-dts": "5.0.0",
Expand All @@ -91,7 +91,7 @@
},
"peerDependencies": {
"lighthouse": ">=10.0.0",
"puppeteer": ">=20.7.3"
"puppeteer": ">=20.8.0"
},
"peerDependenciesMeta": {
"puppeteer": {
Expand Down
56 changes: 28 additions & 28 deletions src/PuppeteerRunnerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import {
import type {
Browser,
ElementHandle,
Frame,
Page,
Locator,
LocatorEmittedEvents,
Page,
} from 'puppeteer';
import { Frame as InternalFrame } from 'puppeteer-core/internal/common/Frame.js';
import { CDPPage as InternalPage } from 'puppeteer-core/internal/common/Page.js';
Expand Down Expand Up @@ -119,18 +118,19 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
const startWaitingForEvents = () => {
assertedEventsPromise = waitForEvents(localFrame, step, timeout);
};
const locatorRace = (this.page as unknown as InternalPage).locatorRace;

switch (step.type) {
case StepType.DoubleClick:
await Locator.race(
await locatorRace(
step.selectors.map((selector) => {
return targetPageOrFrame.locator(
selectorToPElementSelector(selector)
);
return (
targetPageOrFrame as unknown as InternalPage | InternalFrame
).locator(selectorToPElementSelector(selector));
})
)
.setTimeout(timeout)
.on(LocatorEmittedEvents.Action, () => startWaitingForEvents())
.on('action' as LocatorEmittedEvents, () => startWaitingForEvents())
.click({
count: 2,
button: step.button && mouseButtonMap.get(step.button),
Expand All @@ -142,15 +142,15 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
});
break;
case StepType.Click:
await Locator.race(
await locatorRace(
step.selectors.map((selector) => {
return targetPageOrFrame.locator(
selectorToPElementSelector(selector)
);
return (
targetPageOrFrame as unknown as InternalPage | InternalFrame
).locator(selectorToPElementSelector(selector));
})
)
.setTimeout(timeout)
.on(LocatorEmittedEvents.Action, () => startWaitingForEvents())
.on('action' as LocatorEmittedEvents, () => startWaitingForEvents())
.click({
delay: step.duration,
button: step.button && mouseButtonMap.get(step.button),
Expand All @@ -161,15 +161,15 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
});
break;
case StepType.Hover:
await Locator.race(
await locatorRace(
step.selectors.map((selector) => {
return targetPageOrFrame.locator(
selectorToPElementSelector(selector)
);
return (
targetPageOrFrame as unknown as InternalPage | InternalFrame
).locator(selectorToPElementSelector(selector));
})
)
.setTimeout(timeout)
.on(LocatorEmittedEvents.Action, () => startWaitingForEvents())
.on('action' as LocatorEmittedEvents, () => startWaitingForEvents())
.hover();
break;
case StepType.EmulateNetworkConditions:
Expand Down Expand Up @@ -201,14 +201,14 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
}
break;
case StepType.Change:
await Locator.race(
await locatorRace(
step.selectors.map((selector) => {
return targetPageOrFrame.locator(
selectorToPElementSelector(selector)
);
return (
targetPageOrFrame as unknown as InternalPage | InternalFrame
).locator(selectorToPElementSelector(selector));
})
)
.on(LocatorEmittedEvents.Action, () => startWaitingForEvents())
.on('action' as LocatorEmittedEvents, () => startWaitingForEvents())
.setTimeout(timeout)
.fill(step.value);
break;
Expand All @@ -221,14 +221,14 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
}
case StepType.Scroll: {
if ('selectors' in step) {
await Locator.race(
await locatorRace(
step.selectors.map((selector) => {
return targetPageOrFrame.locator(
selectorToPElementSelector(selector)
);
return (
targetPageOrFrame as unknown as InternalPage | InternalFrame
).locator(selectorToPElementSelector(selector));
})
)
.on(LocatorEmittedEvents.Action, () => startWaitingForEvents())
.on('action' as LocatorEmittedEvents, () => startWaitingForEvents())
.setTimeout(timeout)
.scroll({
scrollLeft: step.x || 0,
Expand Down

0 comments on commit 5145546

Please sign in to comment.