feat: implement network condition simulation in NetworkSimulator
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { NetworkSimulator } from '../../utils/NetworkSimulator';
|
||||
import { networkConfigs } from '../../config/network-configs';
|
||||
|
||||
test.describe('NetworkSimulator', () => {
|
||||
test('should set 3G network condition', async ({ page, context }) => {
|
||||
const simulator = new NetworkSimulator(context);
|
||||
await simulator.setNetworkCondition(networkConfigs['3g-fast']);
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('header')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should switch to offline mode', async ({ page, context }) => {
|
||||
const simulator = new NetworkSimulator(context);
|
||||
await page.goto('/');
|
||||
|
||||
await simulator.goOffline();
|
||||
await page.reload();
|
||||
|
||||
await expect(page.locator('header')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should switch back to online mode', async ({ page, context }) => {
|
||||
const simulator = new NetworkSimulator(context);
|
||||
await simulator.goOffline();
|
||||
await page.goto('/');
|
||||
|
||||
await simulator.goOnline();
|
||||
await page.reload();
|
||||
|
||||
await expect(page.locator('header')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should simulate network switch', async ({ page, context }) => {
|
||||
const simulator = new NetworkSimulator(context);
|
||||
|
||||
await simulator.simulateNetworkSwitch(networkConfigs['4g'], networkConfigs['3g-slow']);
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('header')).toBeVisible();
|
||||
});
|
||||
|
||||
test('should reset network condition', async ({ page, context }) => {
|
||||
const simulator = new NetworkSimulator(context);
|
||||
await simulator.setNetworkCondition(networkConfigs['3g-slow']);
|
||||
|
||||
await simulator.resetNetworkCondition();
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('header')).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user