1 changed files with 66 additions and 0 deletions
			
			
		| @ -0,0 +1,66 @@ | |||||
|  | import { test, expect } from '@playwright/test'; | ||||
|  | import { importUser } 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, then search for them', async ({ page }) => { | ||||
|  |   const projectCount = 10; | ||||
|  | 
 | ||||
|  |   // Standard texts
 | ||||
|  |   const standardTitle = "Idea "; | ||||
|  |   const standardDescription = "Description of Idea "; | ||||
|  | 
 | ||||
|  |   // Title and description arrays
 | ||||
|  |   const finalTitles = []; | ||||
|  |   const finalDescriptions = []; | ||||
|  | 
 | ||||
|  |   // Create an array of unique strings
 | ||||
|  |   const uniqueStrings = createUniqueStringsArray(projectCount); | ||||
|  | 
 | ||||
|  |   // Example: Fill the text field with each string in the array
 | ||||
|  |   for (let i = 0; i < projectCount; i++) { | ||||
|  |     let loopTitle = standardTitle + uniqueStrings[i]; | ||||
|  |     finalTitles.push(loopTitle); | ||||
|  |     let loopDescription = standardDescription + uniqueStrings[i]; | ||||
|  |     finalDescriptions.push(loopDescription); | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   // Import user 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 projects
 | ||||
|  |   for (let i = 0; i < projectCount; i++) { | ||||
|  |     await page.goto('./projects'); | ||||
|  |     await page.getByRole('link', { name: 'Projects', exact: true }).click(); | ||||
|  |     await page.getByRole('button').click(); | ||||
|  |     await page.getByPlaceholder('Idea Name').fill(finalTitles[i]); // Add random suffix
 | ||||
|  |     await page.getByPlaceholder('Description').fill(finalDescriptions[i]); | ||||
|  |     await page.getByPlaceholder('Website').fill('https://example.com'); | ||||
|  |     await page.getByPlaceholder('Start Date').fill('2025-12-01'); | ||||
|  |     await page.getByPlaceholder('Start Time').fill('12:00'); | ||||
|  |     await page.getByRole('button', { name: 'Save Project' }).click(); | ||||
|  | 
 | ||||
|  |     // Check texts
 | ||||
|  |     await expect(page.locator('h2')).toContainText(finalTitles[i]); | ||||
|  |     await expect(page.locator('#Content')).toContainText(finalDescriptions[i]); | ||||
|  |   } | ||||
|  | }); | ||||
					Loading…
					
					
				
		Reference in new issue