Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms committed Dec 4, 2024
1 parent febc683 commit a315db5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, test} from '@playwright/test';
import {dotCMSUtils} from '../../utils/dotCMSUtils';
import {dotCMSUtils, waitForVisibleAndCallback} from '../../utils/dotCMSUtils';
import {ContentUtils} from '../../utils/contentUtils';
import {addContent, iFramesLocators, richText} from '../../locators/globalLocators';
import {
Expand Down Expand Up @@ -30,6 +30,9 @@ test.beforeEach('Navigate to content portlet', async ({page}) => {
await cmsUtils.navigate(menuLocators.EXPAND, groupsLocators.CONTENT, toolsLocators.SEARCH_ALL);

// Validate the portlet title
const breadcrumbLocator = page.locator('p-breadcrumb');
await waitForVisibleAndCallback(breadcrumbLocator, () => expect(breadcrumbLocator).toContainText('Search All'));

await expect(page.locator('p-breadcrumb')).toContainText('Search All');
});

Expand Down Expand Up @@ -151,16 +154,20 @@ test("Validate the clear button in the search filter", async ({page}) => {
const iframe = page.frameLocator(iFramesLocators.main_iframe);

//expand the search filter
await iframe.getByRole('link', {name: 'Advanced'}).click();
const advancedLinkLocator = iframe.getByRole('link', {name: 'Advanced'});
await waitForVisibleAndCallback(advancedLinkLocator, () => advancedLinkLocator.click());

// Select the workflow in the search filter
await iframe.locator('#widget_scheme_id [data-dojo-attach-point="_buttonNode"]').click();
await iframe.getByRole('option', {name: 'System Workflow'}).click();
//TODO remove this
await page.waitForTimeout(1000);

// Select the step in the search filter
await iframe.locator('div[id=\'widget_step_id\'] div[data-dojo-attach-point=\'_buttonNode\']').click();
await iframe.getByRole('option', {name: 'New'}).click();
const widgetStepIdLocator = iframe.locator('div[id=\'widget_step_id\'] div[data-dojo-attach-point=\'_buttonNode\']');
await waitForVisibleAndCallback(widgetStepIdLocator, () => widgetStepIdLocator.click());
const newOption = iframe.getByRole('option', {name: 'New'});
await waitForVisibleAndCallback(newOption, () => newOption.click());

// Select the Show in the search filter
await iframe.locator('#widget_showingSelect [data-dojo-attach-point="_buttonNode"]').click();
Expand All @@ -183,7 +190,8 @@ test('Validate the hide button collapse the filter', async ({page}) => {
const iframe = page.frameLocator(iFramesLocators.main_iframe);

await expect(iframe.getByRole('button', {name: 'Search'})).toBeVisible();
await iframe.getByRole('link', {name: 'Advanced'}).click();
let advancedLinkLocator = iframe.getByRole('link', {name: 'Advanced'});
await waitForVisibleAndCallback(advancedLinkLocator, () => advancedLinkLocator.click());

await page.waitForTimeout(1000);
await expect(iframe.getByRole('link', {name: 'Advanced'})).not.toBeVisible();
Expand All @@ -195,5 +203,3 @@ test('Validate the hide button collapse the filter', async ({page}) => {
// Validate the filter has been collapsed
await expect(iframe.getByRole('link', {name: 'Advanced'})).toBeVisible();
});


8 changes: 6 additions & 2 deletions e2e/dotcms-e2e-node/frontend/tests/login/translations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect, test} from '@playwright/test';
import {assert} from 'console';
import {waitForVisibleAndCallback} from "../../utils/dotCMSUtils";

const languages = [
{language: 'español (España)', translation: '¡Bienvenido!'},
Expand All @@ -20,8 +21,11 @@ languages.forEach(list => {
const {language, translation} = list;

await page.goto('/dotAdmin');
await page.getByLabel('dropdown trigger').click();
await page.getByText(language).click();
const dropdownTriggerLocator = page.getByLabel('dropdown trigger');
await waitForVisibleAndCallback(dropdownTriggerLocator, () => dropdownTriggerLocator.click());

const pageByTextLocator = page.getByText(language);
await waitForVisibleAndCallback(pageByTextLocator, () => pageByTextLocator.click());

// Assertion of the translation
assert(await expect(page.getByTestId('header')).toContainText(translation));
Expand Down
27 changes: 17 additions & 10 deletions e2e/dotcms-e2e-node/frontend/utils/contentUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Page, expect, FrameLocator} from '@playwright/test';
import { iFramesLocators, richText } from '../locators/globalLocators';
import { waitForAndExpect } from './dotCMSUtils'
import exp = require("node:constants");
import { waitForVisibleAndCallback} from './dotCMSUtils';

export class ContentUtils {
page: Page;
Expand All @@ -18,7 +17,9 @@ export class ContentUtils {
*/
async fillRichTextForm(page: Page, title: string, body: string, action: string) {
const dotIframe = page.frameLocator(iFramesLocators.dot_iframe);
await expect.soft( page.getByRole('heading')).toContainText(richText.label);

const headingLocator = page.getByRole('heading');
await waitForVisibleAndCallback(headingLocator, () => expect.soft(headingLocator).toContainText(richText.label));

//Fill title
await dotIframe.locator('#title').fill(title);
Expand All @@ -30,11 +31,11 @@ export class ContentUtils {
await dotIframe.getByText(action).click();
//Wait for the content to be saved


await expect(dotIframe.getByText('Content saved')).toBeVisible({ timeout: 9000 });
await expect(dotIframe.getByText('Content saved')).toBeHidden();
//Click on close
await page.getByTestId('close-button').getByRole('button').click();
const closeBtnLocator = page.getByTestId('close-button').getByRole('button');
await waitForVisibleAndCallback(closeBtnLocator, () => closeBtnLocator.click());
}

/**
Expand All @@ -46,16 +47,21 @@ export class ContentUtils {
async addNewContentAction(page: Page, typeLocator: string, typeString: string) {
const iframe = page.frameLocator(iFramesLocators.main_iframe);
const structureINodeLocator = iframe.locator('#structure_inode');
await waitForAndExpect(structureINodeLocator, 'visible', () => expect(structureINodeLocator).toBeVisible());
await waitForVisibleAndCallback(structureINodeLocator, () => expect(structureINodeLocator).toBeVisible());
//TODO remove this
await page.waitForTimeout(1000);
await iframe.locator('#widget_structure_inode div').first().click();
const structureINodeDivLocator = iframe.locator('#widget_structure_inode div').first();
await waitForVisibleAndCallback(structureINodeDivLocator, () => structureINodeDivLocator.click());
//TODO remove this
await page.waitForTimeout(1000);
await iframe.getByText(typeLocator).click();
const typeLocatorByTextLocator = iframe.getByText(typeLocator);
await waitForVisibleAndCallback(typeLocatorByTextLocator, () => typeLocatorByTextLocator.click());

await iframe.locator('#dijit_form_DropDownButton_0').click();
await expect(iframe.getByLabel('actionPrimaryMenu')).toBeVisible();
await iframe.getByLabel('▼').getByText('Add New Content').click();
const headingLocator = page.getByRole('heading');
await waitForAndExpect(headingLocator, 'visible', () => expect(headingLocator).toHaveText(typeString));
await waitForVisibleAndCallback(headingLocator, () => expect(headingLocator).toHaveText(typeString));
};

/**
Expand All @@ -77,7 +83,8 @@ export class ContentUtils {
* @param iframe
*/
async showQuery(iframe : FrameLocator) {
await iframe.getByRole('button', { name: 'createOptions' }).click();
const createOptionsBtnLocator = iframe.getByRole('button', { name: 'createOptions' });
await waitForVisibleAndCallback(createOptionsBtnLocator, () => createOptionsBtnLocator.click());

//Validate the search button has a sub-menu
await expect (iframe.getByLabel('Search ▼').getByText('Search')).toBeVisible();
Expand Down
19 changes: 14 additions & 5 deletions e2e/dotcms-e2e-node/frontend/utils/dotCMSUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Page, expect, Locator } from '@playwright/test';
import { loginLocators } from '../locators/globalLocators';

export const waitForAndExpect = async (locator: Locator, state: "attached" | "detached" | "visible" | "hidden", expectFn: () => Promise<void>): Promise<void> => {
await locator.waitFor({state: state})
await expectFn();
export const waitFor = async (locator: Locator, state: "attached" | "detached" | "visible" | "hidden"): Promise<void> => {
await locator.waitFor({state: state});
}

export const waitForAndCallback = async (locator: Locator, state: "attached" | "detached" | "visible" | "hidden", callback: () => Promise<void>): Promise<void> => {
await waitFor(locator, state);
await callback();
};

export const waitForVisibleAndCallback = async (locator: Locator, callback: () => Promise<void>): Promise<void> => {
await waitForAndCallback(locator, 'visible', callback);
};

export class dotCMSUtils {
Expand All @@ -20,9 +28,10 @@ export class dotCMSUtils {
await page.waitForLoadState()
await page.fill(loginLocators.userNameInput, username);
await page.fill(loginLocators.passwordInput, password);
await page.getByTestId(loginLocators.loginBtn).click();
const loginBtnLocator = page.getByTestId(loginLocators.loginBtn);
await waitForVisibleAndCallback(loginBtnLocator, () => loginBtnLocator.click());
const gettingStartedLocator = page.getByRole('link', { name: 'Getting Started' });
await waitForAndExpect(gettingStartedLocator, 'visible', () => expect(gettingStartedLocator).toBeVisible());
await waitForVisibleAndCallback(gettingStartedLocator, () => expect(gettingStartedLocator).toBeVisible());
}

/**
Expand Down

0 comments on commit a315db5

Please sign in to comment.