mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-28 13:21:42 +00:00
initial commit for notbooks pupeteer tests
This commit is contained in:
18
test/notebooks/notebookTestUtils.ts
Normal file
18
test/notebooks/notebookTestUtils.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Frame } from "puppeteer";
|
||||
|
||||
let testExplorerFrame: Frame;
|
||||
export async function getTestExplorerFrame(): Promise<Frame> {
|
||||
if (testExplorerFrame) {
|
||||
return testExplorerFrame;
|
||||
}
|
||||
|
||||
const prodUrl = "https://localhost:1234/testExplorer.html";
|
||||
await page.goto(prodUrl);
|
||||
const buttonHandle = await page.waitForSelector("button");
|
||||
buttonHandle.click();
|
||||
|
||||
const handle = await page.waitForSelector("iframe");
|
||||
testExplorerFrame = await handle.contentFrame();
|
||||
await testExplorerFrame.waitForSelector(".galleryHeader");
|
||||
return testExplorerFrame;
|
||||
}
|
||||
110
test/notebooks/testNotebooks/GettingStarted.ipynb
Normal file
110
test/notebooks/testNotebooks/GettingStarted.ipynb
Normal file
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "# Getting started with Cosmos notebooks\nIn this notebook, we'll learn how to use Cosmos notebook features. We'll create a database and container, import some sample data in a container in Azure Cosmos DB and run some queries over it."
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "### Create new database and container\n\nTo connect to the service, you can use our built-in instance of ```cosmos_client```. This is a ready to use instance of [CosmosClient](https://docs.microsoft.com/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python) from our Python SDK. It already has the context of this account baked in. We'll use ```cosmos_client``` to create a new database called **RetailDemo** and container called **WebsiteData**.\n\nOur dataset will contain events that occurred on the website - e.g. a user viewing an item, adding it to their cart, or purchasing it. We will partition by CartId, which represents the individual cart of each user. This will give us an even distribution of throughput and storage in our container. Learn more about how to [choose a good partition key.](https://docs.microsoft.com/azure/cosmos-db/partition-data)"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"trusted": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": "import azure.cosmos\nfrom azure.cosmos.partition_key import PartitionKey\n\ndatabase = cosmos_client.create_database_if_not_exists('RetailDemo')\nprint('Database RetailDemo created')\n\ncontainer = database.create_container_if_not_exists(id='WebsiteData', partition_key=PartitionKey(path='/CartID'))\nprint('Container WebsiteData created')\n"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "#### Set the default database and container context to the new resources\n\nWe can use the ```%database {database_id}``` and ```%container {container_id}``` syntax."
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"trusted": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": "%database RetailDemo"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"trusted": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": "%container WebsiteData"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "### Load in sample JSON data and insert into the container. \nWe'll use the **%%upload** magic function to insert items into the container"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"inputHidden": false,
|
||||
"outputHidden": false,
|
||||
"trusted": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": "%%upload --databaseName RetailDemo --containerName WebsiteData --url https://cosmosnotebooksdata.blob.core.windows.net/notebookdata/websiteData-small.json"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "The new database and container should show up under the **Data** section. Use the refresh icon after completing the previous cell. \n\n<img src=\"https://cosmosnotebooksdata.blob.core.windows.net/notebookdata/refreshData.png\" alt=\"Refresh Data resource tree to see newly created resources\" width=\"40%\"/>"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "### Run a query using the built-in Azure Cosmos notebook magic\n"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"trusted": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": "%%sql\nSELECT c.Action, c.Price as ItemRevenue, c.Country, c.Item FROM c"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "We can get more information about the %%sql command using ```%%sql?```"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": "### Next steps\n\nNow that you've learned how to use basic notebook functionality, follow the **Visualization.ipynb** notebook to further analyze and visualize our data. You can find it under the **Sample Notebooks** section."
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"version": "3.6.8"
|
||||
},
|
||||
"nteract": {
|
||||
"version": "dataExplorer 1.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
82
test/notebooks/uploadRunAndDeleteNotebook.spec.ts
Normal file
82
test/notebooks/uploadRunAndDeleteNotebook.spec.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import "expect-puppeteer";
|
||||
import { ElementHandle } from "puppeteer";
|
||||
import { getTestExplorerFrame } from "./notebookTestUtils";
|
||||
import * as path from "path"
|
||||
|
||||
jest.setTimeout(300000);
|
||||
const NOTEBOOK_OPERATION_DELAY = 2500;
|
||||
const RENDER_DELAY = 1000;
|
||||
|
||||
describe("sample", () => {
|
||||
it("portal login", async () => {
|
||||
const frame = await getTestExplorerFrame();
|
||||
|
||||
const notebookResourceTree = await frame.waitForSelector(".notebookResourceTree");
|
||||
const uploadNotebookPath = "C:/Users/srnara/Downloads/GettingStarted.ipynb";
|
||||
const uploadNotebookName = path.basename(uploadNotebookPath);
|
||||
|
||||
const treeNodeHeadersBeforeUpload = await notebookResourceTree.$$(".treeNodeHeader");
|
||||
|
||||
let ellipses = await treeNodeHeadersBeforeUpload[2].$("button");
|
||||
await ellipses.click();
|
||||
|
||||
await frame.waitFor(RENDER_DELAY);
|
||||
|
||||
let 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);
|
||||
|
||||
let uploadedNotebookNode: ElementHandle<Element>;
|
||||
const treeNodeHeadersAfterUpload = await notebookResourceTree.$$(".treeNodeHeader");
|
||||
for (var i = 1; i < treeNodeHeadersAfterUpload.length; i++) {
|
||||
uploadedNotebookNode = treeNodeHeadersAfterUpload[i];
|
||||
const nodeLabel = await uploadedNotebookNode.$eval(".nodeLabel", element => element.textContent);
|
||||
if (nodeLabel === uploadNotebookName) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await uploadedNotebookNode.click();
|
||||
await frame.waitForSelector(".tabNavText");
|
||||
const tabTitle = await frame.$eval(".tabNavText", element => element.textContent);
|
||||
expect(tabTitle).toEqual(uploadNotebookName);
|
||||
|
||||
const closeIcon = await frame.waitForSelector(".close-Icon");
|
||||
await closeIcon.click();
|
||||
|
||||
ellipses = await uploadedNotebookNode.$(".treeMenuEllipsis");
|
||||
await ellipses.click();
|
||||
|
||||
await frame.waitFor(RENDER_DELAY);
|
||||
|
||||
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);
|
||||
|
||||
let index: number;
|
||||
let deletedNotebookNode: ElementHandle<Element>;
|
||||
const treeNodeHeadersAfterDelete = await notebookResourceTree.$$(".treeNodeHeader");
|
||||
for (index = 1; index < treeNodeHeadersAfterDelete.length; index++) {
|
||||
deletedNotebookNode = treeNodeHeadersAfterDelete[index];
|
||||
const nodeLabel = await deletedNotebookNode.$eval(".nodeLabel", element => element.textContent);
|
||||
if (nodeLabel === uploadNotebookName) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
expect(index).toEqual(treeNodeHeadersAfterDelete.length);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,8 @@
|
||||
import crypto from "crypto";
|
||||
import { Frame } from "puppeteer";
|
||||
|
||||
let testExplorerFrame: Frame;
|
||||
|
||||
export async function login(connectionString: string): Promise<Frame> {
|
||||
const prodUrl = "https://localhost:1234/hostedExplorer.html";
|
||||
page.goto(prodUrl);
|
||||
|
||||
Reference in New Issue
Block a user