Skip to content

Commit

Permalink
chore: 公共方法抽出
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng committed Nov 24, 2023
1 parent e1633c3 commit f631864
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions lib/next-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ const logger = require('./logger');
const _ = require('./helper');
const nextActions = {};

const locatorReturnLocatorCommonFuncs = [
'locator',
'getByRole',
'getByAltText',
'getByLabel',
'getByPlaceholder',
'getByTestId',
'getByText',
'getByTitle',
];

nextActions.fileChooser = async function(filePath) {
const fileChooser = await this.page.waitForEvent('filechooser');
await fileChooser.setFiles(filePath);
Expand Down Expand Up @@ -42,23 +53,14 @@ nextActions.locator = async function({ func, args }) {
// 返回locator对象时,缓存
if (
result
&& [
'and',
'or',
'getByRole',
'filter',
'first',
'getByAltText',
'getByLabel',
'getByPlaceholder',
'getByRole',
'getByTestId',
'getByText',
'getByTitle',
'last',
'locator',
'nth',
].includes(func)
&& locatorReturnLocatorCommonFuncs.concat([
'and',
'or',
'filter',
'first',
'last',
'nth',
]).includes(func)
) {
this.locator = result;
}
Expand All @@ -75,18 +77,10 @@ nextActions.page = async function({ func, args }) {
// 返回locator相关的方法时需要给 this.locator 赋值
if (
result
&& [
'locator',
'frameLocator',
'getByAltText',
'getByLabel',
'getByPlaceholder',
'getByRole',
'getByTestId',
'getByText',
'getByTitle',
'waitForSelector',
].includes(func)) {
&& locatorReturnLocatorCommonFuncs.concat([
'frameLocator',
'waitForSelector',
]).includes(func)) {
this.locator = result;
}
return result || '';
Expand Down Expand Up @@ -124,19 +118,11 @@ nextActions.pageIframe = async function({ index, func, args }) {
const result = await this.pageIframe[func].apply(this.pageIframe, args);
if (
result
&& [
'locator',
&& locatorReturnLocatorCommonFuncs.concat([
'frameLocator',
'frameElement',
'getByAltText',
'getByLabel',
'getByPlaceholder',
'getByRole',
'getByTestId',
'getByText',
'getByTitle',
'waitForSelector',
].includes(func)) {
]).includes(func)) {
this.locator = result;
}
return result || '';
Expand Down

0 comments on commit f631864

Please sign in to comment.