Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix browser manipulation issues (closes #2150, closes #2146) #2158

Merged
merged 2 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/screenshots/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Promise from 'pinkie';
import { PNG } from 'pngjs';
import promisifyEvent from 'promisify-event';
import limitNumber from '../utils/limit-number';
import { deleteFile } from '../utils/promisified-functions';
import { InvalidElementScreenshotDimensionsError } from '../errors/test-run/';


Expand Down Expand Up @@ -59,8 +60,10 @@ export default async function (screenshotPath, markSeed, clientAreaDimensions, c
var width = right - left;
var height = bottom - top;

if (width <= 0 || height <= 0)
if (width <= 0 || height <= 0) {
await deleteFile(screenshotPath);
throw new InvalidElementScreenshotDimensionsError(width, height);
}

var dstImage = new PNG({ width, height });
var stride = dstImage.width * 4;
Expand Down
14 changes: 2 additions & 12 deletions src/test-run/commands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ function isWindowSwitchingCommand (command) {
}

export function canSetDebuggerBreakpointBeforeCommand (command) {
return command.type !== TYPE.debug && !isClientFunctionCommand(command) && !isBrowserManipulationCommand(command) &&
!isServiceCommand(command);
return command.type !== TYPE.debug && !isClientFunctionCommand(command) && !isServiceCommand(command);
}

export function isBrowserManipulationCommand (command) {
Expand All @@ -41,28 +40,19 @@ export function isBrowserManipulationCommand (command) {
command.type === TYPE.maximizeWindow;
}

export function isScreenshotCommand (command) {
return command.type === TYPE.takeScreenshot ||
command.type === TYPE.takeScreenshotOnFail;
}

function isRejectableBrowserManipulationCommand (command) {
return command.type === TYPE.resizeWindow ||
command.type === TYPE.resizeWindowToFitDevice ||
command.type === TYPE.maximizeWindow;
}

function isServiceBrowserManipulationCommand (command) {
return command.type === TYPE.takeScreenshotOnFail;
}

export function isServiceCommand (command) {
return command.type === TYPE.testDone ||
command.type === TYPE.takeScreenshotOnFail ||
command.type === TYPE.showAssertionRetriesStatus ||
command.type === TYPE.hideAssertionRetriesStatus ||
command.type === TYPE.setBreakpoint ||
isServiceBrowserManipulationCommand(command);
command.type === TYPE.takeScreenshotOnFail;
}

export function isExecutableInTopWindowOnly (command) {
Expand Down
9 changes: 5 additions & 4 deletions src/utils/promisified-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import psNode from 'ps-node';
import promisify from './promisify';


export const ensureDir = promisify(mkdirp);
export const stat = promisify(fs.stat);
export const writeFile = promisify(fs.writeFile);
export const readFile = promisify(fs.readFile);
export const ensureDir = promisify(mkdirp);
export const stat = promisify(fs.stat);
export const writeFile = promisify(fs.writeFile);
export const readFile = promisify(fs.readFile);
export const deleteFile = promisify(fs.unlink);

export const findProcess = promisify(psNode.lookup);
export const killProcess = promisify(psNode.kill);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ describe('[API] t.takeElementScreenshot()', function () {
only: 'chrome'
})
.catch(function (errs) {
expect(assertionHelper.checkScreenshotsCreated(false, 2, 'custom')).eql(false);
expect(errs[0]).to.contains('Unable to capture an element image because the resulting image width is zero or negative.');
expect(errs[0]).to.contains(
' 37 |test(\'Invalid dimensions\', async t => {' +
Expand Down