-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathplugins.ts
More file actions
55 lines (45 loc) · 1.51 KB
/
plugins.ts
File metadata and controls
55 lines (45 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { logger } from '@twilio/flex-dev-utils';
import { ElementHandle, Page } from 'puppeteer';
import { Base } from './base';
interface PluginResponse {
name: string;
version: string;
phase: number;
src: string;
}
export class Plugins extends Base {
private static readonly _pluginList = 'pre';
assert = {
plugin: {
/**
* Checks whether plugin with the given text is visible in the UI
* @param pluginText
*/
isVisible: async (pluginText: string): Promise<ElementHandle<Element | Node>> =>
this.elementVisible(this._plugin(pluginText), `Plugin with text: ${pluginText}`),
},
};
private readonly _baseUrl: string;
constructor(page: Page, baseUrl: string) {
super(page);
this._baseUrl = baseUrl.includes('flex.local.com') ? 'https://flex.twilio.com' : baseUrl;
}
/**
* Retrieves all plugins from /plugins
*/
async list(): Promise<PluginResponse[]> {
await this.goto({ baseUrl: this._baseUrl, path: '/plugins' });
const pluginListElementHandle = await this.elementVisible(Plugins._pluginList, 'Plugins in PRE tag');
const pluginListAsString = await this.getText(pluginListElementHandle, 'Plugins in PRE tag');
try {
return JSON.parse(pluginListAsString);
} catch (e) {
logger.error('Plugin list retrieved from the /plugins is not a valid JSON');
throw e;
}
}
/**
* Creates selector for plugin based on its text
*/
private _plugin = (text: string): string => `//div[contains(text(), '${text}')]`;
}