Skip to content

Commit

Permalink
use try/catch for E2E on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed May 14, 2024
1 parent 0a5cf56 commit 948ee90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 10 additions & 11 deletions e2e/utils/strategy/CreateStrategyDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { CreateStrategyTestCase, StrategySettings } from './types';
import { RangeOrder, debugTokens, Direction, Setting } from '../types';
import { waitModalClose, waitModalOpen, waitTooltipsClose } from '../modal';
import { screenshot, shouldTakeScreenshot } from '../operators';
import { screenshot, shouldTakeScreenshot, waitFor } from '../operators';
import { MainMenuDriver } from '../MainMenuDriver';

export class CreateStrategyDriver {
Expand Down Expand Up @@ -103,15 +103,6 @@ export class CreateStrategyDriver {

async submit() {
const btn = this.page.getByText('Create Strategy');

try {
if (await this.page.isVisible('[data-testid=approve-warnings]')) {
await this.page.getByTestId('approve-warnings').click();
}
} catch {
// do nothing, there is no approval needed
}

if (shouldTakeScreenshot) {
const mainMenu = new MainMenuDriver(this.page);
await mainMenu.hide();
Expand All @@ -121,6 +112,14 @@ export class CreateStrategyDriver {
await screenshot(form, path);
await mainMenu.show();
}
return btn.click();
try {
await btn.click({ timeout: 1_000 });
} catch {
await waitFor(this.page, 'approve-warnings');
if (await this.page.isVisible('[data-testid=approve-warnings]')) {
await this.page.getByTestId('approve-warnings').click();
}
await btn.click();
}
}
}
20 changes: 11 additions & 9 deletions e2e/utils/strategy/EditStrategyDriver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { Page } from 'playwright-core';
import { MainMenuDriver } from '../MainMenuDriver';
import { screenshot, shouldTakeScreenshot } from '../operators';
import { screenshot, shouldTakeScreenshot, waitFor } from '../operators';
import { CreateStrategyTestCase } from './types';
import { Setting, Direction, MinMax } from '../types';
import {
Expand Down Expand Up @@ -69,13 +69,6 @@ export class EditStrategyDriver {
async submit(type: 'deposit' | 'withdraw' | 'renew' | 'editPrices') {
const btn = this.page.getByTestId('edit-submit');

try {
if (await this.page.isVisible('[data-testid=approve-warnings]')) {
await this.page.getByTestId('approve-warnings').click();
}
} catch {
// do nothing, there is no approval needed
}
if (shouldTakeScreenshot) {
const mainMenu = new MainMenuDriver(this.page);
await mainMenu.hide();
Expand All @@ -85,7 +78,16 @@ export class EditStrategyDriver {
await screenshot(form, path);
await mainMenu.show();
}
return btn.click();

try {
await btn.click({ timeout: 1_000 });
} catch {
await waitFor(this.page, 'approve-warnings');
if (await this.page.isVisible('[data-testid=approve-warnings]')) {
await this.page.getByTestId('approve-warnings').click();
}
await btn.click();
}
}

async fillBudget(direction: Direction, budget: string) {
Expand Down

0 comments on commit 948ee90

Please sign in to comment.