Compare commits

...

3 Commits

Author SHA1 Message Date
Jose Olarte III 69473a826f Removed test.slow() 2 months ago
Jose Olarte III 51eb45353e Moved common functions to testUtils 2 months ago
Jose Olarte III b1875b5812 Remove unneeded timeouts 2 months ago
  1. 3
      test-playwright/20-create-project.spec.ts
  2. 27
      test-playwright/25-create-project-x10.spec.ts
  3. 40
      test-playwright/33-record-gift-x10.spec.ts
  4. 30
      test-playwright/testUtils.ts

3
test-playwright/20-create-project.spec.ts

@ -22,9 +22,6 @@ test('Create new project, then search for it', async ({ page }) => {
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause for 5 seconds
await page.waitForTimeout(5000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Create new project // Create new project
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); await page.getByRole('link', { name: 'Projects', exact: true }).click();

27
test-playwright/25-create-project-x10.spec.ts

@ -1,26 +1,7 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser, createUniqueStringsArray } from './testUtils';
// Function to generate a random string of specified length
function generateRandomString(length) {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
function createUniqueStringsArray(count) {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
test('Create 10 new projects', async ({ page }) => { test('Create 10 new projects', async ({ page }) => {
test.slow(); // Extend the test timeout
const projectCount = 10; const projectCount = 10;
// Standard texts // Standard texts
@ -32,7 +13,7 @@ test('Create 10 new projects', async ({ page }) => {
const finalDescriptions = []; const finalDescriptions = [];
// Create an array of unique strings // Create an array of unique strings
const uniqueStrings = createUniqueStringsArray(projectCount); const uniqueStrings = await createUniqueStringsArray(projectCount);
// Populate arrays with titles and descriptions // Populate arrays with titles and descriptions
for (let i = 0; i < projectCount; i++) { for (let i = 0; i < projectCount; i++) {
@ -45,9 +26,6 @@ test('Create 10 new projects', async ({ page }) => {
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause a bit
await page.waitForTimeout(3000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Create new projects // Create new projects
for (let i = 0; i < projectCount; i++) { for (let i = 0; i < projectCount; i++) {
await page.goto('./projects'); await page.goto('./projects');
@ -59,7 +37,6 @@ test('Create 10 new projects', async ({ page }) => {
await page.getByPlaceholder('Start Date').fill('2025-12-01'); await page.getByPlaceholder('Start Date').fill('2025-12-01');
await page.getByPlaceholder('Start Time').fill('12:00'); await page.getByPlaceholder('Start Time').fill('12:00');
await page.getByRole('button', { name: 'Save Project' }).click(); await page.getByRole('button', { name: 'Save Project' }).click();
await page.waitForTimeout(1000); // Compensate for delay in loading Idea Name heading
// Check texts // Check texts
await expect(page.locator('h2')).toContainText(finalTitles[i]); await expect(page.locator('h2')).toContainText(finalTitles[i]);

40
test-playwright/33-record-gift-x10.spec.ts

@ -1,38 +1,7 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser, createUniqueStringsArray, createRandomNumbersArray } from './testUtils';
// Function to generate a random string of specified length
function generateRandomString(length) {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
function createUniqueStringsArray(count) {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
// Function to create an array of two-digit non-zero numbers
function createRandomNumbersArray(count) {
const numbersArray = [];
for (let i = 0; i < count; i++) {
let randomNumber = Math.floor(Math.random() * 99) + 1;
numbersArray.push(randomNumber);
}
return numbersArray;
}
test('Record 10 new gifts', async ({ page }) => { test('Record 10 new gifts', async ({ page }) => {
test.slow(); // Extend the test timeout
const giftCount = 10; const giftCount = 10;
// Standard text // Standard text
@ -43,8 +12,8 @@ test('Record 10 new gifts', async ({ page }) => {
const finalNumbers = []; const finalNumbers = [];
// Create arrays for field input // Create arrays for field input
const uniqueStrings = createUniqueStringsArray(giftCount); const uniqueStrings = await createUniqueStringsArray(giftCount);
const randomNumbers = createRandomNumbersArray(giftCount); const randomNumbers = await createRandomNumbersArray(giftCount);
// Populate array with titles // Populate array with titles
for (let i = 0; i < giftCount; i++) { for (let i = 0; i < giftCount; i++) {
@ -57,9 +26,6 @@ test('Record 10 new gifts', async ({ page }) => {
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause a bit
await page.waitForTimeout(3000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Record new gifts // Record new gifts
for (let i = 0; i < giftCount; i++) { for (let i = 0; i < giftCount; i++) {
// Record something given // Record something given

30
test-playwright/testUtils.ts

@ -65,4 +65,34 @@ export async function generateEthrUser(page: Page): Promise<string> {
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden(); await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
return newDid; return newDid;
}
// Function to generate a random string of specified length
export async function generateRandomString(length: number): Promise<string> {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
export async function createUniqueStringsArray(count: number): Promise<string[]> {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = await generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
// Function to create an array of two-digit non-zero numbers
export async function createRandomNumbersArray(count: number): Promise<number[]> {
const numbersArray = [];
for (let i = 0; i < count; i++) {
let randomNumber = Math.floor(Math.random() * 99) + 1;
numbersArray.push(randomNumber);
}
return numbersArray;
} }
Loading…
Cancel
Save