* test(e2e): Address deprecation * test(e2e): Add additional connection assertions on tests * CR: Fix flake when waiting for sessions If no sessions are available and the page needs to reload, we should wait to ensure that the page has loaded before checking what the state of the sessions are * CR: Address flake in connect methods Noticed an issue where a session recording was not playable. The theory is that the session didn't last long enough before it was cancelled. This adds a 2 second wait after establishing a connection before continuing. * CR: Use authenticated state by default * CR: Update dynamic host catalog assertion * CR: Simplify host set checks - Use .all() when looping - Add check to see if we need to reload the page or not * CR: Be more specific with locator Ran into a conflict with the Static/Dynamic host catalog type and the Static/Dynamic credential type. * CR: Update connection methods to be more resilient Rather than using a hardcoded sleep, we will now run a command on the target and wait for a specific string to return before continuing. * CR
109 lines
3.6 KiB
JavaScript
109 lines
3.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { expect } from '@playwright/test';
|
|
import { nanoid } from 'nanoid';
|
|
|
|
import { BaseResourcePage } from './base-resource.js';
|
|
|
|
export class HostCatalogsPage extends BaseResourcePage {
|
|
/**
|
|
* Creates a new host catalog. Assumes you have selected the desired project.
|
|
* @returns Name of the host catalog
|
|
*/
|
|
async createHostCatalog() {
|
|
const hostCatalogName = 'Host Catalog ' + nanoid();
|
|
await this.page
|
|
.getByRole('navigation', { name: 'Resources' })
|
|
.getByRole('link', { name: 'Host Catalogs' })
|
|
.click();
|
|
await expect(
|
|
this.page.getByRole('heading', { name: 'Host Catalogs' }),
|
|
).toBeVisible();
|
|
|
|
const newButtonIsVisible = await this.page
|
|
.getByRole('link', { name: 'New', exact: true })
|
|
.isVisible();
|
|
if (newButtonIsVisible) {
|
|
await this.page.getByRole('link', { name: 'New', exact: true }).click();
|
|
} else {
|
|
await this.page
|
|
.getByRole('link', { name: 'New Host Catalog', exact: true })
|
|
.click();
|
|
}
|
|
|
|
await this.page.getByLabel('Name').fill(hostCatalogName);
|
|
await this.page.getByLabel('Description').fill('This is an automated test');
|
|
await this.page
|
|
.getByRole('group', { name: 'Type', exact: 'true' })
|
|
.getByLabel('Static')
|
|
.click();
|
|
await this.page.getByRole('button', { name: 'Save' }).click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(
|
|
this.page
|
|
.getByRole('navigation', { name: 'breadcrumbs' })
|
|
.getByText(hostCatalogName),
|
|
).toBeVisible();
|
|
|
|
return hostCatalogName;
|
|
}
|
|
|
|
/**
|
|
* Creates a new host set. Assumes you have just created a new host catalog.
|
|
* @returns Name of the host set
|
|
*/
|
|
async createHostSet() {
|
|
const hostSetName = 'Host Set ' + nanoid();
|
|
await this.page.getByRole('link', { name: 'Host Sets' }).click();
|
|
await expect(
|
|
this.page
|
|
.getByRole('navigation', { name: 'breadcrumbs' })
|
|
.getByText('Host Sets'),
|
|
).toBeVisible();
|
|
|
|
const emptyLinkIsVisible = await this.page
|
|
.getByRole('link', { name: 'New', exact: true })
|
|
.isVisible();
|
|
if (emptyLinkIsVisible) {
|
|
await this.page.getByRole('link', { name: 'New', exact: true }).click();
|
|
} else {
|
|
await this.page.getByText('Manage').click();
|
|
await this.page.getByRole('link', { name: 'New Host Set' }).click();
|
|
}
|
|
|
|
await this.page.getByLabel('Name').fill(hostSetName);
|
|
await this.page.getByLabel('Description').fill('This is an automated test');
|
|
await this.page.getByRole('button', { name: 'Save' }).click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(
|
|
this.page
|
|
.getByRole('navigation', { name: 'breadcrumbs' })
|
|
.getByText(hostSetName),
|
|
).toBeVisible();
|
|
|
|
return hostSetName;
|
|
}
|
|
|
|
/**
|
|
* Creates a new host in a host set. Assumes you have just created a new host set.
|
|
* @param {string} address Address of the host
|
|
* @returns Name of the host
|
|
*/
|
|
async createHostInHostSet(address) {
|
|
const hostName = 'Host ' + nanoid();
|
|
await this.page.getByText('Manage').click();
|
|
await this.page.getByRole('link', { name: 'Create and Add Host' }).click();
|
|
await this.page.getByLabel('Name').fill(hostName);
|
|
await this.page.getByLabel('Description').fill('This is an automated test');
|
|
await this.page.getByLabel('Address').fill(address);
|
|
await this.page.getByRole('button', { name: 'Save' }).click();
|
|
await this.dismissSuccessAlert();
|
|
await expect(this.page.getByRole('link', { name: hostName })).toBeVisible();
|
|
|
|
return hostName;
|
|
}
|
|
}
|