How to use compensateHalfIntegerRoundingError method in Playwright Internal

Best JavaScript code snippet using playwright-internal

dom.js

Source:dom.js Github

copy

Full Screen

...438 for (const point of filtered[0]) {439 result.x += point.x / 4440 result.y += point.y / 4441 }442 compensateHalfIntegerRoundingError(result)443 return result444 }445 async _offsetPoint(offset) {446 const [box, border] = await Promise.all([447 this.boundingBox(),448 this.evaluateInUtility(449 ([injected, node]) => injected.getElementBorderWidth(node),450 {}451 ).catch((e) => {})452 ])453 if (!box || !border) return 'error:notvisible'454 if (border === 'error:notconnected') return border // Make point relative to the padding box to align with offsetX/offsetY.455 return {456 x: box.x + border.left + offset.x,457 y: box.y + border.top + offset.y458 }459 }460 async _retryPointerAction(461 progress,462 actionName,463 waitForEnabled,464 action,465 options466 ) {467 let retry = 0 // We progressively wait longer between retries, up to 500ms.468 const waitTime = [0, 20, 100, 100, 500] // By default, we scroll with protocol method to reveal the action point.469 // However, that might not work to scroll from under position:sticky elements470 // that overlay the target element. To fight this, we cycle through different471 // scroll alignments. This works in most scenarios.472 const scrollOptions = [473 undefined,474 {475 block: 'end',476 inline: 'end'477 },478 {479 block: 'center',480 inline: 'center'481 },482 {483 block: 'start',484 inline: 'start'485 }486 ]487 while (progress.isRunning()) {488 if (retry) {489 progress.log(490 `retrying ${actionName} action${491 options.trial ? ' (trial run)' : ''492 }, attempt #${retry}`493 )494 const timeout = waitTime[Math.min(retry - 1, waitTime.length - 1)]495 if (timeout) {496 progress.log(` waiting ${timeout}ms`)497 const result = await this.evaluateInUtility(498 ([injected, node, timeout]) =>499 new Promise((f) => setTimeout(f, timeout)),500 timeout501 )502 if (result === 'error:notconnected') return result503 }504 } else {505 progress.log(506 `attempting ${actionName} action${507 options.trial ? ' (trial run)' : ''508 }`509 )510 }511 const forceScrollOptions = scrollOptions[retry % scrollOptions.length]512 const result = await this._performPointerAction(513 progress,514 actionName,515 waitForEnabled,516 action,517 forceScrollOptions,518 options519 )520 ++retry521 if (result === 'error:notvisible') {522 if (options.force) throw new Error('Element is not visible')523 progress.log(' element is not visible')524 continue525 }526 if (result === 'error:notinviewport') {527 if (options.force) throw new Error('Element is outside of the viewport')528 progress.log(' element is outside of the viewport')529 continue530 }531 if (typeof result === 'object' && 'hitTargetDescription' in result) {532 if (options.force)533 throw new Error(534 `Element does not receive pointer events, ${result.hitTargetDescription} intercepts them`535 )536 progress.log(537 ` ${result.hitTargetDescription} intercepts pointer events`538 )539 continue540 }541 return result542 }543 return 'done'544 }545 async _performPointerAction(546 progress,547 actionName,548 waitForEnabled,549 action,550 forceScrollOptions,551 options552 ) {553 const { force = false, position } = options554 if (options.__testHookBeforeStable) await options.__testHookBeforeStable()555 const result = await this._waitForDisplayedAtStablePosition(556 progress,557 force,558 waitForEnabled559 )560 if (result !== 'done') return result561 if (options.__testHookAfterStable) await options.__testHookAfterStable()562 progress.log(' scrolling into view if needed')563 progress.throwIfAborted() // Avoid action that has side-effects.564 if (forceScrollOptions) {565 const scrolled = await this.evaluateInUtility(566 ([injected, node, options]) => {567 if (568 node.nodeType === 1569 /* Node.ELEMENT_NODE */570 )571 node.scrollIntoView(options)572 },573 forceScrollOptions574 )575 if (scrolled === 'error:notconnected') return scrolled576 } else {577 const scrolled = await this._scrollRectIntoViewIfNeeded(578 position579 ? {580 x: position.x,581 y: position.y,582 width: 0,583 height: 0584 }585 : undefined586 )587 if (scrolled !== 'done') return scrolled588 }589 progress.log(' done scrolling')590 const maybePoint = position591 ? await this._offsetPoint(position)592 : await this._clickablePoint()593 if (typeof maybePoint === 'string') return maybePoint594 const point = roundPoint(maybePoint)595 if (!force) {596 if (options.__testHookBeforeHitTarget)597 await options.__testHookBeforeHitTarget()598 progress.log(599 ` checking that element receives pointer events at (${point.x},${point.y})`600 )601 const hitTargetResult = await this._checkHitTargetAt(point)602 if (hitTargetResult !== 'done') return hitTargetResult603 progress.log(` element does receive pointer events`)604 }605 progress.metadata.point = point606 if (options.trial) {607 progress.log(` trial ${actionName} has finished`)608 return 'done'609 }610 await progress.beforeInputAction(this)611 await this._page._frameManager.waitForSignalsCreatedBy(612 progress,613 options.noWaitAfter,614 async () => {615 if (options.__testHookBeforePointerAction)616 await options.__testHookBeforePointerAction()617 progress.throwIfAborted() // Avoid action that has side-effects.618 let restoreModifiers619 if (options && options.modifiers)620 restoreModifiers = await this._page.keyboard._ensureModifiers(621 options.modifiers622 )623 progress.log(` performing ${actionName} action`)624 await action(point)625 progress.log(` ${actionName} action done`)626 progress.log(' waiting for scheduled navigations to finish')627 if (options.__testHookAfterPointerAction)628 await options.__testHookAfterPointerAction()629 if (restoreModifiers)630 await this._page.keyboard._ensureModifiers(restoreModifiers)631 },632 'input'633 )634 progress.log(' navigations have finished')635 return 'done'636 }637 async hover(metadata, options) {638 const controller = new _progress.ProgressController(metadata, this)639 return controller.run(async (progress) => {640 const result = await this._hover(progress, options)641 return assertDone(throwRetargetableDOMError(result))642 }, this._page._timeoutSettings.timeout(options))643 }644 _hover(progress, options) {645 return this._retryPointerAction(646 progress,647 'hover',648 false,649 /* waitForEnabled */650 (point) => this._page.mouse.move(point.x, point.y),651 options652 )653 }654 async click(metadata, options = {}) {655 const controller = new _progress.ProgressController(metadata, this)656 return controller.run(async (progress) => {657 const result = await this._click(progress, options)658 return assertDone(throwRetargetableDOMError(result))659 }, this._page._timeoutSettings.timeout(options))660 }661 _click(progress, options) {662 return this._retryPointerAction(663 progress,664 'click',665 true,666 /* waitForEnabled */667 (point) => this._page.mouse.click(point.x, point.y, options),668 options669 )670 }671 async dblclick(metadata, options) {672 const controller = new _progress.ProgressController(metadata, this)673 return controller.run(async (progress) => {674 const result = await this._dblclick(progress, options)675 return assertDone(throwRetargetableDOMError(result))676 }, this._page._timeoutSettings.timeout(options))677 }678 _dblclick(progress, options) {679 return this._retryPointerAction(680 progress,681 'dblclick',682 true,683 /* waitForEnabled */684 (point) => this._page.mouse.dblclick(point.x, point.y, options),685 options686 )687 }688 async tap(metadata, options = {}) {689 const controller = new _progress.ProgressController(metadata, this)690 return controller.run(async (progress) => {691 const result = await this._tap(progress, options)692 return assertDone(throwRetargetableDOMError(result))693 }, this._page._timeoutSettings.timeout(options))694 }695 _tap(progress, options) {696 return this._retryPointerAction(697 progress,698 'tap',699 true,700 /* waitForEnabled */701 (point) => this._page.touchscreen.tap(point.x, point.y),702 options703 )704 }705 async selectOption(metadata, elements, values, options) {706 const controller = new _progress.ProgressController(metadata, this)707 return controller.run(async (progress) => {708 const result = await this._selectOption(709 progress,710 elements,711 values,712 options713 )714 return throwRetargetableDOMError(result)715 }, this._page._timeoutSettings.timeout(options))716 }717 async _selectOption(progress, elements, values, options) {718 const optionsToSelect = [...elements, ...values]719 await progress.beforeInputAction(this)720 return this._page._frameManager.waitForSignalsCreatedBy(721 progress,722 options.noWaitAfter,723 async () => {724 progress.throwIfAborted() // Avoid action that has side-effects.725 progress.log(' selecting specified option(s)')726 const result = await this.evaluatePoll(727 progress,728 ([injected, node, { optionsToSelect, force }]) => {729 return injected.waitForElementStatesAndPerformAction(730 node,731 ['visible', 'enabled'],732 force,733 injected.selectOptions.bind(injected, optionsToSelect)734 )735 },736 {737 optionsToSelect,738 force: options.force739 }740 )741 await this._page._doSlowMo()742 return result743 }744 )745 }746 async fill(metadata, value, options = {}) {747 const controller = new _progress.ProgressController(metadata, this)748 return controller.run(async (progress) => {749 const result = await this._fill(progress, value, options)750 assertDone(throwRetargetableDOMError(result))751 }, this._page._timeoutSettings.timeout(options))752 }753 async _fill(progress, value, options) {754 progress.log(`elementHandle.fill("${value}")`)755 await progress.beforeInputAction(this)756 return this._page._frameManager.waitForSignalsCreatedBy(757 progress,758 options.noWaitAfter,759 async () => {760 progress.log(761 ' waiting for element to be visible, enabled and editable'762 )763 const filled = await this.evaluatePoll(764 progress,765 ([injected, node, { value, force }]) => {766 return injected.waitForElementStatesAndPerformAction(767 node,768 ['visible', 'enabled', 'editable'],769 force,770 injected.fill.bind(injected, value)771 )772 },773 {774 value,775 force: options.force776 }777 )778 progress.throwIfAborted() // Avoid action that has side-effects.779 if (filled === 'error:notconnected') return filled780 progress.log(' element is visible, enabled and editable')781 if (filled === 'needsinput') {782 progress.throwIfAborted() // Avoid action that has side-effects.783 if (value) await this._page.keyboard.insertText(value)784 else await this._page.keyboard.press('Delete')785 } else {786 assertDone(filled)787 }788 return 'done'789 },790 'input'791 )792 }793 async selectText(metadata, options = {}) {794 const controller = new _progress.ProgressController(metadata, this)795 return controller.run(async (progress) => {796 progress.throwIfAborted() // Avoid action that has side-effects.797 const result = await this.evaluatePoll(798 progress,799 ([injected, node, force]) => {800 return injected.waitForElementStatesAndPerformAction(801 node,802 ['visible'],803 force,804 injected.selectText.bind(injected)805 )806 },807 options.force808 )809 assertDone(throwRetargetableDOMError(result))810 }, this._page._timeoutSettings.timeout(options))811 }812 async setInputFiles(metadata, files, options) {813 const controller = new _progress.ProgressController(metadata, this)814 return controller.run(async (progress) => {815 const result = await this._setInputFiles(progress, files, options)816 return assertDone(throwRetargetableDOMError(result))817 }, this._page._timeoutSettings.timeout(options))818 }819 async _setInputFiles(progress, files, options) {820 for (const payload of files) {821 if (!payload.mimeType)822 payload.mimeType =823 mime.getType(payload.name) || 'application/octet-stream'824 }825 const result = await this.evaluateHandleInUtility(826 ([injected, node, multiple]) => {827 const element = injected.retarget(node, 'follow-label')828 if (!element) return829 if (element.tagName !== 'INPUT')830 throw injected.createStacklessError('Node is not an HTMLInputElement')831 if (multiple && !element.multiple)832 throw injected.createStacklessError(833 'Non-multiple file input can only accept single file'834 )835 return element836 },837 files.length > 1838 )839 if (result === 'error:notconnected' || !result.asElement())840 return 'error:notconnected'841 const retargeted = result.asElement()842 await progress.beforeInputAction(this)843 await this._page._frameManager.waitForSignalsCreatedBy(844 progress,845 options.noWaitAfter,846 async () => {847 progress.throwIfAborted() // Avoid action that has side-effects.848 await this._page._delegate.setInputFiles(retargeted, files)849 }850 )851 await this._page._doSlowMo()852 return 'done'853 }854 async focus(metadata) {855 const controller = new _progress.ProgressController(metadata, this)856 await controller.run(async (progress) => {857 const result = await this._focus(progress)858 await this._page._doSlowMo()859 return assertDone(throwRetargetableDOMError(result))860 }, 0)861 }862 async _focus(progress, resetSelectionIfNotFocused) {863 progress.throwIfAborted() // Avoid action that has side-effects.864 return await this.evaluateInUtility(865 ([injected, node, resetSelectionIfNotFocused]) =>866 injected.focusNode(node, resetSelectionIfNotFocused),867 resetSelectionIfNotFocused868 )869 }870 async type(metadata, text, options) {871 const controller = new _progress.ProgressController(metadata, this)872 return controller.run(async (progress) => {873 const result = await this._type(progress, text, options)874 return assertDone(throwRetargetableDOMError(result))875 }, this._page._timeoutSettings.timeout(options))876 }877 async _type(progress, text, options) {878 progress.log(`elementHandle.type("${text}")`)879 await progress.beforeInputAction(this)880 return this._page._frameManager.waitForSignalsCreatedBy(881 progress,882 options.noWaitAfter,883 async () => {884 const result = await this._focus(885 progress,886 true887 /* resetSelectionIfNotFocused */888 )889 if (result !== 'done') return result890 progress.throwIfAborted() // Avoid action that has side-effects.891 await this._page.keyboard.type(text, options)892 return 'done'893 },894 'input'895 )896 }897 async press(metadata, key, options) {898 const controller = new _progress.ProgressController(metadata, this)899 return controller.run(async (progress) => {900 const result = await this._press(progress, key, options)901 return assertDone(throwRetargetableDOMError(result))902 }, this._page._timeoutSettings.timeout(options))903 }904 async _press(progress, key, options) {905 progress.log(`elementHandle.press("${key}")`)906 await progress.beforeInputAction(this)907 return this._page._frameManager.waitForSignalsCreatedBy(908 progress,909 options.noWaitAfter,910 async () => {911 const result = await this._focus(912 progress,913 true914 /* resetSelectionIfNotFocused */915 )916 if (result !== 'done') return result917 progress.throwIfAborted() // Avoid action that has side-effects.918 await this._page.keyboard.press(key, options)919 return 'done'920 },921 'input'922 )923 }924 async check(metadata, options) {925 const controller = new _progress.ProgressController(metadata, this)926 return controller.run(async (progress) => {927 const result = await this._setChecked(progress, true, options)928 return assertDone(throwRetargetableDOMError(result))929 }, this._page._timeoutSettings.timeout(options))930 }931 async uncheck(metadata, options) {932 const controller = new _progress.ProgressController(metadata, this)933 return controller.run(async (progress) => {934 const result = await this._setChecked(progress, false, options)935 return assertDone(throwRetargetableDOMError(result))936 }, this._page._timeoutSettings.timeout(options))937 }938 async _setChecked(progress, state, options) {939 const isChecked = async () => {940 const result = await this.evaluateInUtility(941 ([injected, node]) => injected.elementState(node, 'checked'),942 {}943 )944 return throwRetargetableDOMError(result)945 }946 if ((await isChecked()) === state) return 'done'947 const result = await this._click(progress, options)948 if (result !== 'done') return result949 if (options.trial) return 'done'950 if ((await isChecked()) !== state)951 throw new Error('Clicking the checkbox did not change its state')952 return 'done'953 }954 async boundingBox() {955 return this._page._delegate.getBoundingBox(this)956 }957 async screenshot(metadata, options = {}) {958 const controller = new _progress.ProgressController(metadata, this)959 return controller.run(960 (progress) =>961 this._page._screenshotter.screenshotElement(progress, this, options),962 this._page._timeoutSettings.timeout(options)963 )964 }965 async querySelector(selector, options) {966 return this._page.selectors.query(967 this._context.frame,968 selector,969 options,970 this971 )972 }973 async querySelectorAll(selector) {974 return this._page.selectors._queryAll(975 this._context.frame,976 selector,977 this,978 true979 /* adoptToMain */980 )981 }982 async evalOnSelectorAndWaitForSignals(983 selector,984 strict,985 expression,986 isFunction,987 arg988 ) {989 const handle = await this._page.selectors.query(990 this._context.frame,991 selector,992 {993 strict994 },995 this996 )997 if (!handle)998 throw new Error(999 `Error: failed to find element matching selector "${selector}"`1000 )1001 const result = await handle.evaluateExpressionAndWaitForSignals(1002 expression,1003 isFunction,1004 true,1005 arg1006 )1007 handle.dispose()1008 return result1009 }1010 async evalOnSelectorAllAndWaitForSignals(1011 selector,1012 expression,1013 isFunction,1014 arg1015 ) {1016 const arrayHandle = await this._page.selectors._queryArray(1017 this._context.frame,1018 selector,1019 this1020 )1021 const result = await arrayHandle.evaluateExpressionAndWaitForSignals(1022 expression,1023 isFunction,1024 true,1025 arg1026 )1027 arrayHandle.dispose()1028 return result1029 }1030 async isVisible() {1031 const result = await this.evaluateInUtility(1032 ([injected, node]) => injected.elementState(node, 'visible'),1033 {}1034 )1035 if (result === 'error:notconnected') return false1036 return result1037 }1038 async isHidden() {1039 const result = await this.evaluateInUtility(1040 ([injected, node]) => injected.elementState(node, 'hidden'),1041 {}1042 )1043 return throwRetargetableDOMError(result)1044 }1045 async isEnabled() {1046 const result = await this.evaluateInUtility(1047 ([injected, node]) => injected.elementState(node, 'enabled'),1048 {}1049 )1050 return throwRetargetableDOMError(result)1051 }1052 async isDisabled() {1053 const result = await this.evaluateInUtility(1054 ([injected, node]) => injected.elementState(node, 'disabled'),1055 {}1056 )1057 return throwRetargetableDOMError(result)1058 }1059 async isEditable() {1060 const result = await this.evaluateInUtility(1061 ([injected, node]) => injected.elementState(node, 'editable'),1062 {}1063 )1064 return throwRetargetableDOMError(result)1065 }1066 async isChecked() {1067 const result = await this.evaluateInUtility(1068 ([injected, node]) => injected.elementState(node, 'checked'),1069 {}1070 )1071 return throwRetargetableDOMError(result)1072 }1073 async waitForElementState(metadata, state, options = {}) {1074 const controller = new _progress.ProgressController(metadata, this)1075 return controller.run(async (progress) => {1076 progress.log(` waiting for element to be ${state}`)1077 const result = await this.evaluatePoll(1078 progress,1079 ([injected, node, state]) => {1080 return injected.waitForElementStatesAndPerformAction(1081 node,1082 [state],1083 false,1084 () => 'done'1085 )1086 },1087 state1088 )1089 assertDone(throwRetargetableDOMError(result))1090 }, this._page._timeoutSettings.timeout(options))1091 }1092 async waitForSelector(metadata, selector, options = {}) {1093 const { state = 'visible' } = options1094 if (!['attached', 'detached', 'visible', 'hidden'].includes(state))1095 throw new Error(1096 `state: expected one of (attached|detached|visible|hidden)`1097 )1098 const info = this._page.parseSelector(selector, options)1099 const task = waitForSelectorTask(info, state, false, this)1100 const controller = new _progress.ProgressController(metadata, this)1101 return controller.run(async (progress) => {1102 progress.log(1103 `waiting for selector "${selector}"${1104 state === 'attached' ? '' : ' to be ' + state1105 }`1106 )1107 const context = await this._context.frame._context(info.world)1108 const injected = await context.injectedScript()1109 const pollHandler = new InjectedScriptPollHandler(1110 progress,1111 await task(injected)1112 )1113 const result = await pollHandler.finishHandle()1114 if (!result.asElement()) {1115 result.dispose()1116 return null1117 }1118 const handle = result.asElement()1119 return handle._adoptTo(await this._context.frame._mainContext())1120 }, this._page._timeoutSettings.timeout(options))1121 }1122 async _adoptTo(context) {1123 if (this._context !== context) {1124 const adopted = await this._page._delegate.adoptElementHandle(1125 this,1126 context1127 )1128 this.dispose()1129 return adopted1130 }1131 return this1132 }1133 async _waitForDisplayedAtStablePosition(progress, force, waitForEnabled) {1134 if (waitForEnabled)1135 progress.log(` waiting for element to be visible, enabled and stable`)1136 else progress.log(` waiting for element to be visible and stable`)1137 const result = await this.evaluatePoll(1138 progress,1139 ([injected, node, { waitForEnabled, force }]) => {1140 return injected.waitForElementStatesAndPerformAction(1141 node,1142 waitForEnabled1143 ? ['visible', 'stable', 'enabled']1144 : ['visible', 'stable'],1145 force,1146 () => 'done'1147 )1148 },1149 {1150 waitForEnabled,1151 force1152 }1153 )1154 if (result === 'error:notconnected') return result1155 if (waitForEnabled) progress.log(' element is visible, enabled and stable')1156 else progress.log(' element is visible and stable')1157 return result1158 }1159 async _checkHitTargetAt(point) {1160 const frame = await this.ownerFrame()1161 if (frame && frame.parentFrame()) {1162 const element = await frame.frameElement()1163 const box = await element.boundingBox()1164 if (!box) return 'error:notconnected' // Translate from viewport coordinates to frame coordinates.1165 point = {1166 x: point.x - box.x,1167 y: point.y - box.y1168 }1169 }1170 return this.evaluateInUtility(1171 ([injected, node, point]) => injected.checkHitTargetAt(node, point),1172 point1173 )1174 }1175} // Handles an InjectedScriptPoll running in injected script:1176// - streams logs into progress;1177// - cancels the poll when progress cancels.1178exports.ElementHandle = ElementHandle1179class InjectedScriptPollHandler {1180 constructor(progress, poll) {1181 this._progress = void 01182 this._poll = void 01183 this._progress = progress1184 this._poll = poll // Ensure we cancel the poll before progress aborts and returns:1185 // - no unnecessary work in the page;1186 // - no possible side effects after progress promsie rejects.1187 this._progress.cleanupWhenAborted(() => this.cancel())1188 this._streamLogs()1189 }1190 async _streamLogs() {1191 while (this._poll && this._progress.isRunning()) {1192 const log = await this._poll1193 .evaluate((poll) => poll.takeNextLogs())1194 .catch((e) => [])1195 if (!this._poll || !this._progress.isRunning()) return1196 for (const entry of log) this._progress.logEntry(entry)1197 }1198 }1199 async finishHandle() {1200 try {1201 const result = await this._poll.evaluateHandle((poll) => poll.run())1202 await this._finishInternal()1203 return result1204 } finally {1205 await this.cancel()1206 }1207 }1208 async finish() {1209 try {1210 const result = await this._poll.evaluate((poll) => poll.run())1211 await this._finishInternal()1212 return result1213 } finally {1214 await this.cancel()1215 }1216 }1217 async _finishInternal() {1218 if (!this._poll) return // Retrieve all the logs before continuing.1219 const log = await this._poll1220 .evaluate((poll) => poll.takeLastLogs())1221 .catch((e) => [])1222 for (const entry of log) this._progress.logEntry(entry)1223 }1224 async cancel() {1225 if (!this._poll) return1226 const copy = this._poll1227 this._poll = null1228 await copy.evaluate((p) => p.cancel()).catch((e) => {})1229 copy.dispose()1230 }1231}1232exports.InjectedScriptPollHandler = InjectedScriptPollHandler1233function throwRetargetableDOMError(result) {1234 if (result === 'error:notconnected')1235 throw new Error('Element is not attached to the DOM')1236 return result1237}1238function assertDone(result) {1239 // This function converts 'done' to void and ensures typescript catches unhandled errors.1240}1241function roundPoint(point) {1242 return {1243 x: ((point.x * 100) | 0) / 100,1244 y: ((point.y * 100) | 0) / 1001245 }1246}1247function compensateHalfIntegerRoundingError(point) {1248 // Firefox internally uses integer coordinates, so 8.5 is converted to 9 when clicking.1249 //1250 // This does not work nicely for small elements. For example, 1x1 square with corners1251 // (8;8) and (9;9) is targeted when clicking at (8;8) but not when clicking at (9;9).1252 // So, clicking at (8.5;8.5) will effectively click at (9;9) and miss the target.1253 //1254 // Therefore, we skew half-integer values from the interval (8.49, 8.51) towards1255 // (8.47, 8.49) that is rounded towards 8. This means clicking at (8.5;8.5) will1256 // be replaced with (8.48;8.48) and will effectively click at (8;8).1257 //1258 // Other browsers use float coordinates, so this change should not matter.1259 const remainderX = point.x - Math.floor(point.x)1260 if (remainderX > 0.49 && remainderX < 0.51) point.x -= 0.021261 const remainderY = point.y - Math.floor(point.y)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: `example.png` });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page._client.send('Emulation.setDeviceMetricsOverride', {13 });14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'google.png' });6 await browser.close();7})();8const {chromium} = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'google.png' });13 await browser.close();14})();15at Object.error (/home/ajay/Downloads/playwright-test/node_modules/playwright/lib/utils/transport.js:185:15)16at Transport._dispatchMessage (/home/ajay/Downloads/playwright-test/node_modules/playwright/lib/utils/transport.js:122:25)17at WebSocketTransport._dispatchBuffer (/home/ajay/Downloads/playwright-test/node_modules/playwright/lib/utils/transport.js:407:17)18at WebSocketTransport._onWebSocketMessage (/home/ajay/Downloads/playwright-test/node_modules/playwright/lib/utils/transport.js:358:14)19at WebSocket.onMessage (/home/ajay/Downloads/playwright-test/node_modules/ws/lib/event-target.js:120:16)20at WebSocket.emit (events.js:315:20)21at Receiver.receiverOnMessage (/home/ajay/Downloads/playwright-test/node_modules/ws/lib/websocket.js:789:20)22at Receiver.emit (events.js:315:20)23at Receiver.dataMessage (/home/ajay/Downloads/playwright-test/node_modules/ws/lib/receiver.js:422:14)24at Receiver.getData (/home/ajay/Downloads/playwright-test/node_modules/ws/lib/receiver.js:352:17)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 await context.addInitScript(() => {6 window.compensateHalfIntegerRoundingError = (x, y) => {7 return { x: Math.round(x), y: Math.round(y) };8 };9 });10 const page = await context.newPage();11 await page.screenshot({ path: 'example.png' });12 await browser.close();13})();14const puppeteer = require('puppeteer');15(async () => {16 const browser = await puppeteer.launch();17 const page = await browser.newPage();18 await page.screenshot({ path: 'example.png' });19 await browser.close();20})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');2const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');3const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');4const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');5const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');6const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');7const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');8const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');9const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');10const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');11const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');12const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');13const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');14const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');15const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils');3(async () => {4 const browser = await playwright.chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Images');8 const element = await page.$('text=Images');9 const boundingBox = await element.boundingBox();10 const {x, y, width, height} = compensateHalfIntegerRoundingError(boundingBox);11 await page.mouse.move(x + width / 2, y + height / 2);12 await page.mouse.down();13 await page.mouse.move(x + width / 2, y + height / 2 + 100);14 await page.mouse.up();15 await browser.close();16})();17[Playwright] Compensating for half-integer rounding error in bounding box: {"x":0,"y":0,"width":0.5,"height":0.5}18[Playwright] Compensating for half-integer rounding error in bounding box: {"x":0,"y":0,"width":0.5,"height":0.5}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {compensateHalfIntegerRoundingError} from 'playwright';2const {x, y} = compensateHalfIntegerRoundingError(50.5, 50.5);3console.log(x, y);4const {x, y} = compensateHalfIntegerRoundingError(50.4, 50.4);5console.log(x, y);6const {x, y} = compensateHalfIntegerRoundingError(50.1, 50.1);7console.log(x, y);8const {x, y} = compensateHalfIntegerRoundingError(50.6, 50.6);9console.log(x, y);10const {x, y} = compensateHalfIntegerRoundingError(50.9, 50.9);11console.log(x, y);12const {x, y} = compensateHalfIntegerRoundingError(0.5, 0.5);13console.log(x, y);14const {x, y} = compensateHalfIntegerRoundingError(0.4, 0.4);15console.log(x, y);16const {x, y} = compensateHalfIntegerRoundingError(0.1, 0.1);17console.log(x, y);18const {x, y} = compensateHalfIntegerRoundingError(0.6, 0.6);19console.log(x, y);20const {x, y} = compensateHalfIntegerRoundingError(0.9, 0.9);21console.log(x, y);22const {x, y} = compensateHalfIntegerRoundingError(-0.5, -0.5);23console.log(x, y);24const {x, y} = compensateHalfIntegerRoundingError(-0.4, -0.4);25console.log(x, y);

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright-chromium');2const path = require('path');3const fs = require('fs');4const {compensateHalfIntegerRoundingError} = require('playwright-core/lib/server/supplements/recorder/recorderSupplement.js');5(async () => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 const element = await page.$('input[name="q"]');10 const boundingBox = await element.boundingBox();11 const {x, y} = compensateHalfIntegerRoundingError(boundingBox);12 await page.mouse.move(x, y);13 await page.mouse.down();14 await page.mouse.up();15 await browser.close();16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');2const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');3const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');4const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');5const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');6const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');7const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');8const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');9const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');10const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');11const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');12const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');13const {compensateHalfIntegerRoundingError} = require('playwright/lib/utils/math');14const {compensateHalfIntegerRoundingError} = require('playwright

Full Screen

Using AI Code Generation

copy

Full Screen

1const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');2const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');3const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');4const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');5const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');6const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');7const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');8const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');9const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');10const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');11const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal/utils');12const { compensateHalfIntegerRoundingError } = require('playwright/lib/internal

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful