How to use ensureCropOptions method in Testcafe

Best JavaScript code snippet using testcafe

index.js

Source: index.js Github

copy

Full Screen

...83 throw error;84 });85 })86 .then(() => {87 ensureCropOptions(this.element, this.command.options);88 const { scrollTargetX, scrollTargetY, scrollToCenter } = this.command.options;89 const scrollAutomation = new ScrollAutomation(this.element, new ScrollOptions({90 offsetX: scrollTargetX,91 offsetY: scrollTargetY,92 scrollToCenter: scrollToCenter,93 skipParentFrames: true94 }));95 return scrollAutomation.run();96 });97 }98 _hideUI () {99 hideUI();100 if (this.command.markData)101 showScreenshotMark(this.command.markData);...

Full Screen

Full Screen

ensure-crop-options.js

Source: ensure-crop-options.js Github

copy

Full Screen

1import { styleUtils } from '../​../​deps/​testcafe-core';2import { getOffsetOptions } from '../​../​deps/​testcafe-automation';3import limitNumber from '../​../​../​../​utils/​limit-number';4import { ActionInvalidScrollTargetError, InvalidElementScreenshotDimensionsError } from '../​../​../​../​errors/​test-run';5function determineDimensionBounds (bounds, maximum) {6 const hasMin = typeof bounds.min === 'number';7 const hasMax = typeof bounds.max === 'number';8 const hasLength = typeof bounds.length === 'number';9 if (hasLength)10 bounds.length = limitNumber(bounds.length, 0, maximum);11 if (hasMin && bounds.min < 0)12 bounds.min += maximum;13 if (hasMax && bounds.max < 0)14 bounds.max += maximum;15 if (!hasMin)16 bounds.min = hasMax && hasLength ? bounds.max - bounds.length : 0;17 if (!hasMax)18 bounds.max = hasLength ? bounds.min + bounds.length : maximum;19 bounds.min = limitNumber(bounds.min, 0, maximum);20 bounds.max = limitNumber(bounds.max, 0, maximum);21 bounds.length = bounds.max - bounds.min;22 return bounds;23}24function determineScrollPoint (cropStart, cropEnd, viewportBound) {25 return Math.round(cropStart + limitNumber(cropEnd - cropStart, 0, viewportBound) /​ 2);26}27export default function ensureCropOptions (element, options) {28 const elementRectangle = element.getBoundingClientRect();29 const elementBounds = {30 left: elementRectangle.left,31 right: elementRectangle.right,32 top: elementRectangle.top,33 bottom: elementRectangle.bottom34 };35 const elementMargin = styleUtils.getElementMargin(element);36 const elementPadding = styleUtils.getElementPadding(element);37 const elementBordersWidth = styleUtils.getBordersWidth(element);38 options.originOffset = { x: 0, y: 0 };39 const scrollRight = elementBounds.left + element.scrollWidth + elementBordersWidth.left + elementBordersWidth.right;40 const scrollBottom = elementBounds.top + element.scrollHeight + elementBordersWidth.top + elementBordersWidth.bottom;41 elementBounds.right = Math.max(elementBounds.right, scrollRight);42 elementBounds.bottom = Math.max(elementBounds.bottom, scrollBottom);43 if (!options.includeBorders || !options.includePaddings) {44 options.originOffset.x += elementBordersWidth.left;45 options.originOffset.y += elementBordersWidth.top;46 elementBounds.left += elementBordersWidth.left;47 elementBounds.top += elementBordersWidth.top;48 elementBounds.right -= elementBordersWidth.right;49 elementBounds.bottom -= elementBordersWidth.bottom;50 if (!options.includePaddings) {51 options.originOffset.x += elementPadding.left;52 options.originOffset.y += elementPadding.top;53 elementBounds.left += elementPadding.left;54 elementBounds.top += elementPadding.top;55 elementBounds.right -= elementPadding.right;56 elementBounds.bottom -= elementPadding.bottom;57 }58 }59 else if (options.includeMargins) {60 options.originOffset.x -= elementMargin.left;61 options.originOffset.y -= elementMargin.top;62 elementBounds.left -= elementMargin.left;63 elementBounds.top -= elementMargin.top;64 elementBounds.right += elementMargin.right;65 elementBounds.bottom += elementMargin.bottom;66 }67 elementBounds.width = elementBounds.right - elementBounds.left;68 elementBounds.height = elementBounds.bottom - elementBounds.top;69 const horizontalCropBounds = determineDimensionBounds({ min: options.crop.left, max: options.crop.right, length: options.crop.width }, elementBounds.width);70 const verticalCropBounds = determineDimensionBounds({ min: options.crop.top, max: options.crop.bottom, length: options.crop.height }, elementBounds.height);71 options.crop.left = horizontalCropBounds.min;72 options.crop.right = horizontalCropBounds.max;73 options.crop.width = horizontalCropBounds.length;74 options.crop.top = verticalCropBounds.min;75 options.crop.bottom = verticalCropBounds.max;76 options.crop.height = verticalCropBounds.length;77 if (options.crop.width <= 0 || options.crop.height <= 0)78 throw new InvalidElementScreenshotDimensionsError(options.crop.width, options.crop.height);79 const viewportDimensions = styleUtils.getViewportDimensions();80 if (elementBounds.width > viewportDimensions.width || elementBounds.height > viewportDimensions.height)81 options.scrollToCenter = true;82 const hasScrollTargetX = typeof options.scrollTargetX === 'number';83 const hasScrollTargetY = typeof options.scrollTargetY === 'number';84 if (!hasScrollTargetX)85 options.scrollTargetX = determineScrollPoint(options.crop.left, options.crop.right, viewportDimensions.width);86 if (!hasScrollTargetY)87 options.scrollTargetY = determineScrollPoint(options.crop.top, options.crop.bottom, viewportDimensions.height);88 const { offsetX, offsetY } = getOffsetOptions(element, options.scrollTargetX, options.scrollTargetY);89 options.scrollTargetX = offsetX;90 options.scrollTargetY = offsetY;91 const isScrollTargetXValid = !hasScrollTargetX || options.scrollTargetX >= options.crop.left && options.scrollTargetX <= options.crop.right;92 const isScrollTargetYValid = !hasScrollTargetY || options.scrollTargetY >= options.crop.top && options.scrollTargetY <= options.crop.bottom;93 if (!isScrollTargetXValid || !isScrollTargetYValid)94 throw new ActionInvalidScrollTargetError(isScrollTargetXValid, isScrollTargetYValid);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensureCropOptions } from 'testcafe-browser-tools';2test('My Test', async t => {3 await ensureCropOptions('chrome');4});5import { ensureCropOptions } from 'testcafe-browser-tools';6test('My Test', async t => {7 await ensureCropOptions('firefox');8});9import { ensureCropOptions } from 'testcafe-browser-tools';10test('My Test', async t => {11 await ensureCropOptions('ie');12});13import { ensureCropOptions } from 'testcafe-browser-tools';14test('My Test', async t => {15 await ensureCropOptions('MicrosoftEdge');16});17import { ensureCropOptions } from 'testcafe-browser-tools';18test('My Test', async t => {19 await ensureCropOptions('safari');20});21import { ensureCropOptions } from 'testcafe-browser-tools';22test('My Test', async t => {23 await ensureCropOptions('opera');24});25import { ensureCropOptions } from 'testcafe-browser-tools';26test('My Test', async t => {27 await ensureCropOptions('chromium');28});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensureCropOptions } from 'testcafe-browser-tools';2import { Selector } from 'testcafe';3test('My first test', async t => {4 ensureCropOptions({ crop: { left: 10, top: 10, width: 100, height: 100 } });5 const developerNameInput = Selector('#developer-name');6 .typeText(developerNameInput, 'Peter')7 .click('#submit-button');8});9import { ensureCropOptions } from 'testcafe-browser-tools';10import { Selector } from 'testcafe';11test('My first test', async t => {12 ensureCropOptions({ crop: { left: 10, top: 10, width: 100, height: 100 } });13 const developerNameInput = Selector('#developer-name');14 .typeText(developerNameInput, 'Peter')15 .click('#submit-button');16});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensureCropOptions } from 'testcafe-browser-tools';2test('My test', async t => {3 await t.takeScreenshot();4 const cropDimensions = {5 };6 await ensureCropOptions(cropDimensions);7});8import { setCrop } from 'testcafe-browser-tools';9test('My test', async t => {10 await t.takeScreenshot();11 const cropDimensions = {12 };13 await setCrop(cropDimensions);14});15import { takeScreenshot } from 'testcafe-browser-tools';16test('My test', async t => {17 const screenshotPath = 'C:/​Users/​John/​screenshots/​';18 const screenshotName = 'test3';19 await takeScreenshot(screenshotPath, screenshotName);20});21import { resize } from 'testcafe-browser-tools';22test('My test', async t => {23 const width = 100;24 const height = 100;25 await resize(width, height);26});27docker run -v /​dev/​shm:/​dev/​shm -v $(pwd):/​tests -it testcafe/​testcafe "chrome:headless" "/​tests/​**/​*.js"28async function getBrowserInfo () {29 return {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensureCropOptions } from 'testcafe-browser-tools';2test('Crop image', async t => {3 .setFilesToUpload('#upload', [4 ]);5 const img = await ensureCropOptions('./​images/​1.png', { left: 0, top: 0, width: 10, height: 10 });6 .expect(img.width).eql(10)7 .expect(img.height).eql(10);8});9ensureCropOptions( filePath, cropArea ) → Promise10{ left : number , top : number , width : number , height : number }11import { ensureCropOptions } from 'testcafe-browser-tools';12test('Crop image', async t => {13 .setFilesToUpload('#upload', [14 ]);15 const img = await ensureCropOptions('./​images/​1.png', { left: 0, top: 0, width: 10, height: 10 });16 .expect(img.width).eql(10)17 .expect(img.height).e

Full Screen

Using AI Code Generation

copy

Full Screen

1import { t, Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .takeScreenshot({ path: 'screenshot.png', crop: { left: 10, top: 20, right: 30, bottom: 40 } });6});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ensureCropOptions } from 'testcafe-browser-tools';2test('Crop options', async t => {3 const cropOptions = {4 };5 const { left, top, width, height } = await ensureCropOptions(cropOptions);6 await t.expect(left).eql(0);7 await t.expect(top).eql(0);8 await t.expect(width).eql(100);9 await t.expect(height).eql(100);10});11import { ensureCropOptions } from 'testcafe-browser-tools';12test('Crop options', async t => {13 const cropOptions = {14 };15 try {16 await ensureCropOptions(cropOptions);17 }18 catch (err) {19 console.log(err.message);20 }21});22import { ensureCropOptions } from 'testcafe-browser-tools';23test('Crop options', async t => {24 const cropOptions = {25 };26 const { left, top, width, height } = await ensureCropOptions(cropOptions, { defaultHeight: 20 });27 await t.expect(left).eql(0);28 await t.expect(top).eql(0);29 await t.expect(width).eql(100);30 await t.expect(height).eql(20);31});32import { ensureCropOptions } from 'testcafe-browser-tools';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { ensureCropOptions } from 'testcafe-browser-tools';3test('My Test', async t => {4 const button = Selector('#submit-button');5 .click(button)6 .takeScreenshot({ path: 'test.png', crop: { left: 10, top: 10, right: 10, bottom: 10 } });7});8import { Selector } from 'testcafe';9import { ensureCropOptions } from 'testcafe-browser-tools';10test('My Test', async t => {11 const button = Selector('#submit-button');12 .click(button)13 .takeScreenshot({ path: 'test.png', crop: { left: 10, top: 10, right: 10, bottom: 10 } });14});15import { Selector } from 'testcafe';16import { ensureCropOptions } from 'testcafe-browser-tools';17test('My Test', async t => {18 const button = Selector('#submit-button');19 .click(button)20 .takeScreenshot({ path: 'test.png', crop: { left: 10, top: 10, right: 10, bottom: 10 } });21});22import { Selector } from 'testcafe';23import { ensureCropOptions } from 'testcafe-browser-tools';24test('My Test', async t => {25 const button = Selector('#submit-button');26 .click(button)27 .takeScreenshot({ path: 'test.png', crop: { left: 10, top: 10, right:

Full Screen

Using AI Code Generation

copy

Full Screen

1import { t } from 'testcafe';2import { ensureCropOptions } from './​crop-options';3test('My test', async () => {4 await ensureCropOptions(t);5});6export async function ensureCropOptions(t) {7 const cropOptions = await t.eval(() => window.cropOptions);8}9import { t } from 'testcafe';10import { ensureCropOptions } from './​crop-options';11test('My test', async () => {12 await ensureCropOptions(t);13});14export async function ensureCropOptions(t) {15 const cropOptions = await t.eval(() => window.cropOptions);

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Getting Started With Ghost Testing

Hello World!!! In this article, you will get the answers to what needs to be tested in the case of websites created using the Ghost framework and how the Ghost testing can be planned and executed. To begin with, you will be introduced to a brief overview of the platform, Ghost, its goals, its adoption rate, and its popularity in the present market.

TestCafe Tutorial: How To Select Page Elements Using TestCafe Selectors

Let’s assume you want to build or create a web page as a web developer. First, you will create an HTML file that comprises semantic and non-semantic elements (e.g. < header >, < section >, and < footer > are examples of semantic elements). < div >, < span >, < h1 >, and < p > are examples of non-semantic elements.

How To Perform Modern Web Testing With TestCafe Using JavaScript And Selenium

Whether it is an application or web app, every software requires testing after development to ensure it does what we expect it to do. Software testing involves using manual or automated tools. Test automation tools are the best to use over manual tools because they increase software testing effectiveness, efficiency, and coverage.

The Evolution of Browser Automation: Christian Bromann [Testμ 2022]

Have you been curious about browser automation? Christian Bromann, Founding Engineer, Stateful Inc., is here to share the perils of information surrounding the topic with Manoj Kumar, VP of Developers Relation, hosting the session.

The Story Behind Dunelm’s 360° Digital Transformation

Dunelm is a billion-dollar British home furnishing retailer with 169 superstores, three high street stores, and over a hundred in-store coffee shops throughout the United Kingdom. It is listed on LSE (London Stock Exchange) and has been a major retailer for homewares in the country.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe 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