|
|
@ -1,5 +1,5 @@ |
|
|
|
// 找到控件区域点击
|
|
|
|
export function clickForce(ele: UiObject) { |
|
|
|
export function clickForce(ele: UiObject | null) { |
|
|
|
if (!ele) { |
|
|
|
console.log('控件不存在'); |
|
|
|
return; |
|
|
@ -19,3 +19,90 @@ export function clickForceXY(x: number, y: number, width: number, height: number |
|
|
|
click(x - 1, y + 1); |
|
|
|
click(x + 1, y - 1); |
|
|
|
} |
|
|
|
|
|
|
|
export function findNextElement(ele: UiSelector, nextEle: UiSelector, classNameString: string, step: number = 1) { |
|
|
|
const findit = ele.findOne(500); |
|
|
|
const finditNext = nextEle.findOne(500); |
|
|
|
if (!findit || !finditNext) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
const eles = className(classNameString).find(); |
|
|
|
const index = eles.findIndex((ele) => { |
|
|
|
if (ele.bounds().centerX() === findit.bounds().centerX() && ele.bounds().centerY() === findit.bounds().centerY()) { |
|
|
|
return ele; |
|
|
|
} |
|
|
|
}); |
|
|
|
if ( |
|
|
|
eles[index + step].bounds().centerX() === finditNext.bounds().centerX() && |
|
|
|
eles[index + step].bounds().width() === finditNext.bounds().width() && |
|
|
|
eles[index + step].bounds().height() === finditNext.bounds().height() && |
|
|
|
eles[index + step].bounds().centerY() === finditNext.bounds().centerY() |
|
|
|
) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
export function findPrevElement(ele: UiSelector, prevEle: UiSelector, classNameString: string, step: number = 1) { |
|
|
|
const findit = ele.findOne(500); |
|
|
|
const finditPrev = prevEle.findOne(500); |
|
|
|
if (!findit || !finditPrev) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
const eles = className(classNameString).find(); |
|
|
|
const index = eles.findIndex((ele) => { |
|
|
|
if (ele.bounds().centerX() === findit.bounds().centerX() && ele.bounds().centerY() === findit.bounds().centerY()) { |
|
|
|
return ele; |
|
|
|
} |
|
|
|
}); |
|
|
|
if ( |
|
|
|
eles[index - step].bounds().centerX() === finditPrev.bounds().centerX() && |
|
|
|
eles[index - step].bounds().width() === finditPrev.bounds().width() && |
|
|
|
eles[index - step].bounds().height() === finditPrev.bounds().height() && |
|
|
|
eles[index - step].bounds().centerY() === finditPrev.bounds().centerY() |
|
|
|
) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
export interface MakeSureOptions { |
|
|
|
hasModal?: (() => UiObject | null)[]; |
|
|
|
retry?: number; |
|
|
|
landOver?: (() => void)[]; |
|
|
|
} |
|
|
|
|
|
|
|
export function withMakeSure<T>( |
|
|
|
fn: () => T | null, |
|
|
|
options: { hasModal?: (() => UiObject | null)[]; retry?: number; landOver?: (() => void)[] } |
|
|
|
) { |
|
|
|
const { hasModal, landOver, retry = 5 } = options; |
|
|
|
let result = fn() || true; |
|
|
|
|
|
|
|
let whileNum = 0; |
|
|
|
let ok = false; |
|
|
|
|
|
|
|
while (!ok) { |
|
|
|
whileNum++; |
|
|
|
if (whileNum > retry) { |
|
|
|
result = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (hasModal) { |
|
|
|
const modals = hasModal.map((fn) => fn()); |
|
|
|
if (modals.length) { |
|
|
|
modals.forEach((modal) => { |
|
|
|
modal && clickForce(modal); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (landOver) { |
|
|
|
ok = landOver.every((fn) => fn()); |
|
|
|
} else { |
|
|
|
ok = true; |
|
|
|
} |
|
|
|
sleep(500); |
|
|
|
} |
|
|
|
console.log('fn:', fn, 'whileNum:', whileNum, 'result:', result); |
|
|
|
return result as T; |
|
|
|
} |
|
|
|