2020-12-28 23:50:12 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
*
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
*
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
export type ActionName =
|
|
|
|
|
|
'check' |
|
|
|
|
|
|
'click' |
|
|
|
|
|
|
'closePage' |
|
|
|
|
|
|
'fill' |
|
|
|
|
|
|
'navigate' |
|
|
|
|
|
|
'openPage' |
|
|
|
|
|
|
'press' |
|
|
|
|
|
|
'select' |
|
|
|
|
|
|
'uncheck' |
|
|
|
|
|
|
'setInputFiles';
|
|
|
|
|
|
|
|
|
|
|
|
export type ActionBase = {
|
|
|
|
|
|
name: ActionName,
|
|
|
|
|
|
signals: Signal[],
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export type ClickAction = ActionBase & {
|
|
|
|
|
|
name: 'click',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
button: 'left' | 'middle' | 'right',
|
|
|
|
|
|
modifiers: number,
|
|
|
|
|
|
clickCount: number,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type CheckAction = ActionBase & {
|
|
|
|
|
|
name: 'check',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type UncheckAction = ActionBase & {
|
|
|
|
|
|
name: 'uncheck',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type FillAction = ActionBase & {
|
|
|
|
|
|
name: 'fill',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
text: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type NavigateAction = ActionBase & {
|
|
|
|
|
|
name: 'navigate',
|
|
|
|
|
|
url: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type OpenPageAction = ActionBase & {
|
|
|
|
|
|
name: 'openPage',
|
|
|
|
|
|
url: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type ClosesPageAction = ActionBase & {
|
|
|
|
|
|
name: 'closePage',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type PressAction = ActionBase & {
|
|
|
|
|
|
name: 'press',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
key: string,
|
|
|
|
|
|
modifiers: number,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type SelectAction = ActionBase & {
|
|
|
|
|
|
name: 'select',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
options: string[],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type SetInputFilesAction = ActionBase & {
|
|
|
|
|
|
name: 'setInputFiles',
|
|
|
|
|
|
selector: string,
|
|
|
|
|
|
files: string[],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type Action = ClickAction | CheckAction | ClosesPageAction | OpenPageAction | UncheckAction | FillAction | NavigateAction | PressAction | SelectAction | SetInputFilesAction;
|
|
|
|
|
|
|
|
|
|
|
|
// Signals.
|
|
|
|
|
|
|
2021-02-17 03:13:26 +01:00
|
|
|
|
export type BaseSignal = {
|
|
|
|
|
|
isAsync?: boolean,
|
2021-02-17 23:05:41 +01:00
|
|
|
|
};
|
2021-02-17 03:13:26 +01:00
|
|
|
|
|
|
|
|
|
|
export type NavigationSignal = BaseSignal & {
|
2020-12-28 23:50:12 +01:00
|
|
|
|
name: 'navigation',
|
|
|
|
|
|
url: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-02-17 03:13:26 +01:00
|
|
|
|
export type PopupSignal = BaseSignal & {
|
2020-12-28 23:50:12 +01:00
|
|
|
|
name: 'popup',
|
|
|
|
|
|
popupAlias: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-02-17 03:13:26 +01:00
|
|
|
|
export type DownloadSignal = BaseSignal & {
|
2020-12-28 23:50:12 +01:00
|
|
|
|
name: 'download',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-02-17 03:13:26 +01:00
|
|
|
|
export type DialogSignal = BaseSignal & {
|
2020-12-28 23:50:12 +01:00
|
|
|
|
name: 'dialog',
|
|
|
|
|
|
dialogAlias: string,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type Signal = NavigationSignal | PopupSignal | DownloadSignal | DialogSignal;
|
|
|
|
|
|
|
|
|
|
|
|
export function actionTitle(action: Action): string {
|
|
|
|
|
|
switch (action.name) {
|
|
|
|
|
|
case 'openPage':
|
|
|
|
|
|
return `Open new page`;
|
|
|
|
|
|
case 'closePage':
|
|
|
|
|
|
return `Close page`;
|
|
|
|
|
|
case 'check':
|
|
|
|
|
|
return `Check ${action.selector}`;
|
|
|
|
|
|
case 'uncheck':
|
|
|
|
|
|
return `Uncheck ${action.selector}`;
|
|
|
|
|
|
case 'click': {
|
|
|
|
|
|
if (action.clickCount === 1)
|
|
|
|
|
|
return `Click ${action.selector}`;
|
|
|
|
|
|
if (action.clickCount === 2)
|
|
|
|
|
|
return `Double click ${action.selector}`;
|
|
|
|
|
|
if (action.clickCount === 3)
|
|
|
|
|
|
return `Triple click ${action.selector}`;
|
|
|
|
|
|
return `${action.clickCount}× click`;
|
|
|
|
|
|
}
|
|
|
|
|
|
case 'fill':
|
|
|
|
|
|
return `Fill ${action.selector}`;
|
|
|
|
|
|
case 'setInputFiles':
|
|
|
|
|
|
if (action.files.length === 0)
|
|
|
|
|
|
return `Clear selected files`;
|
|
|
|
|
|
else
|
|
|
|
|
|
return `Upload ${action.files.join(', ')}`;
|
|
|
|
|
|
case 'navigate':
|
|
|
|
|
|
return `Go to ${action.url}`;
|
|
|
|
|
|
case 'press':
|
|
|
|
|
|
return `Press ${action.key}` + (action.modifiers ? ' with modifiers' : '');
|
|
|
|
|
|
case 'select':
|
|
|
|
|
|
return `Select ${action.options.join(', ')}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|