Skip to content

Commit

Permalink
Add log.warn to click and moveTo command to avoid out of bound error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jemishgopani committed Feb 29, 2024
1 parent 261b015 commit 776ced4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions packages/webdriverio/src/commands/element/click.ts
@@ -1,7 +1,10 @@
import logger from '@wdio/logger'

import { getBrowserObject } from '../../utils/index.js'
import type { ClickOptions } from '../../types.js'
import type { Button } from '../../utils/actions/index.js'

const log = logger('webdriver')
/**
*
* Click on an element.
Expand Down Expand Up @@ -79,7 +82,7 @@ import type { Button } from '../../utils/actions/index.js'
* @param {string= | number=} options.button can be one of [0, "left", 1, "middle", 2, "right"] (optional)
* @param {number=} options.x Number (optional)
* @param {number=} options.y Number (optional)
* @param {number=} options.skipRelease Boolean (optional)
* @param {boolean=} options.skipRelease Boolean (optional)
*/
export async function click(
this: WebdriverIO.Element,
Expand Down Expand Up @@ -126,10 +129,10 @@ export async function click(
if (xOffset || yOffset) {
const { width, height } = await browser.getElementRect(this.elementId)
if ((xOffset && xOffset < (-Math.floor(width / 2))) || (xOffset && xOffset > Math.floor(width / 2))) {
throw new Error('xOffset would cause a out of bounds error as it goes outside of element')
log.warn('xOffset would cause a out of bounds error as it goes outside of element')
}
if ((yOffset && yOffset < (-Math.floor(height / 2))) || (yOffset && yOffset > Math.floor(height / 2))) {
throw new Error('yOffset would cause a out of bounds error as it goes outside of element')
log.warn('yOffset would cause a out of bounds error as it goes outside of element')
}
}
const clickNested = async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/webdriverio/src/commands/element/moveTo.ts
@@ -1,9 +1,9 @@
import logger from '@wdio/logger'

import { getBrowserObject } from '../../utils/index.js'
import type { MoveToOptions } from '../../types.js'

type MoveToOptions = {
xOffset?: number,
yOffset?: number,
}
const log = logger('webdriver')

/**
*
Expand Down Expand Up @@ -33,10 +33,10 @@ export async function moveTo (
if (xOffset || yOffset) {
const { width, height } = await browser.getElementRect(this.elementId)
if ((xOffset && xOffset < (-Math.floor(width / 2))) || (xOffset && xOffset > Math.floor(width / 2))) {
throw new Error('xOffset would cause a out of bounds error as it goes outside of element')
log.warn('xOffset would cause a out of bounds error as it goes outside of element')
}
if ((yOffset && yOffset < (-Math.floor(height / 2))) || (yOffset && yOffset > Math.floor(height / 2))) {
throw new Error('yOffset would cause a out of bounds error as it goes outside of element')
log.warn('yOffset would cause a out of bounds error as it goes outside of element')
}
}
const moveToNested = async () => {
Expand Down

0 comments on commit 776ced4

Please sign in to comment.