How to use assertDone method in Playwright Internal

Best JavaScript code snippet using playwright-internal

dom.js

Source:dom.js Github

copy

Full Screen

...238 return await this._page._delegate.scrollRectIntoViewIfNeeded(this, rect);239 }240 async _waitAndScrollIntoViewIfNeeded(progress) {241 while (progress.isRunning()) {242 assertDone(throwRetargetableDOMError(await this._waitForDisplayedAtStablePosition(progress, false243 /* force */244 , false245 /* waitForEnabled */246 )));247 progress.throwIfAborted(); // Avoid action that has side-effects.248 const result = throwRetargetableDOMError(await this._scrollRectIntoViewIfNeeded());249 if (result === 'error:notvisible') continue;250 assertDone(result);251 return;252 }253 }254 async scrollIntoViewIfNeeded(metadata, options = {}) {255 const controller = new _progress.ProgressController(metadata, this);256 return controller.run(progress => this._waitAndScrollIntoViewIfNeeded(progress), this._page._timeoutSettings.timeout(options));257 }258 async _clickablePoint() {259 const intersectQuadWithViewport = quad => {260 return quad.map(point => ({261 x: Math.min(Math.max(point.x, 0), metrics.width),262 y: Math.min(Math.max(point.y, 0), metrics.height)263 }));264 };265 const computeQuadArea = quad => {266 // Compute sum of all directed areas of adjacent triangles267 // https://en.wikipedia.org/wiki/Polygon#Simple_polygons268 let area = 0;269 for (let i = 0; i < quad.length; ++i) {270 const p1 = quad[i];271 const p2 = quad[(i + 1) % quad.length];272 area += (p1.x * p2.y - p2.x * p1.y) / 2;273 }274 return Math.abs(area);275 };276 const [quads, metrics] = await Promise.all([this._page._delegate.getContentQuads(this), this._page.mainFrame()._utilityContext().then(utility => utility.evaluate(() => ({277 width: innerWidth,278 height: innerHeight279 })))]);280 if (!quads || !quads.length) return 'error:notvisible'; // Allow 1x1 elements. Compensate for rounding errors by comparing with 0.99 instead.281 const filtered = quads.map(quad => intersectQuadWithViewport(quad)).filter(quad => computeQuadArea(quad) > 0.99);282 if (!filtered.length) return 'error:notinviewport'; // Return the middle point of the first quad.283 const result = {284 x: 0,285 y: 0286 };287 for (const point of filtered[0]) {288 result.x += point.x / 4;289 result.y += point.y / 4;290 }291 compensateHalfIntegerRoundingError(result);292 return result;293 }294 async _offsetPoint(offset) {295 const [box, border] = await Promise.all([this.boundingBox(), this.evaluateInUtility(([injected, node]) => injected.getElementBorderWidth(node), {}).catch(e => {})]);296 if (!box || !border) return 'error:notvisible';297 if (border === 'error:notconnected') return border; // Make point relative to the padding box to align with offsetX/offsetY.298 return {299 x: box.x + border.left + offset.x,300 y: box.y + border.top + offset.y301 };302 }303 async _retryPointerAction(progress, actionName, waitForEnabled, action, options) {304 let retry = 0; // We progressively wait longer between retries, up to 500ms.305 const waitTime = [0, 20, 100, 100, 500]; // By default, we scroll with protocol method to reveal the action point.306 // However, that might not work to scroll from under position:sticky elements307 // that overlay the target element. To fight this, we cycle through different308 // scroll alignments. This works in most scenarios.309 const scrollOptions = [undefined, {310 block: 'end',311 inline: 'end'312 }, {313 block: 'center',314 inline: 'center'315 }, {316 block: 'start',317 inline: 'start'318 }];319 while (progress.isRunning()) {320 if (retry) {321 progress.log(`retrying ${actionName} action${options.trial ? ' (trial run)' : ''}, attempt #${retry}`);322 const timeout = waitTime[Math.min(retry - 1, waitTime.length - 1)];323 if (timeout) {324 progress.log(` waiting ${timeout}ms`);325 const result = await this.evaluateInUtility(([injected, node, timeout]) => new Promise(f => setTimeout(f, timeout)), timeout);326 if (result === 'error:notconnected') return result;327 }328 } else {329 progress.log(`attempting ${actionName} action${options.trial ? ' (trial run)' : ''}`);330 }331 const forceScrollOptions = scrollOptions[retry % scrollOptions.length];332 const result = await this._performPointerAction(progress, actionName, waitForEnabled, action, forceScrollOptions, options);333 ++retry;334 if (result === 'error:notvisible') {335 if (options.force) throw new NonRecoverableDOMError('Element is not visible');336 progress.log(' element is not visible');337 continue;338 }339 if (result === 'error:notinviewport') {340 if (options.force) throw new NonRecoverableDOMError('Element is outside of the viewport');341 progress.log(' element is outside of the viewport');342 continue;343 }344 if (typeof result === 'object' && 'hitTargetDescription' in result) {345 progress.log(` ${result.hitTargetDescription} intercepts pointer events`);346 continue;347 }348 return result;349 }350 return 'done';351 }352 async _performPointerAction(progress, actionName, waitForEnabled, action, forceScrollOptions, options) {353 const {354 force = false,355 position356 } = options;357 if (options.__testHookBeforeStable) await options.__testHookBeforeStable();358 const result = await this._waitForDisplayedAtStablePosition(progress, force, waitForEnabled);359 if (result !== 'done') return result;360 if (options.__testHookAfterStable) await options.__testHookAfterStable();361 progress.log(' scrolling into view if needed');362 progress.throwIfAborted(); // Avoid action that has side-effects.363 if (forceScrollOptions) {364 const scrolled = await this.evaluateInUtility(([injected, node, options]) => {365 if (node.nodeType === 1366 /* Node.ELEMENT_NODE */367 ) node.scrollIntoView(options);368 }, forceScrollOptions);369 if (scrolled === 'error:notconnected') return scrolled;370 } else {371 const scrolled = await this._scrollRectIntoViewIfNeeded(position ? {372 x: position.x,373 y: position.y,374 width: 0,375 height: 0376 } : undefined);377 if (scrolled !== 'done') return scrolled;378 }379 progress.log(' done scrolling');380 const maybePoint = position ? await this._offsetPoint(position) : await this._clickablePoint();381 if (typeof maybePoint === 'string') return maybePoint;382 const point = roundPoint(maybePoint);383 progress.metadata.point = point;384 if (process.env.PLAYWRIGHT_NO_LAYOUT_SHIFT_CHECK) return this._finishPointerAction(progress, actionName, point, options, action);else return this._finishPointerActionDetectLayoutShift(progress, actionName, point, options, action);385 }386 async _finishPointerAction(progress, actionName, point, options, action) {387 if (!options.force) {388 if (options.__testHookBeforeHitTarget) await options.__testHookBeforeHitTarget();389 progress.log(` checking that element receives pointer events at (${point.x},${point.y})`);390 const hitTargetResult = await this._checkHitTargetAt(point);391 if (hitTargetResult !== 'done') return hitTargetResult;392 progress.log(` element does receive pointer events`);393 }394 if (options.trial) {395 progress.log(` trial ${actionName} has finished`);396 return 'done';397 }398 await progress.beforeInputAction(this);399 await this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {400 if (options.__testHookBeforePointerAction) await options.__testHookBeforePointerAction();401 progress.throwIfAborted(); // Avoid action that has side-effects.402 let restoreModifiers;403 if (options && options.modifiers) restoreModifiers = await this._page.keyboard._ensureModifiers(options.modifiers);404 progress.log(` performing ${actionName} action`);405 await action(point);406 progress.log(` ${actionName} action done`);407 progress.log(' waiting for scheduled navigations to finish');408 if (options.__testHookAfterPointerAction) await options.__testHookAfterPointerAction();409 if (restoreModifiers) await this._page.keyboard._ensureModifiers(restoreModifiers);410 }, 'input');411 progress.log(' navigations have finished');412 return 'done';413 }414 async _finishPointerActionDetectLayoutShift(progress, actionName, point, options, action) {415 await progress.beforeInputAction(this);416 let hitTargetInterceptionHandle;417 if (!options.force) {418 if (options.__testHookBeforeHitTarget) await options.__testHookBeforeHitTarget();419 if (actionName === 'move and up') {420 // When dropping, the "element that is being dragged" often stays under the cursor,421 // so hit target check at the moment we receive mousedown does not work -422 // it finds the "element that is being dragged" instead of the423 // "element that we drop onto".424 progress.log(` checking that element receives pointer events at (${point.x},${point.y})`);425 const hitTargetResult = await this._checkHitTargetAt(point);426 if (hitTargetResult !== 'done') return hitTargetResult;427 progress.log(` element does receive pointer events`);428 if (options.trial) {429 progress.log(` trial ${actionName} has finished`);430 return 'done';431 }432 } else {433 const actionType = actionName === 'hover' || actionName === 'tap' ? actionName : 'mouse';434 const handle = await this.evaluateHandleInUtility(([injected, node, {435 actionType,436 trial437 }]) => injected.setupHitTargetInterceptor(node, actionType, trial), {438 actionType,439 trial: !!options.trial440 });441 if (handle === 'error:notconnected') return handle;442 if (!handle._objectId) return handle.rawValue();443 hitTargetInterceptionHandle = handle;444 progress.cleanupWhenAborted(() => {445 // Do not await here, just in case the renderer is stuck (e.g. on alert)446 // and we won't be able to cleanup.447 hitTargetInterceptionHandle.evaluate(h => h.stop()).catch(e => {});448 });449 }450 }451 const actionResult = await this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {452 if (options.__testHookBeforePointerAction) await options.__testHookBeforePointerAction();453 progress.throwIfAborted(); // Avoid action that has side-effects.454 let restoreModifiers;455 if (options && options.modifiers) restoreModifiers = await this._page.keyboard._ensureModifiers(options.modifiers);456 progress.log(` performing ${actionName} action`);457 await action(point);458 if (restoreModifiers) await this._page.keyboard._ensureModifiers(restoreModifiers);459 if (hitTargetInterceptionHandle) {460 const stopHitTargetInterception = hitTargetInterceptionHandle.evaluate(h => h.stop()).catch(e => 'done');461 if (!options.noWaitAfter) {462 // When noWaitAfter is passed, we do not want to accidentally stall on463 // non-committed navigation blocking the evaluate.464 const hitTargetResult = await stopHitTargetInterception;465 if (hitTargetResult !== 'done') return hitTargetResult;466 }467 }468 progress.log(` ${options.trial ? 'trial ' : ''}${actionName} action done`);469 progress.log(' waiting for scheduled navigations to finish');470 if (options.__testHookAfterPointerAction) await options.__testHookAfterPointerAction();471 return 'done';472 }, 'input');473 if (actionResult !== 'done') return actionResult;474 progress.log(' navigations have finished');475 return 'done';476 }477 async hover(metadata, options) {478 const controller = new _progress.ProgressController(metadata, this);479 return controller.run(async progress => {480 const result = await this._hover(progress, options);481 return assertDone(throwRetargetableDOMError(result));482 }, this._page._timeoutSettings.timeout(options));483 }484 _hover(progress, options) {485 return this._retryPointerAction(progress, 'hover', false486 /* waitForEnabled */487 , point => this._page.mouse.move(point.x, point.y), options);488 }489 async click(metadata, options = {}) {490 const controller = new _progress.ProgressController(metadata, this);491 return controller.run(async progress => {492 const result = await this._click(progress, options);493 return assertDone(throwRetargetableDOMError(result));494 }, this._page._timeoutSettings.timeout(options));495 }496 _click(progress, options) {497 return this._retryPointerAction(progress, 'click', true498 /* waitForEnabled */499 , point => this._page.mouse.click(point.x, point.y, options), options);500 }501 async dblclick(metadata, options) {502 const controller = new _progress.ProgressController(metadata, this);503 return controller.run(async progress => {504 const result = await this._dblclick(progress, options);505 return assertDone(throwRetargetableDOMError(result));506 }, this._page._timeoutSettings.timeout(options));507 }508 _dblclick(progress, options) {509 return this._retryPointerAction(progress, 'dblclick', true510 /* waitForEnabled */511 , point => this._page.mouse.dblclick(point.x, point.y, options), options);512 }513 async tap(metadata, options = {}) {514 const controller = new _progress.ProgressController(metadata, this);515 return controller.run(async progress => {516 const result = await this._tap(progress, options);517 return assertDone(throwRetargetableDOMError(result));518 }, this._page._timeoutSettings.timeout(options));519 }520 _tap(progress, options) {521 return this._retryPointerAction(progress, 'tap', true522 /* waitForEnabled */523 , point => this._page.touchscreen.tap(point.x, point.y), options);524 }525 async selectOption(metadata, elements, values, options) {526 const controller = new _progress.ProgressController(metadata, this);527 return controller.run(async progress => {528 const result = await this._selectOption(progress, elements, values, options);529 return throwRetargetableDOMError(result);530 }, this._page._timeoutSettings.timeout(options));531 }532 async _selectOption(progress, elements, values, options) {533 const optionsToSelect = [...elements, ...values];534 await progress.beforeInputAction(this);535 return this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {536 progress.throwIfAborted(); // Avoid action that has side-effects.537 progress.log(' selecting specified option(s)');538 const result = await this.evaluatePoll(progress, ([injected, node, {539 optionsToSelect,540 force541 }]) => {542 return injected.waitForElementStatesAndPerformAction(node, ['visible', 'enabled'], force, injected.selectOptions.bind(injected, optionsToSelect));543 }, {544 optionsToSelect,545 force: options.force546 });547 await this._page._doSlowMo();548 return result;549 });550 }551 async fill(metadata, value, options = {}) {552 const controller = new _progress.ProgressController(metadata, this);553 return controller.run(async progress => {554 const result = await this._fill(progress, value, options);555 assertDone(throwRetargetableDOMError(result));556 }, this._page._timeoutSettings.timeout(options));557 }558 async _fill(progress, value, options) {559 progress.log(`elementHandle.fill("${value}")`);560 await progress.beforeInputAction(this);561 return this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {562 progress.log(' waiting for element to be visible, enabled and editable');563 const filled = await this.evaluatePoll(progress, ([injected, node, {564 value,565 force566 }]) => {567 return injected.waitForElementStatesAndPerformAction(node, ['visible', 'enabled', 'editable'], force, injected.fill.bind(injected, value));568 }, {569 value,570 force: options.force571 });572 progress.throwIfAborted(); // Avoid action that has side-effects.573 if (filled === 'error:notconnected') return filled;574 progress.log(' element is visible, enabled and editable');575 if (filled === 'needsinput') {576 progress.throwIfAborted(); // Avoid action that has side-effects.577 if (value) await this._page.keyboard.insertText(value);else await this._page.keyboard.press('Delete');578 } else {579 assertDone(filled);580 }581 return 'done';582 }, 'input');583 }584 async selectText(metadata, options = {}) {585 const controller = new _progress.ProgressController(metadata, this);586 return controller.run(async progress => {587 progress.throwIfAborted(); // Avoid action that has side-effects.588 const result = await this.evaluatePoll(progress, ([injected, node, force]) => {589 return injected.waitForElementStatesAndPerformAction(node, ['visible'], force, injected.selectText.bind(injected));590 }, options.force);591 assertDone(throwRetargetableDOMError(result));592 }, this._page._timeoutSettings.timeout(options));593 }594 async setInputFiles(metadata, files, options) {595 const controller = new _progress.ProgressController(metadata, this);596 return controller.run(async progress => {597 const result = await this._setInputFiles(progress, files, options);598 return assertDone(throwRetargetableDOMError(result));599 }, this._page._timeoutSettings.timeout(options));600 }601 async _setInputFiles(progress, files, options) {602 for (const payload of files) {603 if (!payload.mimeType) payload.mimeType = mime.getType(payload.name) || 'application/octet-stream';604 }605 const result = await this.evaluateHandleInUtility(([injected, node, multiple]) => {606 const element = injected.retarget(node, 'follow-label');607 if (!element) return;608 if (element.tagName !== 'INPUT') throw injected.createStacklessError('Node is not an HTMLInputElement');609 if (multiple && !element.multiple) throw injected.createStacklessError('Non-multiple file input can only accept single file');610 return element;611 }, files.length > 1);612 if (result === 'error:notconnected' || !result.asElement()) return 'error:notconnected';613 const retargeted = result.asElement();614 await progress.beforeInputAction(this);615 await this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {616 progress.throwIfAborted(); // Avoid action that has side-effects.617 await this._page._delegate.setInputFiles(retargeted, files);618 });619 await this._page._doSlowMo();620 return 'done';621 }622 async focus(metadata) {623 const controller = new _progress.ProgressController(metadata, this);624 await controller.run(async progress => {625 const result = await this._focus(progress);626 await this._page._doSlowMo();627 return assertDone(throwRetargetableDOMError(result));628 }, 0);629 }630 async _focus(progress, resetSelectionIfNotFocused) {631 progress.throwIfAborted(); // Avoid action that has side-effects.632 return await this.evaluateInUtility(([injected, node, resetSelectionIfNotFocused]) => injected.focusNode(node, resetSelectionIfNotFocused), resetSelectionIfNotFocused);633 }634 async type(metadata, text, options) {635 const controller = new _progress.ProgressController(metadata, this);636 return controller.run(async progress => {637 const result = await this._type(progress, text, options);638 return assertDone(throwRetargetableDOMError(result));639 }, this._page._timeoutSettings.timeout(options));640 }641 async _type(progress, text, options) {642 progress.log(`elementHandle.type("${text}")`);643 await progress.beforeInputAction(this);644 return this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {645 const result = await this._focus(progress, true646 /* resetSelectionIfNotFocused */647 );648 if (result !== 'done') return result;649 progress.throwIfAborted(); // Avoid action that has side-effects.650 await this._page.keyboard.type(text, options);651 return 'done';652 }, 'input');653 }654 async press(metadata, key, options) {655 const controller = new _progress.ProgressController(metadata, this);656 return controller.run(async progress => {657 const result = await this._press(progress, key, options);658 return assertDone(throwRetargetableDOMError(result));659 }, this._page._timeoutSettings.timeout(options));660 }661 async _press(progress, key, options) {662 progress.log(`elementHandle.press("${key}")`);663 await progress.beforeInputAction(this);664 return this._page._frameManager.waitForSignalsCreatedBy(progress, options.noWaitAfter, async () => {665 const result = await this._focus(progress, true666 /* resetSelectionIfNotFocused */667 );668 if (result !== 'done') return result;669 progress.throwIfAborted(); // Avoid action that has side-effects.670 await this._page.keyboard.press(key, options);671 return 'done';672 }, 'input');673 }674 async check(metadata, options) {675 const controller = new _progress.ProgressController(metadata, this);676 return controller.run(async progress => {677 const result = await this._setChecked(progress, true, options);678 return assertDone(throwRetargetableDOMError(result));679 }, this._page._timeoutSettings.timeout(options));680 }681 async uncheck(metadata, options) {682 const controller = new _progress.ProgressController(metadata, this);683 return controller.run(async progress => {684 const result = await this._setChecked(progress, false, options);685 return assertDone(throwRetargetableDOMError(result));686 }, this._page._timeoutSettings.timeout(options));687 }688 async _setChecked(progress, state, options) {689 const isChecked = async () => {690 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'checked'), {});691 return throwRetargetableDOMError(result);692 };693 if ((await isChecked()) === state) return 'done';694 const result = await this._click(progress, options);695 if (result !== 'done') return result;696 if (options.trial) return 'done';697 if ((await isChecked()) !== state) throw new NonRecoverableDOMError('Clicking the checkbox did not change its state');698 return 'done';699 }700 async boundingBox() {701 return this._page._delegate.getBoundingBox(this);702 }703 async screenshot(metadata, options = {}) {704 const controller = new _progress.ProgressController(metadata, this);705 return controller.run(progress => this._page._screenshotter.screenshotElement(progress, this, options), this._page._timeoutSettings.timeout(options));706 }707 async querySelector(selector, options) {708 const pair = await this._frame.resolveFrameForSelectorNoWait(selector, options, this);709 if (!pair) return null;710 const {711 frame,712 info713 } = pair; // If we end up in the same frame => use the scope again, line above was noop.714 return this._page.selectors.query(frame, info, this._frame === frame ? this : undefined);715 }716 async querySelectorAll(selector) {717 const pair = await this._frame.resolveFrameForSelectorNoWait(selector, {}, this);718 if (!pair) return [];719 const {720 frame,721 info722 } = pair; // If we end up in the same frame => use the scope again, line above was noop.723 return this._page.selectors._queryAll(frame, info, this._frame === frame ? this : undefined, true724 /* adoptToMain */725 );726 }727 async evalOnSelectorAndWaitForSignals(selector, strict, expression, isFunction, arg) {728 const pair = await this._frame.resolveFrameForSelectorNoWait(selector, {729 strict730 }, this); // If we end up in the same frame => use the scope again, line above was noop.731 const handle = pair ? await this._page.selectors.query(pair.frame, pair.info, this._frame === pair.frame ? this : undefined) : null;732 if (!handle) throw new Error(`Error: failed to find element matching selector "${selector}"`);733 const result = await handle.evaluateExpressionAndWaitForSignals(expression, isFunction, true, arg);734 handle.dispose();735 return result;736 }737 async evalOnSelectorAllAndWaitForSignals(selector, expression, isFunction, arg) {738 const pair = await this._frame.resolveFrameForSelectorNoWait(selector, {}, this);739 if (!pair) throw new Error(`Error: failed to find frame for selector "${selector}"`);740 const {741 frame,742 info743 } = pair; // If we end up in the same frame => use the scope again, line above was noop.744 const arrayHandle = await this._page.selectors._queryArrayInMainWorld(frame, info, this._frame === frame ? this : undefined);745 const result = await arrayHandle.evaluateExpressionAndWaitForSignals(expression, isFunction, true, arg);746 arrayHandle.dispose();747 return result;748 }749 async isVisible() {750 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'visible'), {});751 if (result === 'error:notconnected') return false;752 return result;753 }754 async isHidden() {755 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'hidden'), {});756 return throwRetargetableDOMError(result);757 }758 async isEnabled() {759 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'enabled'), {});760 return throwRetargetableDOMError(result);761 }762 async isDisabled() {763 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'disabled'), {});764 return throwRetargetableDOMError(result);765 }766 async isEditable() {767 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'editable'), {});768 return throwRetargetableDOMError(result);769 }770 async isChecked() {771 const result = await this.evaluateInUtility(([injected, node]) => injected.elementState(node, 'checked'), {});772 return throwRetargetableDOMError(result);773 }774 async waitForElementState(metadata, state, options = {}) {775 const controller = new _progress.ProgressController(metadata, this);776 return controller.run(async progress => {777 progress.log(` waiting for element to be ${state}`);778 const result = await this.evaluatePoll(progress, ([injected, node, state]) => {779 return injected.waitForElementStatesAndPerformAction(node, [state], false, () => 'done');780 }, state);781 assertDone(throwRetargetableDOMError(result));782 }, this._page._timeoutSettings.timeout(options));783 }784 async waitForSelector(metadata, selector, options = {}) {785 return this._frame.waitForSelector(metadata, selector, options, this);786 }787 async _adoptTo(context) {788 if (this._context !== context) {789 const adopted = await this._page._delegate.adoptElementHandle(this, context);790 this.dispose();791 return adopted;792 }793 return this;794 }795 async _waitForDisplayedAtStablePosition(progress, force, waitForEnabled) {796 if (waitForEnabled) progress.log(` waiting for element to be visible, enabled and stable`);else progress.log(` waiting for element to be visible and stable`);797 const result = await this.evaluatePoll(progress, ([injected, node, {798 waitForEnabled,799 force800 }]) => {801 return injected.waitForElementStatesAndPerformAction(node, waitForEnabled ? ['visible', 'stable', 'enabled'] : ['visible', 'stable'], force, () => 'done');802 }, {803 waitForEnabled,804 force805 });806 if (result === 'error:notconnected') return result;807 if (waitForEnabled) progress.log(' element is visible, enabled and stable');else progress.log(' element is visible and stable');808 return result;809 }810 async _checkHitTargetAt(point) {811 const frame = await this.ownerFrame();812 if (frame && frame.parentFrame()) {813 const element = await frame.frameElement();814 const box = await element.boundingBox();815 if (!box) return 'error:notconnected'; // Translate from viewport coordinates to frame coordinates.816 point = {817 x: point.x - box.x,818 y: point.y - box.y819 };820 }821 return this.evaluateInUtility(([injected, node, point]) => injected.checkHitTargetAt(node, point), point);822 }823} // Handles an InjectedScriptPoll running in injected script:824// - streams logs into progress;825// - cancels the poll when progress cancels.826exports.ElementHandle = ElementHandle;827class InjectedScriptPollHandler {828 constructor(progress, poll) {829 this._progress = void 0;830 this._poll = void 0;831 this._progress = progress;832 this._poll = poll; // Ensure we cancel the poll before progress aborts and returns:833 // - no unnecessary work in the page;834 // - no possible side effects after progress promsie rejects.835 this._progress.cleanupWhenAborted(() => this.cancel());836 this._streamLogs();837 }838 async _streamLogs() {839 while (this._poll && this._progress.isRunning()) {840 const log = await this._poll.evaluate(poll => poll.takeNextLogs()).catch(e => []);841 if (!this._poll || !this._progress.isRunning()) return;842 for (const entry of log) this._progress.logEntry(entry);843 }844 }845 async finishHandle() {846 try {847 const result = await this._poll.evaluateHandle(poll => poll.run());848 await this._finishInternal();849 return result;850 } finally {851 await this.cancel();852 }853 }854 async finish() {855 try {856 const result = await this._poll.evaluate(poll => poll.run());857 await this._finishInternal();858 return result;859 } finally {860 await this.cancel();861 }862 }863 async _finishInternal() {864 if (!this._poll) return; // Retrieve all the logs before continuing.865 const log = await this._poll.evaluate(poll => poll.takeLastLogs()).catch(e => []);866 for (const entry of log) this._progress.logEntry(entry);867 }868 async cancel() {869 if (!this._poll) return;870 const copy = this._poll;871 this._poll = null;872 await copy.evaluate(p => p.cancel()).catch(e => {});873 copy.dispose();874 }875}876exports.InjectedScriptPollHandler = InjectedScriptPollHandler;877function throwRetargetableDOMError(result) {878 if (result === 'error:notconnected') throw new Error('Element is not attached to the DOM');879 return result;880}881function assertDone(result) {// This function converts 'done' to void and ensures typescript catches unhandled errors.882}883function roundPoint(point) {884 return {885 x: (point.x * 100 | 0) / 100,886 y: (point.y * 100 | 0) / 100887 };888}889function compensateHalfIntegerRoundingError(point) {890 // Firefox internally uses integer coordinates, so 8.5 is converted to 9 when clicking.891 //892 // This does not work nicely for small elements. For example, 1x1 square with corners893 // (8;8) and (9;9) is targeted when clicking at (8;8) but not when clicking at (9;9).894 // So, clicking at (8.5;8.5) will effectively click at (9;9) and miss the target.895 //...

Full Screen

Full Screen

AvailabilityIterator.test.js

Source:AvailabilityIterator.test.js Github

copy

Full Screen

...53 }),54 cal: cal55 });56 tester.assertLastStatus(Status.STATUS_AVAILABLE);57 tester.assertDone();58 });59 it ('treats null availability as empty availability', () => {60 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);61 let yesterday = cal.clone();62 advancer.advance(yesterday, 'day', -1);63 const tester = new StatusIteratorTester({64 it: new AvailabilityIterator({65 availability: null,66 cal: cal67 }),68 cal: cal69 });70 tester.assertLastStatus(Status.STATUS_AVAILABLE);71 tester.assertDone();72 });73 it ('returns a single status for a full weekly schedule with a redundant exception', () => {74 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);75 let yesterday = cal.clone();76 advancer.advance(yesterday, 'day', -1);77 let tester = createTester({78 cal: yesterday,79 weekly: [80 {81 minuteOfWeek: WeeklyTimeWindow.SUNDAY,82 durationMins: WeeklyTimeWindow.WEEK83 }84 ],85 exceptions: [86 when(cal, 'day', 1, true)87 ]88 });89 tester.assertLastStatus(Status.STATUS_AVAILABLE);90 tester.assertDone();91 });92 it ('returns 3 statuses for a full weekly schedule with a non-redundant exception with an end date', () => {93 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);94 let yesterday = cal.clone();95 advancer.advance(yesterday, 'day', -1);96 let tester = createTester({97 cal: yesterday,98 weekly: [99 {100 minuteOfWeek: WeeklyTimeWindow.SUNDAY,101 durationMins: WeeklyTimeWindow.WEEK102 }103 ],104 exceptions: [105 when(cal, 'day', 1, false)106 ]107 });108 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);109 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);110 tester.assertLastStatus(Status.STATUS_AVAILABLE);111 tester.assertDone();112 });113 it ('returns a series of statuses for a complex weekly schedule with an exception', () => {114 let cal1 = moment.tz([2010, 12-1, 10, 0, 0, 0, 0], tz);115 let cal2 = moment.tz([2010, 12-1, 14, 12, 0, 0, 0], tz);116 let tester = createTester({117 cal: cal1,118 weekly: [119 {120 minuteOfWeek: WeeklyTimeWindow.SUNDAY,121 durationMins: WeeklyTimeWindow.DAY122 },123 {124 minuteOfWeek: WeeklyTimeWindow.TUESDAY,125 durationMins: 2 * WeeklyTimeWindow.DAY126 }127 ],128 exceptions: [129 when(cal2, 'hour', 12, false)130 ]131 });132 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 2);133 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);134 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);135 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'hour', 12);136 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'hour', 12);137 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);138 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 3);139 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);140 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);141 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 2);142 });143 it ('returns a single status for a full weekly schedule with an exception "until forever"', () => {144 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);145 let ex = when(cal, 'day', 1, false);146 ex.end = null;147 let tester = createTester({148 cal: cal,149 weekly: null,150 exceptions: [ex]151 });152 tester.assertLastStatus(Status.STATUS_UNAVAILABLE);153 tester.assertDone();154 });155 it ('returns a single status for a partial weekly schedule with an exception "until forever"', () => {156 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);157 let ex = when(cal, 'day', 1, false);158 ex.end = null;159 let tester = createTester({160 cal: cal,161 weekly: [162 {163 minuteOfWeek: WeeklyTimeWindow.SUNDAY,164 durationMins: WeeklyTimeWindow.DAY165 }166 ],167 exceptions: [ex]168 });169 tester.assertLastStatus(Status.STATUS_UNAVAILABLE);170 tester.assertDone();171 });172 it ('supports overlapping exceptions by following the "last one wins" rule', () => {173 const yesterday = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);174 const today = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);175 const tomorrow = moment.tz([2010, 12-1, 14, 0, 0, 0, 0], tz);176 const tester = createTester({177 cal: yesterday,178 weekly: [179 {180 minuteOfWeek: WeeklyTimeWindow.SUNDAY,181 durationMins: WeeklyTimeWindow.WEEK182 }183 ],184 exceptions: [185 when(today, 'day', 2, false),186 when(tomorrow, 'day', 1, true)187 ]188 });189 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);190 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);191 tester.assertLastStatus(Status.STATUS_AVAILABLE);192 tester.assertDone();193 });194 it('handles daylight saving times correctly', () => {195 const today = moment.tz([2017, 3-1, 19, 0, 0, 0, 0], tz);196 const tester = new AvailabilityIterator({197 availability: {198 weekly: [{199 minuteOfWeek: WeeklyTimeWindow.SUNDAY + (5 * 60),200 durationMins: WeeklyTimeWindow.HOUR201 }],202 exceptions: []203 },204 cal: today205 });206 let next = tester.next();...

Full Screen

Full Screen

toast.js

Source:toast.js Github

copy

Full Screen

...215 var $toast = $(toastHtml)216 .bootstrapToast()217 .appendTo($('#qunit-fixture'))218 var shownCalled = false219 function assertDone() {220 setTimeout(function () {221 assert.strictEqual(shownCalled, false)222 done()223 }, 20)224 }225 $toast226 .on('show.bs.toast', function (event) {227 event.preventDefault()228 assertDone()229 })230 .on('shown.bs.toast', function () {231 shownCalled = true232 })233 .bootstrapToast('show')234 })235 QUnit.test('should not trigger hidden if hide is prevented', function (assert) {236 assert.expect(1)237 var done = assert.async()238 var toastHtml =239 '<div class="toast" data-delay="1" data-autohide="false">' +240 '<div class="toast-body">' +241 'a simple toast' +242 '</div>' +243 '</div>'244 var $toast = $(toastHtml)245 .bootstrapToast()246 .appendTo($('#qunit-fixture'))247 var hiddenCalled = false248 function assertDone() {249 setTimeout(function () {250 assert.strictEqual(hiddenCalled, false)251 done()252 }, 20)253 }254 $toast255 .on('shown.bs.toast', function () {256 $toast.bootstrapToast('hide')257 })258 .on('hide.bs.toast', function (event) {259 event.preventDefault()260 assertDone()261 })262 .on('hidden.bs.toast', function () {263 hiddenCalled = true264 })265 .bootstrapToast('show')266 })...

