Skip to content

Commit

Permalink
Clean up the script and removed unused function. This should fixed both
Browse files Browse the repository at this point in the history
#15 and #16.
  • Loading branch information
eugene-dynamsoft committed Sep 17, 2024
1 parent e364ffd commit bc33468
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
5 changes: 2 additions & 3 deletions VINScanner/tests/e2e/test-MinElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test.describe.configure({ mode: 'serial' });

test.describe('Minimum Element Page Tests', () => {
test.use({userAgent});

test.beforeEach(async ({ minElementPage }) => {
await minElementPage.navigateTo();
});
Expand All @@ -45,8 +45,7 @@ test.describe('Minimum Element Page Tests', () => {
test('should get all available resolutions', async ({ minElementPage }) => {
const resolutions = await minElementPage.getAllResolutions();
if (resolutions !== null) {
// This fails because we're comparing objects incorrectly
// We need to compare each property of the objects instead

let isFound = availableResolutions.some(ai =>
resolutions.some(res => res.width === ai.width && res.height === ai.height)
);
Expand Down
21 changes: 1 addition & 20 deletions VINScanner/tests/pages/MinElementPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,16 @@ const URL = '/VINScanner/minimum-elements.html';
export class MinElementPage {
private page: Page;
private selResolution: Locator;
private options: Locator[];

constructor(page: Page) {
this.page = page;
}

async initialize() {
this.selResolution = await this.page.locator('select.dce-sel-resolution');
this.options = await this.selResolution.locator('option').all();
}

async grantCameraPermission() {
await this.page.addScriptTag({
content: `
navigator.mediaDevices.getUserMedia = async () => {
return {
getVideoTracks: () => [{
applyConstraints: () => {},
stop: () => {},
}],
getAudioTracks: () => [],
};
};
`,
});
this.selResolution = await this.page.locator('select.dce-sel-resolution');
}

async navigateTo() {
// await this.grantCameraPermission();
await this.page.goto(URL);
await this.initialize();
}
Expand Down
15 changes: 4 additions & 11 deletions VINScanner/tests/pages/VinScannerPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export class VinScannerPage {
private page: Page;
private headerLabel: Locator;
private settingsModal: Locator;
private scanModeContainer: Locator;
private startButton: Locator;
private scanBarcodeButton: Locator;
private scanTextButton: Locator;
Expand All @@ -20,7 +19,7 @@ export class VinScannerPage {
this.headerLabel = this.page.locator(".scan-mode");
this.settingsModal = this.page.locator(".settings-modal-content");
this.startButton = this.page.locator(".start-btn");
this.scanModeContainer = this.page.locator(".scan-mode-content");

this.scanBarcodeButton = this.page.locator("#scan-barcode-btn");
this.scanTextButton = this.page.locator("#scan-text-btn");
this.scanBothButton = this.page.locator("#scan-both-btn");
Expand Down Expand Up @@ -72,8 +71,8 @@ export class VinScannerPage {
}

async getHeaderLabel(expectedText?: string) {
// await this.headerLabel.waitFor({ state: 'visible', timeout: 5000 });
await this.page.waitForTimeout(3000);

// If expectedText is provided, wait for it to appear
if (expectedText) {
await this.headerLabel.waitFor({ state: 'visible', timeout: 5000});
Expand All @@ -90,16 +89,10 @@ export class VinScannerPage {
await this.settingsModal.waitFor({ state: "visible" });
}

async waitForPageLoad() {
await this.page.waitForFunction(() => {
return (typeof cameraEnhancer !== undefined);
}, { timeout: 10000 });
await this.scanModeContainer.waitFor({ timeout: 10000 });
}

async clickStartButton() {
await this.startButton.click();
// await this.waitForPageLoad();

// Ensuring the page is loaded after clicked on the Start button
await this.page.waitForLoadState('networkidle', {timeout: 30000});
await this.page.waitForLoadState('domcontentloaded');
}
Expand Down

0 comments on commit bc33468

Please sign in to comment.