Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): add connectionName support to more helpers COMPASS-8002 #6033

Merged
merged 21 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Selectors from '../selectors';

async function navigateToCollection(
browser: CompassBrowser,
// TODO(COMPASS-8002): take connectionName into account
connectionName: string,
dbName: string,
collectionName: string,

Expand All @@ -12,7 +12,10 @@ async function navigateToCollection(
// state of Schema, and Validation tabs without re-connecting.
closeExistingTabs = true
): Promise<void> {
const connectionId = await browser.getConnectionIdByName(connectionName);

const collectionSelector = Selectors.sidebarCollection(
connectionId,
dbName,
collectionName
);
Expand All @@ -30,12 +33,17 @@ async function navigateToCollection(

// click it and wait for the collection header to become visible
await browser.clickVisible(collectionSelector);
await waitUntilActiveCollectionTab(browser, dbName, collectionName);
await waitUntilActiveCollectionTab(
browser,
connectionName,
dbName,
collectionName
);
}

export async function navigateToCollectionTab(
browser: CompassBrowser,
// TODO(COMPASS-8002): take connectionName into account
connectionName: string,
dbName: string,
collectionName: string,
tabName:
Expand All @@ -48,6 +56,7 @@ export async function navigateToCollectionTab(
): Promise<void> {
await navigateToCollection(
browser,
connectionName,
dbName,
collectionName,
closeExistingTabs
Expand All @@ -57,7 +66,6 @@ export async function navigateToCollectionTab(

export async function navigateWithinCurrentCollectionTabs(
browser: CompassBrowser,
// TODO(COMPASS-8002): take connectionName into account
tabName:
| 'Documents'
| 'Aggregations'
Expand All @@ -77,9 +85,9 @@ export async function navigateWithinCurrentCollectionTabs(
await waitUntilActiveCollectionSubTab(browser, tabName);
}

export async function waitUntilActiveCollectionTab(
async function waitUntilActiveCollectionTab(
browser: CompassBrowser,
// TODO(COMPASS-8002): take connectionName into account
connectionName: string,
dbName: string,
collectionName: string,
tabName:
Expand All @@ -91,7 +99,13 @@ export async function waitUntilActiveCollectionTab(
| null = null
) {
await browser
.$(Selectors.collectionWorkspaceTab(`${dbName}.${collectionName}`, true))
.$(
Selectors.workspaceTab({
connectionName,
namespace: `${dbName}.${collectionName}`,
active: true,
})
)
.waitForDisplayed();
if (tabName) {
await waitUntilActiveCollectionSubTab(browser, tabName);
Expand All @@ -100,7 +114,6 @@ export async function waitUntilActiveCollectionTab(

export async function waitUntilActiveCollectionSubTab(
browser: CompassBrowser,
// TODO(COMPASS-8002): take connectionName into account
tabName:
| 'Documents'
| 'Aggregations'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import type { WorkspaceTabSelectorOptions } from '../selectors';

export async function navigateToConnectionTab(
browser: CompassBrowser,
Expand Down Expand Up @@ -30,8 +31,13 @@ export async function waitUntilActiveConnectionTab(
connectionName: string,
tabName: 'Performance' | 'Databases'
) {
// TODO(COMPASS-8002): we should differentiate by connectionName somehow
await browser
.$(Selectors.connectionWorkspaceTab(tabName, true))
.waitForDisplayed();
const options: WorkspaceTabSelectorOptions = { title: tabName, active: true };

// Only add the connectionName for multiple connections because for some
// reason this sometimes flakes in single connections even though the tab is
// definitely there in the screenshot.
if (TEST_MULTIPLE_CONNECTIONS) {
options.connectionName = connectionName;
}
await browser.$(Selectors.workspaceTab(options)).waitForDisplayed();
}
16 changes: 12 additions & 4 deletions packages/compass-e2e-tests/helpers/commands/database-workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import type { WorkspaceTabSelectorOptions } from '../selectors';

export async function navigateToDatabaseCollectionsTab(
browser: CompassBrowser,
Expand All @@ -16,8 +18,14 @@ export async function waitUntilActiveDatabaseTab(
connectionName: string,
dbName: string
) {
// TODO(COMPASS-8002): check that the connectionName matches too
await browser
.$(Selectors.databaseWorkspaceTab(dbName, true))
.waitForDisplayed();
const options: WorkspaceTabSelectorOptions = { title: dbName, active: true };

// Only add the connectionName for multiple connections because for some
// reason this sometimes flakes in single connections even though the tab is
// definitely there in the screenshot.
if (TEST_MULTIPLE_CONNECTIONS) {
options.connectionName = connectionName;
}

await browser.$(Selectors.workspaceTab(options)).waitForDisplayed();
}
10 changes: 7 additions & 3 deletions packages/compass-e2e-tests/helpers/commands/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ export async function disconnectAll(
// toast by now. If so, just close it otherwise the next test or connection
// attempt will be confused by it.
if (await browser.$(Selectors.LGToastCloseButton).isExisting()) {
const toastText = await browser.$('#lg-toast-region').getText();
debug('Closing toast', toastText);
await browser.clickVisible(Selectors.LGToastCloseButton);
try {
const toastText = await browser.$('#lg-toast-region').getText();
debug('Closing toast', toastText);
await browser.clickVisible(Selectors.LGToastCloseButton);
} catch (error) {
debug('ignoring', error);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import * as Selectors from '../selectors';

export async function dropCollectionFromSidebar(
browser: CompassBrowser,
connectionName: string,
dbName: string,
collectionName: string
): Promise<void> {
const connectionId = await browser.getConnectionIdByName(connectionName);

// search for the collecton in the sidebar filter
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, collectionName);
const dbElement = await browser.$(Selectors.sidebarDatabase(dbName));
const dbElement = await browser.$(
Selectors.sidebarDatabase(connectionId, dbName)
);
await dbElement.waitForDisplayed();

// wait for the collection to become displayed
const collectionSelector = Selectors.sidebarCollection(
connectionId,
dbName,
collectionName
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import * as Selectors from '../selectors';

export async function dropDatabaseFromSidebar(
browser: CompassBrowser,
connectionName: string,
dbName: string
): Promise<void> {
const connectionId = await browser.getConnectionIdByName(connectionName);

// search for the database in the sidebar filter
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, dbName);
await browser.$(Selectors.sidebarDatabase(dbName)).waitForDisplayed();
await browser
.$(Selectors.sidebarDatabase(connectionId, dbName))
.waitForDisplayed();

// open the drop database modal from the sidebar
await browser.hover(Selectors.sidebarDatabase(dbName));
await browser.hover(Selectors.sidebarDatabase(connectionId, dbName));

await browser.clickVisible(Selectors.DropDatabaseButton);

await browser.dropNamespace(dbName);

// wait for it to be gone
await browser
.$(Selectors.sidebarDatabase(dbName))
.$(Selectors.sidebarDatabase(connectionId, dbName))
.waitForExist({ reverse: true });
}
4 changes: 1 addition & 3 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export * from './get-feature';
export * from './set-feature';
export * from './save-favorite';
export * from './save-connection-string-as-favorite';
export * from './select-connection';
export * from './select-connection-menu-item';
export * from './sidebar-connection';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I combined a bunch of sidebar connection related commands into one file to mirror what we do for workspace management already. Otherwise it is a bit of a proliferation of little files. It might also help if we do move these to page objects because they'd already be together.

export * from './select-connections-menu-item';
export * from './open-settings-modal';
export * from './wait-for-connection-result';
Expand All @@ -67,4 +66,3 @@ export * from './drop-index';
export * from './hide-index';
export * from './unhide-index';
export * from './hide-visible-toasts';
export * from './remove-connection';
31 changes: 0 additions & 31 deletions packages/compass-e2e-tests/helpers/commands/remove-connection.ts

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions packages/compass-e2e-tests/helpers/commands/select-connection.ts

This file was deleted.

Loading
Loading