Skip to content

Commit

Permalink
Playwright Test : SLOs, Minion Searches & Saved Queries Screen (sigle…
Browse files Browse the repository at this point in the history
…ns#1678)

* Playwright Test : SLOs, Minion Searches & Saved Queries Screen

* Fix Flaky Test
  • Loading branch information
sonamgupta21 authored Sep 27, 2024
1 parent 4bc0c62 commit a21ddfa
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
22 changes: 22 additions & 0 deletions playwright-tests/tests/all-slos.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, expect } = require('@playwright/test');
const { testThemeToggle } = require('./common-functions');

test.describe('SLO Screen Test', () => {
test('should have SLOs div with correct heading and message', async ({ page }) => {
// Navigate to the page containing the SLOs div
await page.goto('http://localhost:5122/all-slos.html');

// Check if the SLOs div is present
const slosDiv = page.locator('#all-slos');
await expect(slosDiv).toBeVisible();

// Check if the heading is correct
await expect(slosDiv.locator('h1.myOrg-heading')).toHaveText('SLOs');

// Check if the enterprise version message is present
await expect(slosDiv).toContainText('This feature is available in Enterprise version');

// Theme Button
await testThemeToggle(page);
});
});
9 changes: 9 additions & 0 deletions playwright-tests/tests/dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@ test.describe('Dashboard Page Tests', () => {
});

test('Toggle favorite status', async () => {
await page.waitForSelector('#favbutton', { state: 'visible' });
const initialState = await page.locator('#favbutton').getAttribute('class');
await page.click('#favbutton');
await page.waitForFunction(
(selector, initialState) => {
const button = document.querySelector(selector);
return button && button.getAttribute('class') !== initialState;
},
'#favbutton',
initialState
);
const newState = await page.locator('#favbutton').getAttribute('class');
expect(newState).not.toBe(initialState);
});
Expand Down
46 changes: 46 additions & 0 deletions playwright-tests/tests/minion-searches.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { test, expect } = require('@playwright/test');
const { testThemeToggle } = require('./common-functions');

test.describe('Minion Searches Page Tests', () => {
test('should load minion searches page correctly', async ({ page }) => {
// Navigate to the minion searches page
await page.goto('http://localhost:5122/minion-searches.html');

// Check if the main heading is present
await expect(page.locator('.main-heading')).toHaveText('Minion Searches');

// Check if all log level buttons are present
const logLevels = ['Error', 'Warning', 'Debug', 'Info'];
for (const level of logLevels) {
const button = page.locator(`.log-pane button#${level.toLowerCase()}`);
await expect(button).toBeVisible();
await expect(button.locator('h3')).toHaveText(level);
await expect(button.locator('h4')).toHaveText('0');
}

// Check if the ag-grid is present
await expect(page.locator('#ag-grid')).toBeVisible();
await expect(page.locator('.ag-root-wrapper')).toBeVisible();

// Check if the grid headers are correct
const expectedHeaders = ['Log Statement', 'Filename', 'Line Number', 'Level', 'State'];
const headers = page.locator('.ag-header-cell-text');
await expect(headers).toHaveCount(expectedHeaders.length);
for (let i = 0; i < expectedHeaders.length; i++) {
await expect(headers.nth(i)).toHaveText(expectedHeaders[i]);
}

// Check if the "No Rows To Show" message is visible
await expect(page.locator('.ag-overlay-no-rows-center')).toHaveText('No Rows To Show');

// Check if the pagination panel is present
await expect(page.locator('.ag-paging-panel')).toBeVisible();

// Check if the result pane is present
await expect(page.locator('.result-pane .header')).toHaveText('Result');
await expect(page.locator('.result-pane .result-body')).toBeVisible();

// Theme Button
await testThemeToggle(page);
});
});
64 changes: 64 additions & 0 deletions playwright-tests/tests/saved-queries.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { test, expect } = require('@playwright/test');
const { testDateTimePicker, testThemeToggle } = require('./common-functions');

test.describe('Saved Queries Tests', () => {
test('Save query, open it, and delete it', async ({ page }) => {
// Save a query
await page.goto('http://localhost:5122/index.html');
await testDateTimePicker(page);
await page.locator('#query-builder-btn').click();
await page.waitForTimeout(1000);
await expect(page.locator('#logs-result-container')).toBeVisible();

await page.click('#saveq-btn');

const dialog = page.locator('[aria-describedby="save-queries"]');
await dialog.waitFor({ state: 'visible' });

await page.fill('[aria-describedby="save-queries"] #qname', 'Test-Query');
await page.fill('[aria-describedby="save-queries"] #description', 'This is a test query');

const saveButton = dialog.locator('.saveqButton');
await saveButton.waitFor({ state: 'visible' });
await saveButton.click();

const toast = page.locator('#message-toast');
await expect(toast).toContainText('Query saved successfully');

// Open saved-queries.html and verify the saved query
await page.goto('http://localhost:5122/saved-queries.html');

// Wait for the ag-grid to load
await page.waitForSelector('.ag-root-wrapper');

// Check if the saved query is present in the grid
const cellWithTestQuery = page.locator('.ag-cell-value:has-text("Test-Query")');
await expect(cellWithTestQuery).toBeVisible();

// Click on the saved query
await cellWithTestQuery.click();

// Verify that it opens the index page with the table visible
await expect(page).toHaveURL(/index\.html/);
await expect(page.locator('#logs-result-container')).toBeVisible();

// Go back to saved queries page
await page.goto('http://localhost:5122/saved-queries.html');

// Wait for the ag-grid to load again
await page.waitForSelector('.ag-root-wrapper');

// Find and click the delete button for the Test-Query
const deleteButton = page.locator('.ag-row:has-text("Test-Query") .btn-simple');
await deleteButton.click();

// Confirm deletion in the popup
await page.locator('#delete-btn').click();

// Verify that the query is no longer in the grid
await expect(cellWithTestQuery).not.toBeVisible();

// Theme Button
await testThemeToggle(page);
});
});

0 comments on commit a21ddfa

Please sign in to comment.