-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspaces.js
72 lines (58 loc) · 2.01 KB
/
workspaces.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { By, until } = require('selenium-webdriver');
const { getDownloadedWorkspaces } = require('../util');
const WORKSPACES_URL = `https://c9.io/${process.env.USERNAME}`;
const MIGRATE_URL_REGEX = new RegExp(`/${process.env.USERNAME}/(.+)/migrate$`);
const PREPARE_TO_DOWNLOAD_BUTTON_LOCATOR = By.xpath(
'//span[contains(text(), "Prepare to Download / Migrate")]',
);
const DOWNLOAD_LINK_LOCATOR = By.xpath('//a[text()="Download / Migrate"]');
const MODAL_LOCATOR = By.css('.modal');
const ARCHIVE_BUTTON_LOCATOR = By.xpath('//button[text()="Archive"]');
class WorkspacesPage {
/**
* @param {ThenableWebDriver} driver
*/
constructor(driver) {
this.driver = driver;
}
async goToWorkspaces() {
await this.driver.get(WORKSPACES_URL);
}
async prepareToDownload() {
const { driver } = this;
const prepareToDownloadButtons = await driver.findElements(
PREPARE_TO_DOWNLOAD_BUTTON_LOCATOR,
);
for (const prepareToDownloadButton of prepareToDownloadButtons) {
await prepareToDownloadButton.click();
await driver.wait(until.elementLocated(MODAL_LOCATOR));
const archiveButton = await driver.wait(
until.elementLocated(ARCHIVE_BUTTON_LOCATOR),
);
await archiveButton.click();
await driver.wait(async () => {
const elements = await driver.findElements(MODAL_LOCATOR);
return elements.length === 0;
});
}
}
/**
* @return {string}
*/
async getWorkspaceToDownload() {
const { driver } = this;
const downloadLinks = await driver.findElements(DOWNLOAD_LINK_LOCATOR);
for (let downloadLink of downloadLinks) {
const href = await downloadLink.getAttribute('href');
const match = href.match(MIGRATE_URL_REGEX);
if (Array.isArray(match)) {
const downloadedWorkspaces = await getDownloadedWorkspaces();
const workspaceName = match[1];
if (!downloadedWorkspaces.includes(workspaceName)) {
return workspaceName;
}
}
}
}
}
module.exports = WorkspacesPage;