Full Screen

Full Screen

DateTimeWindowsIterator.test.js

Source:DateTimeWindowsIterator.test.js Github

copy

Full Screen

...42 cal: cal,43 timeWindows: null44 });45 tester.assertLastStatus(Status.STATUS_UNKNOWN);46 tester.assertDone();47 });48 it ('returns a single unknown status when given no time windows', () => {49 let cal = moment.tz([2010, 12-1, 15, 0, 0, 0, 0], tz);50 let tester = createTester({51 cal: cal,52 timeWindows: []53 });54 tester.assertLastStatus(Status.STATUS_UNKNOWN);55 tester.assertDone();56 });57 it ('returns two statuses when given a single "since forever" window and pointed in it', () => {58 let cal = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);59 let window = when(cal, 'day', 1, true);60 window.start = null;61 let tester = createTester({62 cal: cal,63 timeWindows: [ window ]64 });65 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);66 tester.assertLastStatus(Status.STATUS_UNKNOWN);67 tester.assertDone();68 });69 it ('returns a single status when given a single "until forever" window and pointed to it', () => {70 let cal = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);71 let window = when(cal, 'day', 1, true);72 window.end = null;73 let tester = createTester({74 cal: cal,75 timeWindows: [ window ]76 });77 tester.assertLastStatus(Status.STATUS_AVAILABLE);78 tester.assertDone();79 });80 it ('returns a single status when given a single "since forever, until forever" (as null) window and pointed to it', () => {81 let cal = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);82 let tester = createTester({83 cal: cal,84 timeWindows: [{85 start: null,86 end: null,87 available: true88 }]89 });90 tester.assertLastStatus(Status.STATUS_AVAILABLE);91 tester.assertDone();92 });93 it ('returns a single status when given a single "since forever, until forever" (as undefined) window and pointed to it', () => {94 let cal = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);95 let tester = createTester({96 cal: cal,97 timeWindows: [{98 available: true99 }]100 });101 tester.assertLastStatus(Status.STATUS_AVAILABLE);102 tester.assertDone();103 });104 it ('returns two statuses when given a single time window and pointed to its start', () => {105 let cal = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);106 let tester = createTester({107 cal: cal,108 timeWindows: [109 when(cal, 'day', 1, true)110 ]111 });112 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);113 tester.assertLastStatus(Status.STATUS_UNKNOWN);114 tester.assertDone();115 });116 it ('returns three statuses when given a single time window and pointed to before its start', () => {117 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);118 let yesterday = cal.clone();119 advancer.advance(yesterday, 'day', -1);120 let tester = createTester({121 cal: yesterday,122 timeWindows: [123 when(cal, 'day', 1, false)124 ]125 });126 tester.assertNextStatus(Status.STATUS_UNKNOWN, 'day', 1);127 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);128 tester.assertLastStatus(Status.STATUS_UNKNOWN);129 tester.assertDone();130 });131 it ('returns the correct status when pointed to middle of window', () => {132 let cal = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);133 let midWindow = cal.clone();134 advancer.advance(midWindow, 'hour', 12);135 let tester = createTester({136 cal: midWindow,137 timeWindows: [138 when(cal, 'day', 1, true)139 ]140 });141 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'hour', 12);142 });143 it ('returns 5 statuses when given 3 separate windows, and pointed to between 1st and 2nd', () => {144 let cal1 = moment.tz([2010, 12-1, 11, 0, 0, 0, 0], tz);145 let cal2 = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);146 let cal3 = moment.tz([2010, 12-1, 15, 0, 0, 0, 0], tz);147 let tomorrow = cal1.clone();148 advancer.advance(tomorrow, 'day', 1);149 let tester = createTester({150 cal: tomorrow,151 timeWindows: [152 when(cal1, 'day', 1, true),153 when(cal2, 'day', 1, false),154 when(cal3, 'day', 1, true)155 ]156 });157 tester.assertNextStatus(Status.STATUS_UNKNOWN, 'day', 1);158 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);159 tester.assertNextStatus(Status.STATUS_UNKNOWN, 'day', 1);160 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);161 tester.assertLastStatus(Status.STATUS_UNKNOWN);162 tester.assertDone();163 });164 it ('supports overlapping windows by following the "last one wins" rule', () => {165 const yesterday = moment.tz([2010, 12-1, 12, 0, 0, 0, 0], tz);166 const today = moment.tz([2010, 12-1, 13, 0, 0, 0, 0], tz);167 const tomorrow = moment.tz([2010, 12-1, 14, 0, 0, 0, 0], tz);168 const tester = createTester({169 cal: yesterday,170 timeWindows: [171 when(today, 'day', 2, false),172 when(tomorrow, 'day', 1, true)173 ]174 });175 tester.assertNextStatus(Status.STATUS_UNKNOWN, 'day', 1);176 tester.assertNextStatus(Status.STATUS_UNAVAILABLE, 'day', 1);177 tester.assertNextStatus(Status.STATUS_UNKNOWN, 'day', 0); // TODO: This shouldn't be returned (we chose not to deal with it now as it doesn't really matter)178 tester.assertNextStatus(Status.STATUS_AVAILABLE, 'day', 1);179 tester.assertLastStatus(Status.STATUS_UNKNOWN);180 tester.assertDone();181 });...

Full Screen

Full Screen

externalDBMock.js

Source:externalDBMock.js Github

copy

Full Screen

...17 var goodPass = vars.users[1].password;18 vars.DB.log_user(goodMail, goodPass, function()19 {20 assert.ok(true, "user identified");21 assertDone();22 },23 function()24 {25 assert.notOk(false, "user identified");26 assertDone();27 });28 var badMail = "je_ne_suis_meme_pas_un_mail";29 var badPass = "";30 vars.DB.log_user(badMail, badPass, function()31 {32 assert.notOk(true, "foreigner not identified");33 assertDone();34 },35 function()36 {37 assert.notOk(false, "foreigner not identified");38 assertDone();39 });40}41suite.create_event = function(assert)42{43 var suite = test.suites.externalDBMock;44 var vars = suite.vars;45 var assertDone = assert.async(1);46 var evt = {47 name : "folle réunion de tdlog chez adèle",48 owner : 0,49 part : [1, 2, 3, 4],50 pos : new Position(0., 0.),51 addr : "chez adèle BIATCH",52 date : "17/01/2016"}53 var mail = vars.users[evt.owner].mail;54 var pass = vars.users[evt.owner].password;55 vars.DB.create_event(56 mail,57 pass,58 evt.name,59 evt.addr,60 evt.lat,61 evt.lon,62 evt.part,63 evt.date,64 function(id)65 {66 var db_evt = vars.DB.events[vars.DB.eventId];67 assert.equal(db_evt.name, evt.name);68 assert.equal(db_evt.address, evt.addr);69 assert.equal(db_evt.participants, evt.part);70 assert.equal(db_evt.date, evt.date);71 assert.equal(db_evt.owner, evt.owner);72 assertDone();73 });74}75suite.get_user_id = function(assert)76{77 var suite = test.suites.externalDBMock;78 var vars = suite.vars;79 var assertDone = assert.async(1);80 var mail = vars.users[0].mail;81 vars.DB.get_user_id(mail, function(id)82 {83 assert.equal(id, 0);84 assertDone();85 });86}87suite.set_pass = function(assert)88{89 var suite = test.suites.externalDBMock;90 var vars = suite.vars;91 var assertDone = assert.async(2);92 var goodMail = vars.users[1].mail;93 var goodPass = vars.users[1].password;94 var newPass = "toto";95 vars.DB.set_pass(goodMail, goodPass, newPass, test_added);96 function test_added()97 {98 assert.equal(newPass, vars.DB.users[1].password, "password changed");99 assertDone();100 }101 var badMail = "je_ne_suis_meme_pas_un_mail";102 var badPass = "";103 vars.DB.set_pass(badMail, badPass, newPass, function(){assert.ok(false)}, test_err);104 function test_err(err)105 {106 assert.equal(err.code, 1000, "exception wrong identification");107 assertDone();108 }109}110suite.add_user = function(assert)111{112 var suite = test.suites.externalDBMock;113 var vars = suite.vars;114 var assertDone = assert.async(3);115 var goodUser = {116 name : "jane",117 surname : "doe",118 mail : "jane.doe@gmail.com",119 tel : "+33648751227",120 password : "peanutButter"121 }122 var badMail = {123 name : "michel",124 surname : "perrier",125 mail : "_michel.perrier@gmail.com",126 tel : "+336487512",127 password : "tmux"128 }129 var users_equal = function(usr1, usr2)130 {131 return usr1.name == usr2.name &&132 usr1.surname == usr2.surname &&133 usr1.mail == usr2.mail &&134 usr1.tel == usr2.tel &&135 usr1.password == usr2.password;136 }137 vars.DB.add_user(goodUser.name,138 goodUser.surname,139 goodUser.mail,140 goodUser.tel,141 goodUser.password,142 test_added);143 function test_added()144 {145 assert.ok(users_equal(vars.DB.users[vars.DB.currentId], goodUser));146 assertDone();147 }148 vars.DB.add_user(badMail.name,149 badMail.surname,150 badMail.mail,151 badMail.tel,152 badMail.password,153 function(){},154 function excep1002(err)155 {156 assert.equal(err.code, 1002, "Exception 1002 when adding bad mail do DB");157 assertDone();158 });159 vars.DB.add_user("",160 "",161 goodUser.mail,162 "+33640404040",163 "",164 function(){},165 function excep1001(err)166 {167 assert.equal(err.code, 1001, "Exception 1001 when adding same user");168 assertDone();169 });170}171suite.is_mail = function(assert)172{173 var suite = test.suites.externalDBMock;174 var vars = suite.vars;175 var goodMail = "a.correct.mail@mailer.com";176 var badMail1 = "_incorrect.mail@mailer.com";177 var badMail2 = "incorrect.mail";178 var badMail3 = "incorrect.mail@com";179 var badMail4 = "incorr&ct.mail@mailer.com";180 assert.ok(vars.DB.is_mail(goodMail), goodMail);181 assert.notOk(vars.DB.is_mail(badMail1), badMail1);182 assert.notOk(vars.DB.is_mail(badMail2), badMail2);...

Full Screen

Full Screen

localDB.js

Source:localDB.js Github

copy

Full Screen

...46 var evt = vars.events[0];47 vars.DB.get_event(evt.id, function(db_evt)48 {49 assert.ok(isEqual(db_evt, evt), "adding event");50 assertDone();51 });52}53suite.add_event_participants = function(assert)54{55 var vars = test.suites.localDB.vars;56 var suite = test.suites.localDB;57 var assertDone = assert.async(1);58 var evt = vars.events[1];59 var participantId = 1;60 vars.DB.add_event_participant(2, participantId, test_added);61 function test_added ()62 {63 vars.DB.get_event_participants(evt.id, function get_parts(db_parts)64 {65 assert.equal(db_parts[0], participantId, "adding participant");66 assert.equal(db_parts.length, 1, "not adding too much participants");67 assertDone();68 });69 }70}71suite.add_friend = function(assert)72{73 var vars = test.suites.localDB.vars;74 var suite = test.suites.localDB;75 var assertDone = assert.async(1);76 var expFriend = {77 id : 1000,78 name : "cymes",79 surname : "michel",80 mail : "michel.cymes@france5.fr",81 tel : "+33684572310"82 }83 var test_added = function()84 {85 vars.DB.get_friend_by_id(expFriend.id,86 function(actFriend)87 {88 assert.ok(isEqual(actFriend, expFriend), "Friend correctly added");89 assertDone();90 });91 }92 vars.DB.add_friend(expFriend.id,93 expFriend.name,94 expFriend.surname,95 expFriend.mail,96 expFriend.tel,97 test_added);98}99suite.get_all_friends = function(assert)100{101 var vars = test.suites.localDB.vars;102 var suite = test.suites.localDB;103 var assertDone = assert.async(1);104 vars.DB.get_all_friends(function(friends)105 {106 var friend2 = vars.friends[2]107 assert.equal(friends[2].name, friend2.name, "name");108 assert.equal(friends[2].surname, friend2.surname, "surname");109 assert.equal(friends[2].tel, friend2.tel, "tel");110 assertDone();111 });112}113suite.search_friends = function(assert)114{115 var vars = test.suites.localDB.vars;116 var suite = test.suites.localDB;117 var assertDone = assert.async(5);118 var tel0 = "0650544817";119 var surname1 = vars.friends[1].surname.substring(2,5);120 var mail2 = vars.friends[2].mail;121 var name3 = vars.friends[3].name + " " + vars.friends[3].surname;122 var search_assertion = function(keyword, expFriend, message)123 {124 vars.DB.search_friends(keyword, function(actFriend)125 {126 assert.equal(actFriend[0].id, expFriend.id, message);127 assertDone();128 });129 }130 search_assertion(tel0, vars.friends[0], "keyword : french tel");131 search_assertion(surname1, vars.friends[1], "keyword : surname substr");132 search_assertion(mail2, vars.friends[2], "keyword : mail");133 search_assertion(name3, vars.friends[3], "keyword : name surname");134 vars.DB.search_friends("", function(all_friends)135 {136 assert.equal(all_friends.length, vars.friends.length, "empty chain");137 assertDone();138 });139}140suite.setUp = function(assert)141{142 var vars = test.suites.localDB.vars;143 var suite = test.suites.localDB;144 vars.user = { id : 0,145 name : "john",146 surname : "doe",147 mail : "john.doe@eleves.enpc.fr",148 tel : "+336128745",149 lat : 0.,150 long : 0.,151 pass : "mot_de_passe"};152 vars.friends = Array(153 { id : 1,154 name : "paran",155 surname : "arnaud",156 mail : "paran.arnaud@gmail.com",157 tel : "+33650544817",158 lat : 0.1,159 long : 0.1},160 {id : 2,161 name : "lebastard",162 surname : "simon",163 mail : "simon.lebastard@eleves.enpc.fr",164 tel : "+33750332043",165 lat : 0.2,166 long : 0.2},167 {id : 3,168 name : "gillier",169 surname : "adele",170 mail : "adele.gillier@eleves.enpc.fr",171 tel : "+34567853159",172 lat : 0.3,173 long : 0.3},174 {id : 4,175 name : "soulier",176 surname : "eloise",177 mail : "eloise.soulier@eleves.enpc.fr",178 tel : "+44865874520",179 lat : 0.4,180 long : 0.4}181 );182 vars.events = Array({id : 1,183 name : "partouze entre amis chez jacquie et michel",184 creatorId : 2,185 participants : [1, 2, 3, 4],186 latitude : 0.,187 longitude : 0.,188 address : "Merci qui?",189 date : "16/09/1993"190 },191 {id : 2,192 name : "forever alone festival",193 creatorId : 3,194 participants : [],195 latitude : 0.,196 longitude : 0.,197 address : "lonely island",198 date : "17/09/1993"199 });200 var assertDone = assert.async(vars.friends.length + vars.events.length);201 vars.DB = new localDBManager(populateDB);202 function populateDB()203 {204 vars.DB.set_user_mail_pass(vars.user.mail, vars.user.pass);205 for (friend of vars.friends) {206 vars.DB.add_friend(friend.id,207 friend.name,208 friend.surname,209 friend.mail,210 friend.tel,211 assertDone212 );213 }214 for (evt of vars.events) {215 vars.DB.add_event(evt.id,216 evt.name,217 evt.creatorId,218 evt.participants,219 evt.latitude,220 evt.longitude,221 evt.address,222 evt.date,223 assertDone224 );225 }226 }227}228suite.tearDown = function(assert)229{230 var vars = test.suites.localDB.vars;231 var suite = test.suites.localDB;232 var assertDone = assert.async(1);233 vars.DB.drop_db(function()234 {235 assertDone();236 });...

Full Screen

Full Screen

localDBMock.js

Source:localDBMock.js Github

copy

Full Screen

...38 {39 vars.DB.get_event(evt.id, function(db_evt)40 {41 assert.ok(isEqual(db_evt, evt), "adding event");42 assertDone();43 });44 }45 vars.DB.add_event(evt.id,46 evt.name,47 evt.owner,48 evt.part,49 evt.lat,50 evt.lon,51 evt.addr,52 evt.date,53 test_added);54}55suite.add_friend = function(assert)56{57 var vars = test.suites.localDBMock.vars;58 var suite = test.suites.localDBMock;59 var assertDone = assert.async(1);60 var expFriend = {61 id : 1000,62 name : "cymes",63 surname : "michel",64 mail : "michel.cymes@france5.fr",65 tel : "+33684572310"66 }67 var test_added = function()68 {69 vars.DB.get_friend_by_id(expFriend.id,70 function(actFriend)71 {72 assert.ok(isEqual(actFriend, expFriend), "Friend correctly added");73 assertDone();74 });75 }76 vars.DB.add_friend(expFriend.id,77 expFriend.name,78 expFriend.surname,79 expFriend.mail,80 expFriend.tel,81 test_added);82}83suite.get_all_events = function(assert)84{85 var suite = test.suites.localDBMock;86 var vars = suite.vars;87 var evts = vars.events;88 var assertDone = assert.async(1);89 vars.DB.get_all_events(function(evt_list)90 {91 assert.equal(evt_list.length, evts.length, "all events should be caught");92 assertDone();93 });94}95suite.get_all_friends_names_tel = function(assert)96{97 var vars = test.suites.localDBMock.vars;98 var suite = test.suites.localDBMock;99 var assertDone = assert.async(1);100 vars.DB.get_all_friends_names_tel(function(friends)101 {102 var friend2 = vars.friends[2]103 assert.equal(friends[2].name, friend2.name, "name");104 assert.equal(friends[2].surname, friend2.surname, "surname");105 assert.equal(friends[2].tel, friend2.tel, "tel");106 assertDone();107 });108}109suite.search_friends = function(assert)110{111 var vars = test.suites.localDBMock.vars;112 var suite = test.suites.localDBMock;113 var assertDone = assert.async(5);114 var tel0 = "0650544817";115 var surname1 = vars.friends[1].surname.substring(2,5);116 var mail2 = vars.friends[2].mail;117 var name3 = vars.friends[3].name + " " + vars.friends[3].surname;118 var search_assertion = function(keyword, expFriend, message)119 {120 vars.DB.search_friends(keyword, function(actFriend)121 {122 assert.equal(actFriend[0].id, expFriend.id, message);123 assertDone();124 });125 }126 search_assertion(tel0, vars.friends[0], "keyword : french tel");127 search_assertion(surname1, vars.friends[1], "keyword : surname substr");128 search_assertion(mail2, vars.friends[2], "keyword : mail");129 search_assertion(name3, vars.friends[3], "keyword : name substr");130 vars.DB.search_friends("", function(all_friends)131 {132 assert.equal(all_friends.length, vars.friends.length, "empty chain");133 assertDone();134 });135}136suite.get_friend_id_by_tel = function(assert)137{138 var vars = test.suites.localDBMock.vars;139 var suite = test.suites.localDBMock;140 141 var id = 1;142 var tel = vars.friends[id].tel;143 var non_existing_tel = "+33758315420";144 assert.equal(vars.DB.get_friend_id_by_tel(tel), id, "returns id when given corresponding tel");145 assert.throws(function(){vars.DB.get_friend_id_by_tel(non_existing_tel)}, new CommonException(2002), "throws error when friend doesn't exist");146}147suite.setUp = function()...

Full Screen

Full Screen

room.js

Source:room.js Github

copy

Full Screen

...15 user.done = true;16 console.log(user.name.bold, 'joined room', this.id.bold);17 io.to(this.id).emit('userJoined', user);18 this.users.push(user);19 this.assertDone();20};21Room.prototype.removeUser = function (user) {22 io.to(this.id).emit('userLeft', _.findWhere(this.users, {uuid: user}));23 delete _.remove(this.users, {uuid: user});24 this.assertDone();25};26/* add's a time with the user's uuid. If index exists, add to the indexed time, if not, add to current solve. */27Room.prototype.addTime = function (user, time, index) {28 if (!index) {29 index = this.times.length - 1;30 }31 _.set(this.times[index], 'results[' + user + ']', time);32 io.to(this.id).emit('newTime', {user: user, time: time, index: index});33 this.getUser(user).done = true;34 this.assertDone();35};36/* Determines if we're done with the current solve. If yes, generate new sramble and move to next solve. */37Room.prototype.assertDone = function () {38 if (!_.isEmpty(this.users)) {39 if (_.every(this.users, 'done', true)) {40 var scramble = Scramblers[this.event].getRandomScramble().scramble_string;41 this.times.push({scramble: scramble, results: {}});42 io.to(this.id).emit('newScramble', scramble);43 console.log('new Scramble', scramble);44 this.users.forEach(function (user) {45 user.done = false;46 });47 }48 } else {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { assertDone } = require('playwright/lib/internal/test');3(async () => {4 const browser = await playwright.chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: 'example.png' });8 await browser.close();9 assertDone();10})();11$ npx playwright test --browser-context "viewport: { width: 640, height: 480 }, userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.73 Mobile/15E148 Safari/604.1'" test.js

