From 8524beae6796333cd96f6d0536937ef869f66b2b Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Sun, 28 Apr 2024 17:46:31 +0800 Subject: [PATCH] chore: make e2e more stable --- .../client/__e2e__/schemaInitializer.test.ts | 28 +++++++++---------- .../src/client/__e2e__/schemaSettings.test.ts | 15 +++++----- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts index 92f37431fa..1b40dc9496 100644 --- a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts +++ b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts @@ -1,15 +1,6 @@ import { expect, test } from '@nocobase/test/e2e'; import { oneTableWithMap } from './templates'; -test.afterEach(async ({ page }) => { - await page.goto('/admin/settings/map'); - await page.getByRole('button', { name: 'Edit' }).click(); - await page.getByLabel('Access key').clear(); - await page.getByLabel('securityJsCode or serviceHost').clear(); - await page.getByRole('button', { name: 'Save' }).click(); - await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); -}); - test.describe('where map block can be added', () => { test('page & popup', async ({ page, mockPage }) => { const nocoPage = await mockPage(oneTableWithMap).waitForInit(); @@ -29,14 +20,13 @@ test.describe('where map block can be added', () => { // 2. 点击跳转按钮去配置页面,配置好后返回刚才的页面,应该能正常显示地图 await page.getByRole('button', { name: 'Go to the configuration page' }).click(); await page.waitForLoadState('networkidle'); - if (await page.getByRole('button', { name: 'Edit' }).isVisible()) { - await page.getByRole('button', { name: 'Edit' }).click(); + await page.waitForTimeout(1000); + if (await page.getByRole('button', { name: 'Edit' }).first().isVisible()) { + await page.getByRole('button', { name: 'Edit' }).first().click(); } - await page.getByLabel('Access key').click(); await page.getByLabel('Access key').fill('9717a70e44273882bcf5489f72b4e261'); - await page.getByLabel('securityJsCode or serviceHost').click(); await page.getByLabel('securityJsCode or serviceHost').fill('6876ed2d3a6168b75c4fba852e16c99c'); - await page.getByRole('button', { name: 'Save' }).click(); + await page.getByRole('button', { name: 'Save' }).first().click(); await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); await nocoPage.goto(); await expect(page.getByLabel('block-item-CardItem-map-map').locator('.amap-layer')).toBeAttached(); @@ -46,5 +36,15 @@ test.describe('where map block can be added', () => { await page.getByLabel('schema-initializer-Grid-form:').hover(); await page.getByRole('menuitem', { name: 'point' }).click(); await expect(page.getByLabel('block-item-CollectionField-').locator('.amap-layer')).toBeAttached(); + + // 4. 清空配置信息,以免影响其他测试用例 + await page.goto('/admin/settings/map'); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(1000); + await page.getByRole('button', { name: 'Edit' }).first().click(); + await page.getByLabel('Access key').clear(); + await page.getByLabel('securityJsCode or serviceHost').clear(); + await page.getByRole('button', { name: 'Save' }).first().click(); + await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); }); }); diff --git a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaSettings.test.ts b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaSettings.test.ts index eef50c82bf..5bcf61b316 100644 --- a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaSettings.test.ts +++ b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaSettings.test.ts @@ -4,23 +4,24 @@ import { oneMapUsedToTestSettings } from './templates'; test.beforeEach(async ({ page }) => { await page.goto('/admin/settings/map'); await page.waitForLoadState('networkidle'); - if (await page.getByRole('button', { name: 'Edit' }).isVisible()) { - await page.getByRole('button', { name: 'Edit' }).click(); + await page.waitForTimeout(1000); + if (await page.getByRole('button', { name: 'Edit' }).first().isVisible()) { + await page.getByRole('button', { name: 'Edit' }).first().click(); } - await page.getByLabel('Access key').click(); await page.getByLabel('Access key').fill('9717a70e44273882bcf5489f72b4e261'); - await page.getByLabel('securityJsCode or serviceHost').click(); await page.getByLabel('securityJsCode or serviceHost').fill('6876ed2d3a6168b75c4fba852e16c99c'); - await page.getByRole('button', { name: 'Save' }).click(); + await page.getByRole('button', { name: 'Save' }).first().click(); await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); }); test.afterEach(async ({ page }) => { await page.goto('/admin/settings/map'); - await page.getByRole('button', { name: 'Edit' }).click(); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(1000); + await page.getByRole('button', { name: 'Edit' }).first().click(); await page.getByLabel('Access key').clear(); await page.getByLabel('securityJsCode or serviceHost').clear(); - await page.getByRole('button', { name: 'Save' }).click(); + await page.getByRole('button', { name: 'Save' }).first().click(); await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); });