2020-11-13 14:27:27 -08:00
|
|
|
import { ElementHandle, Frame } from "puppeteer";
|
2020-11-17 03:50:12 -08:00
|
|
|
import { TestExplorerParams } from "./testExplorer/TestExplorerParams";
|
2020-11-13 14:27:27 -08:00
|
|
|
|
|
|
|
export const NOTEBOOK_OPERATION_DELAY = 5000;
|
|
|
|
export const RENDER_DELAY = 1000;
|
2020-11-11 04:53:04 -08:00
|
|
|
|
|
|
|
let testExplorerFrame: Frame;
|
2020-11-13 14:27:27 -08:00
|
|
|
export const getTestExplorerFrame = async (): Promise<Frame> => {
|
2020-11-11 04:53:04 -08:00
|
|
|
if (testExplorerFrame) {
|
|
|
|
return testExplorerFrame;
|
|
|
|
}
|
|
|
|
|
2020-11-17 11:05:17 -08:00
|
|
|
const notebooksTestRunnerTenantId = process.env.NOTEBOOKS_TEST_RUNNER_TENANT_ID;
|
2020-11-13 14:27:27 -08:00
|
|
|
const notebooksTestRunnerClientId = process.env.NOTEBOOKS_TEST_RUNNER_CLIENT_ID;
|
|
|
|
const notebooksTestRunnerClientSecret = process.env.NOTEBOOKS_TEST_RUNNER_CLIENT_SECRET;
|
2020-11-17 11:05:17 -08:00
|
|
|
const portalRunnerDatabaseAccount = process.env.PORTAL_RUNNER_DATABASE_ACCOUNT;
|
2020-11-17 11:29:46 -08:00
|
|
|
const portalRunnerDatabaseAccountKey = process.env.PORTAL_RUNNER_DATABASE_ACCOUNT_KEY;
|
2020-11-17 11:05:17 -08:00
|
|
|
const portalRunnerSubscripton = process.env.PORTAL_RUNNER_SUBSCRIPTION;
|
|
|
|
const portalRunnerResourceGroup = process.env.PORTAL_RUNNER_RESOURCE_GROUP;
|
2020-11-13 14:27:27 -08:00
|
|
|
|
2020-11-17 03:50:12 -08:00
|
|
|
const testExplorerUrl = new URL("testExplorer.html", "https://localhost:1234");
|
|
|
|
testExplorerUrl.searchParams.append(
|
2020-11-17 11:05:17 -08:00
|
|
|
TestExplorerParams.notebooksTestRunnerTenantId,
|
|
|
|
encodeURI(notebooksTestRunnerTenantId)
|
2020-11-17 03:50:12 -08:00
|
|
|
);
|
|
|
|
testExplorerUrl.searchParams.append(
|
|
|
|
TestExplorerParams.notebooksTestRunnerClientId,
|
|
|
|
encodeURI(notebooksTestRunnerClientId)
|
|
|
|
);
|
|
|
|
testExplorerUrl.searchParams.append(
|
|
|
|
TestExplorerParams.notebooksTestRunnerClientSecret,
|
|
|
|
encodeURI(notebooksTestRunnerClientSecret)
|
|
|
|
);
|
|
|
|
testExplorerUrl.searchParams.append(
|
2020-11-17 11:05:17 -08:00
|
|
|
TestExplorerParams.portalRunnerDatabaseAccount,
|
|
|
|
encodeURI(portalRunnerDatabaseAccount)
|
2020-11-17 03:50:12 -08:00
|
|
|
);
|
2020-11-17 11:37:48 -08:00
|
|
|
testExplorerUrl.searchParams.append(
|
|
|
|
TestExplorerParams.portalRunnerDatabaseAccountKey,
|
|
|
|
encodeURI(portalRunnerDatabaseAccountKey)
|
|
|
|
);
|
2020-11-17 11:05:17 -08:00
|
|
|
testExplorerUrl.searchParams.append(TestExplorerParams.portalRunnerSubscripton, encodeURI(portalRunnerSubscripton));
|
2020-11-17 03:50:12 -08:00
|
|
|
testExplorerUrl.searchParams.append(
|
2020-11-17 11:05:17 -08:00
|
|
|
TestExplorerParams.portalRunnerResourceGroup,
|
|
|
|
encodeURI(portalRunnerResourceGroup)
|
2020-11-17 03:50:12 -08:00
|
|
|
);
|
2020-11-13 14:27:27 -08:00
|
|
|
|
2020-11-17 03:50:12 -08:00
|
|
|
await page.goto(testExplorerUrl.toString());
|
2020-11-11 04:53:04 -08:00
|
|
|
|
|
|
|
const handle = await page.waitForSelector("iframe");
|
|
|
|
testExplorerFrame = await handle.contentFrame();
|
|
|
|
await testExplorerFrame.waitForSelector(".galleryHeader");
|
|
|
|
return testExplorerFrame;
|
2020-11-13 14:27:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const uploadNotebook = async (frame: Frame, uploadNotebookPath: string): Promise<void> => {
|
|
|
|
const notebookResourceTree = await frame.waitForSelector(".notebookResourceTree");
|
|
|
|
|
|
|
|
const treeNodeHeadersBeforeUpload = await notebookResourceTree.$$(".treeNodeHeader");
|
|
|
|
|
|
|
|
const ellipses = await treeNodeHeadersBeforeUpload[2].$("button");
|
|
|
|
await ellipses.click();
|
|
|
|
|
|
|
|
await frame.waitFor(RENDER_DELAY);
|
|
|
|
|
|
|
|
const menuItems = await frame.$$(".ms-ContextualMenu-item");
|
|
|
|
await menuItems[4].click();
|
|
|
|
|
|
|
|
const uploadFileButton = await frame.waitForSelector("#importFileButton");
|
|
|
|
uploadFileButton.click();
|
|
|
|
|
|
|
|
const fileChooser = await page.waitForFileChooser();
|
|
|
|
fileChooser.accept([uploadNotebookPath]);
|
|
|
|
|
|
|
|
const submitButton = await frame.waitForSelector("#uploadFileButton");
|
|
|
|
await submitButton.click();
|
|
|
|
|
|
|
|
await frame.waitFor(NOTEBOOK_OPERATION_DELAY);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getNotebookNode = async (frame: Frame, uploadNotebookName: string): Promise<ElementHandle<Element>> => {
|
|
|
|
const notebookResourceTree = await frame.waitForSelector(".notebookResourceTree");
|
|
|
|
let currentNotebookNode: ElementHandle<Element>;
|
|
|
|
|
|
|
|
const treeNodeHeaders = await notebookResourceTree.$$(".treeNodeHeader");
|
|
|
|
for (let i = 1; i < treeNodeHeaders.length; i++) {
|
|
|
|
currentNotebookNode = treeNodeHeaders[i];
|
|
|
|
const nodeLabel = await currentNotebookNode.$eval(".nodeLabel", element => element.textContent);
|
|
|
|
if (nodeLabel === uploadNotebookName) {
|
|
|
|
return currentNotebookNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteNotebook = async (frame: Frame, notebookNodeToDelete: ElementHandle<Element>): Promise<void> => {
|
|
|
|
const ellipses = await notebookNodeToDelete.$(".treeMenuEllipsis");
|
|
|
|
await ellipses.click();
|
|
|
|
|
|
|
|
await frame.waitFor(RENDER_DELAY);
|
|
|
|
|
|
|
|
const menuItems = await frame.$$(".ms-ContextualMenu-item");
|
|
|
|
await menuItems[1].click();
|
|
|
|
|
|
|
|
const deleteAcceptButton = await frame.waitForSelector(".ms-Dialog-action");
|
|
|
|
await deleteAcceptButton.click();
|
|
|
|
await frame.waitFor(NOTEBOOK_OPERATION_DELAY);
|
|
|
|
};
|