Full Screen

Using AI Code Generation

copy

Full Screen

1const { assertDone } = require('playwright-core/lib/server/trace/recorder');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Get Started');8 await assertDone();9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2test('My test', async ({ page }) => {3 expect(await page.textContent('.navbar__inner')).toContain('Docs');4 await page.internalAPI.assertDone();5});6The assertDone() method is available in the Playwright API. It is not available in

Full Screen

Using AI Code Generation

copy

Full Screen

1const { assertDone } = require('@playwright/test/lib/test');2const { assertDone } = require('@playwright/test/lib/test');3const { test, expect } = require('@playwright/test');4test('example test', async ({ page }) => {5 await page.click('text=Get started');6 await page.click('text=Docs');7 await page.click('text=API');8 await assertDone(page);9});10const { assertDone } = require('@playwright/test/lib/test');11const { assertDone } = require('@playwright/test/lib/test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const assertDone = require('playwright-internal').assertDone;2const { test } = require('playwright-internal');3test('should work', async ({ page }) => {4 assertDone();5});6const { test } = require('@playwright/test');7test('should work', async ({ page }) => {8 assertDone();9});10assertDone(options)11const assertDone = require('playwright-internal').assertDone;12const { test } = require('playwright-internal');13test('should work', async ({ page }) => {14 assertDone();15});16test('should work with timeout', async ({ page }) => {17 assertDone({ timeout: 5000 });18});19test('should work with timeout', async ({ page }) => {20 assertDone({ timeout: 5000 });21});22test('should work with timeout', async ({ page }) => {23 assertDone({ timeout: 5000 });24});25test('should work with timeout', async ({ page }) => {26 assertDone({ timeout: 5000 });27});28test('should work with timeout', async ({ page }) => {29 assertDone({ timeout: 5000 });30});31test('should work with timeout', async ({ page }) => {32 assertDone({ timeout: 5000 });33});34test('should work with timeout', async ({ page }) => {35 assertDone({ timeout: 5000 });36});37test('should work with timeout', async

Full Screen

Using AI Code Generation

copy

Full Screen

1const { assertDone } = require('playwright/lib/server/browserContext');2const assert = require('assert');3(async () => {4 const context = await browser.newContext();5 await context.newPage();6 const error = await assertDone(1000).catch(e => e);7 assert.ok(error.message.includes('Timeout of 1000ms exceeded'));8 await context.close();9})();10const { test, expect } = require('@playwright/test');11test('assertDone', async ({ page }) => {12 await expect(page).toHaveSelector('text=Playwright is a Node library to automate');13});14{15 "scripts": {16 },17 "devDependencies": {18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { assertDone } = require('@playwright/test/lib/server/trace/recorder');2(async () => {3 await assertDone();4})();5const test = require('@playwright/test');6test('My Test', async ({ page }) => {7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { assertDone } from "@playwright/test";2import { test, expect } from "@playwright/test";3test("assertDone", async ({ page }) => {4 await assertDone(page);5 await page.click("text=Google Search");6 await assertDone(page);7 await page.click("text=I'm Feeling Lucky");8 await assertDone(page);9});10import { test } from "@playwright/test";11import { assertDone } from "../test";12test("assertDone", async ({ page }) => {13 await assertDone(page);14 await page.click("text=Google Search");15 await assertDone(page);16 await page.click("text=I'm Feeling Lucky");17 await assertDone(page);18});

Full Screen

Using AI Code Generation

copy

Full Screen

1const assertDone = require('@playwright/test/lib/internal/assertDone');2const { chromium } = require('playwright');3const assert = require('assert');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await assertDone(page);9 await page.screenshot({ path: 'example.png' });10 await browser.close();11})();12const { test } = require('@playwright/test');13test('assertDone example', async ({ page }) => {14 await page.screenshot({ path: 'example.png' });15});

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