-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import EnvironmentUtil from '../../utils/environment.util'; | ||
import { check } from 'k6'; | ||
|
||
export class DashboardPage { | ||
constructor(page) { | ||
this.page = page; | ||
this.header = page.locator('h1'); | ||
} | ||
|
||
async navigate() { | ||
await this.page.goto(`${EnvironmentUtil.getMerchantPortalUrl()}/dashboard-merchant-portal-gui/dashboard`); | ||
await this.page.waitForLoadState('load'); | ||
} | ||
|
||
async verifyHeader() { | ||
await this.header.waitFor(); | ||
const headerText = await this.header.textContent(); | ||
|
||
check(headerText, { | ||
'Dashboard page was loaded': (text) => text === 'Dashboard', | ||
}); | ||
} | ||
|
||
async getDurationTime() { | ||
await this.page.evaluate(() => window.performance.mark('page-visit')); | ||
const marks = await this.page.evaluate(() => | ||
JSON.parse(JSON.stringify(window.performance.getEntriesByType('mark'))) | ||
); | ||
|
||
if (marks.length > 0) { | ||
return marks[0].startTime; | ||
} | ||
|
||
throw new Error('No marks found'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import EnvironmentUtil from '../../utils/environment.util'; | ||
import { check } from 'k6'; | ||
|
||
export class LoginPage { | ||
constructor(page) { | ||
this.page = page; | ||
this.usernameInput = page.locator('#security-merchant-portal-gui_username'); | ||
this.passwordInput = page.locator('#security-merchant-portal-gui_password'); | ||
this.submitButton = page.locator('[name="security-merchant-portal-gui"] button[type="submit"]'); | ||
this.header = page.locator('h1'); | ||
} | ||
|
||
async navigate() { | ||
await this.page.goto(`${EnvironmentUtil.getMerchantPortalUrl()}/security-merchant-portal-gui/login`); | ||
} | ||
|
||
async login(username, password) { | ||
await this.usernameInput.type(username); | ||
await this.passwordInput.type(password); | ||
|
||
await Promise.all([this.page.waitForNavigation(), this.submitButton.click()]); | ||
|
||
await this.header.waitFor(); | ||
const headerText = await this.header.textContent(); | ||
|
||
check(headerText, { | ||
'Login was successful': (text) => text === 'Dashboard', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,78 @@ | ||
import {group} from 'k6'; | ||
import OptionsUtil from '../../utils/options.util'; | ||
import {createMetrics} from '../../utils/metric.util'; | ||
import {check} from 'k6'; | ||
import { createMetrics } from '../../utils/metric.util'; | ||
import EnvironmentUtil from '../../utils/environment.util'; | ||
import {MerchantUserFixture} from "../../fixtures/merchant-user.fixture"; | ||
import {browser} from 'k6/browser'; | ||
import { MerchantUserFixture } from '../../fixtures/merchant-user.fixture'; | ||
import { browser } from 'k6/browser'; | ||
import { DashboardPage } from '../../pages/mp/dashboard.page'; | ||
import { LoginPage } from '../../pages/mp/login.page'; | ||
|
||
const testConfiguration = { | ||
...EnvironmentUtil.getDefaultTestConfiguration(), | ||
id: 'M8', | ||
group: 'Dashboard', | ||
vus: 1, | ||
iterations: 10, | ||
metrics: ['M8_view_dashboard'], | ||
thresholds: { | ||
M8_view_dashboard: { | ||
smoke: ['avg<475'], | ||
load: ['avg<475'], | ||
}, | ||
...EnvironmentUtil.getDefaultTestConfiguration(), | ||
id: 'M8', | ||
group: 'Dashboard', | ||
metrics: ['M8_view_dashboard'], | ||
thresholds: { | ||
M8_view_dashboard: { | ||
smoke: ['avg<475'], | ||
load: ['avg<475'], | ||
}, | ||
}, | ||
}; | ||
|
||
const {metrics, metricThresholds} = createMetrics(testConfiguration); | ||
const { metrics, metricThresholds } = createMetrics(testConfiguration); | ||
export const options = OptionsUtil.loadOptions(testConfiguration, metricThresholds); | ||
|
||
export function setup() { | ||
const dynamicFixture = new MerchantUserFixture({ | ||
idMerchant: 1, | ||
merchantUserCount: testConfiguration.vus, | ||
}); | ||
const dynamicFixture = new MerchantUserFixture({ | ||
idMerchant: 1, | ||
merchantUserCount: testConfiguration.vus, | ||
}); | ||
|
||
return dynamicFixture.getData(); | ||
return dynamicFixture.getData(); | ||
} | ||
|
||
async function login(merchantUser) { | ||
const browserContext = await browser.newContext(); // Create browser context | ||
const page = await browserContext.newPage(); // Create a new page in the context | ||
|
||
try { | ||
// Navigate to login page | ||
await page.goto(`${EnvironmentUtil.getMerchantPortalUrl()}/security-merchant-portal-gui/login`); | ||
|
||
// Fill in login credentials | ||
await page.locator('#security-merchant-portal-gui_username').type(merchantUser.username); | ||
await page.locator('#security-merchant-portal-gui_password').type(merchantUser.password); | ||
|
||
// Submit the form | ||
const submitButton = page.locator('[name="security-merchant-portal-gui"] button[type="submit"]'); | ||
await Promise.all([ | ||
page.waitForNavigation(), // Wait for navigation to complete | ||
submitButton.click(), // Click the submit button | ||
]); | ||
export function teardown() { | ||
MerchantUserFixture.runConsoleCommands(['console queue:worker:start --stop-when-empty']); | ||
} | ||
|
||
// Ensure the header is loaded | ||
const header = page.locator('h1'); | ||
await header.waitFor(); // Wait for the header to appear | ||
export default async function (data) { | ||
const merchantUser = MerchantUserFixture.iterateData(data); | ||
let browserContext = await browser.newContext(); | ||
|
||
// Validate the header text | ||
const headerText = await header.textContent(); | ||
check(headerText, { | ||
'Header text is correct': (text) => text === 'Dashboard', | ||
}); | ||
try { | ||
browserContext = await login(browserContext, merchantUser); | ||
const durationTime = await openDashboardPage(browserContext); | ||
|
||
return browserContext; // Return the browser context for reuse | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
throw error; // Rethrow error for debugging | ||
} finally { | ||
await page.close(); // Always close the page | ||
} | ||
metrics[testConfiguration.metrics[0]].add(durationTime); | ||
} finally { | ||
await browserContext.close(); | ||
} | ||
} | ||
|
||
export default async function (data) { | ||
const merchantUser = MerchantUserFixture.iterateData(data); | ||
const context = await login(merchantUser); | ||
|
||
group(testConfiguration.group, async () => { | ||
const page = await context.newPage(); | ||
async function login(browserContext, merchantUser) { | ||
const page = await browserContext.newPage({ headless: false }); | ||
const loginPage = new LoginPage(page); | ||
|
||
try { | ||
await page.goto(`${EnvironmentUtil.getMerchantPortalUrl()}/dashboard-merchant-portal-gui/dashboard`); | ||
// Wait for the page to load completely | ||
await page.waitForLoadState('load'); | ||
try { | ||
await loginPage.navigate(); | ||
await loginPage.login(merchantUser.username, merchantUser.password); | ||
|
||
// Record a performance mark | ||
await page.evaluate(() => window.performance.mark('page-visit')); | ||
return browserContext; | ||
} finally { | ||
await page.close(); | ||
} | ||
} | ||
|
||
// Retrieve performance marks | ||
const marks = await page.evaluate(() => | ||
JSON.parse(JSON.stringify(window.performance.getEntriesByType('mark'))) | ||
); | ||
async function openDashboardPage(browserContext) { | ||
const page = await browserContext.newPage({ headless: false }); | ||
const dashboardPage = new DashboardPage(page); | ||
|
||
if (marks.length > 0) { | ||
const totalActionTime = marks[0].startTime; // Use startTime of the first mark | ||
metrics[testConfiguration.metrics[0]].add(totalActionTime); | ||
} | ||
} finally { | ||
await page.close(); // Close the page after use | ||
} | ||
}); | ||
try { | ||
await dashboardPage.navigate(); | ||
await dashboardPage.verifyHeader(); | ||
|
||
await context.close(); // Close context after the test | ||
return await dashboardPage.getDurationTime(); | ||
} finally { | ||
await page.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.