From 7d3d0a714c9e62ddd11d2497e0008e27107a0213 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 21:57:24 +0200 Subject: [PATCH 01/14] ci: combine things to one workflow --- .github/workflows/clean_tree.yaml | 88 +++++++++++++++++++++++++++++-- .github/workflows/lint.yml | 19 ------- .github/workflows/unittest.yml | 18 ------- 3 files changed, 85 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/unittest.yml diff --git a/.github/workflows/clean_tree.yaml b/.github/workflows/clean_tree.yaml index a7278ec5..4af1192c 100644 --- a/.github/workflows/clean_tree.yaml +++ b/.github/workflows/clean_tree.yaml @@ -1,6 +1,11 @@ name: Test Clean Tree on: pull_request: + +env: + DOCKER_APP_IMAGE_NAME: 'ghcr.io/hasadna/open-bus-map-search/open-bus-map-search' + DOCKER_APP_IMAGE_TAG: 'latest' + jobs: git-clean-tree-test: runs-on: ubuntu-latest @@ -33,6 +38,83 @@ jobs: uses: ArkadiK94/action-git-clean-tree@v1.0.3 with: error-reason: 'yarn build and yarn build-storybook' - - name: Clean up - if: always() - run: npm uninstall -g yarn + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install + - name: Run lint + run: yarn lint + circular: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install + - name: find circular dependencies + run: yarn madge --extensions js,ts --circular . + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and Export Docker image + uses: docker/build-push-action@v2 + with: + context: . + tags: ${{ env.DOCKER_APP_IMAGE_NAME }}:${{ env.DOCKER_APP_IMAGE_TAG }} + outputs: type=docker, dest=/tmp/docker-image.tar + - name: Save Docker image + uses: actions/upload-artifact@v2 + with: + name: docker-image + path: /tmp/docker-image.tar + test: + runs-on: ubuntu-latest + needs: build + steps: + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: myimage + path: /tmp + - name: Load image + run: docker load -i /tmp/docker-image.tar + - name: Run application + run: docker run -d -p 3000:80 ${{ env.DOCKER_APP_IMAGE_NAME }}:${{ env.DOCKER_APP_IMAGE_TAG }} + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install + - name: Run test + run: yarn test + test-unit: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install + - name: run the tests + run: yarn test:unit diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 55b4a826..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Lint -on: - pull_request: -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Run install - uses: borales/actions-yarn@v4 - with: - cmd: install - - name: Run lint - run: yarn lint - - name: find circular dependencies - run: yarn madge --extensions js,ts --circular . diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml deleted file mode 100644 index 016ec598..00000000 --- a/.github/workflows/unittest.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Unit Tests -on: - pull_request: -jobs: - test-unit: - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 20 - - name: Run install - uses: borales/actions-yarn@v4 - with: - cmd: install - - name: run the tests - run: yarn test:unit From 48ca94224aab96e285f347bda5d2c26e68cc7518 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 22:15:16 +0200 Subject: [PATCH 02/14] fix: typo --- .github/workflows/playwright.yml | 52 ------------------- .../{clean_tree.yaml => validate.yaml} | 6 +-- 2 files changed, 3 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/playwright.yml rename .github/workflows/{clean_tree.yaml => validate.yaml} (97%) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml deleted file mode 100644 index 33ba1767..00000000 --- a/.github/workflows/playwright.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Playwright Tests -on: - pull_request: -jobs: - test: - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Run install - uses: borales/actions-yarn@v4 - with: - cmd: install - - name: Install Playwright Browsers - run: yarn playwright install --with-deps - - name: Run Playwright tests - run: yarn playwright test - - uses: actions/upload-artifact@v3 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30\ - - uses: shallwefootball/s3-upload-action@master - name: Upload report to S3 - if: always() - id: s3-report - continue-on-error: true - with: - aws_key_id: ${{ secrets.AWS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} - aws_bucket: noam-gaash.co.il - source_dir: playwright-report - destination_dir: ${{ github.run_id }}/open-bus/playwright-report - - name: output link to report to the summary - if: always() && steps.s3-report.outcome == 'success' - run: echo "link to report - https://s3.amazonaws.com/noam-gaash.co.il/$GITHUB_RUN_ID/open-bus/playwright-report/index.html" >> $GITHUB_STEP_SUMMARY - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Install dependencies - run: yarn - - name: Build - run: yarn build diff --git a/.github/workflows/clean_tree.yaml b/.github/workflows/validate.yaml similarity index 97% rename from .github/workflows/clean_tree.yaml rename to .github/workflows/validate.yaml index 4af1192c..68ef7b81 100644 --- a/.github/workflows/clean_tree.yaml +++ b/.github/workflows/validate.yaml @@ -1,4 +1,4 @@ -name: Test Clean Tree +name: Validate on: pull_request: @@ -7,7 +7,7 @@ env: DOCKER_APP_IMAGE_TAG: 'latest' jobs: - git-clean-tree-test: + verify-clean-tree: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -88,7 +88,7 @@ jobs: - name: Download artifact uses: actions/download-artifact@v3 with: - name: myimage + name: docker-image path: /tmp - name: Load image run: docker load -i /tmp/docker-image.tar From 7aaa2185a4822220998d722c82b562518de59361 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 22:16:54 +0200 Subject: [PATCH 03/14] ci: add all passed --- .github/workflows/validate.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 68ef7b81..3d9e0cd1 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -118,3 +118,10 @@ jobs: cmd: install - name: run the tests run: yarn test:unit + + all-passed: + runs-on: ubuntu-latest + needs: [verify-clean-tree, lint, circular, test, test-unit] + steps: + - name: All passed + run: echo "All passed" From a1aec7e4e87ef1c8b84771a07b82715b8d426705 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 22:23:15 +0200 Subject: [PATCH 04/14] test: don't reuseExistingServer --- playwright.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/playwright.config.ts b/playwright.config.ts index 1b9ac1ee..2b497fcf 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -72,7 +72,6 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { command: 'yarn start', - reuseExistingServer: !process.env.CI, timeout: 120 * 1000, port: 3000, }, From 5032e8466bd7805c4fbafbe0c57b94a62e31960c Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 22:54:08 +0200 Subject: [PATCH 05/14] test: reuseExistingServer --- playwright.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/playwright.config.ts b/playwright.config.ts index 2b497fcf..597114b5 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -72,6 +72,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { command: 'yarn start', + reuseExistingServer: true, timeout: 120 * 1000, port: 3000, }, From 6dbf9cd96fb94cf61ff6f5e42115bef0d6cd487a Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 22:59:00 +0200 Subject: [PATCH 06/14] test: playwright install --- .github/workflows/validate.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 3d9e0cd1..c0f9a793 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -102,6 +102,7 @@ jobs: uses: borales/actions-yarn@v4 with: cmd: install + - run: yarn playwright install - name: Run test run: yarn test test-unit: From 3e28b8991d2d9ca426279a99cd8dea4ae4b21fdc Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 23:24:56 +0200 Subject: [PATCH 07/14] fix: tests --- tests/about.spec.ts | 4 ++-- tests/clearButton.spec.ts | 5 +++++ tests/realtimemap.spec.ts | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/about.spec.ts b/tests/about.spec.ts index e0585ce2..39f93c8d 100644 --- a/tests/about.spec.ts +++ b/tests/about.spec.ts @@ -3,8 +3,8 @@ test.describe('About Page Tests', () => { test('can access about page by clicking `about` menu', async ({ page }) => { await page.goto('/') await page.getByText('אודות').click() - await expect(page).toHaveURL('http://localhost:3000/about') - const locator = await page.getByText('אודות') + await expect(page).toHaveURL(/about/) + const locator = page.getByText('אודות') await expect(locator).toHaveClass('menu-item active') }) test('page display title `מהו אתר “דאטאבוס”?`', async ({ page }) => { diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index 8f108f93..89d1dc5c 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -53,22 +53,27 @@ test.describe('test clearButton ', () => { await page.goto('/') await page.goto('/dashboard') await page.locator('li').filter({ hasText: 'לוח זמנים היסטורי' }).click() + await page.waitForURL(/timeline/) }) test('test in GapsPage', async ({ page }) => { await page.goto('/') await page.getByText('נסיעות שלא יצאו', { exact: true }).click() + await page.waitForURL(/gaps/) }) test('test in GapsPatternsPage', async ({ page }) => { await page.goto('/') await page.getByText('דפוסי נסיעות שלא יצאו', { exact: true }).click() + await page.waitForURL(/gaps-patterns/) }) test('test in SingleLineMapPage', async ({ page }) => { await page.goto('/') await page.getByText('מפה לפי קו', { exact: true }).click() + await page.waitForURL(/single-line/) }) test('test in RealtimeMapPage', async ({ page }) => { await page.goto('/') await page.getByText('מפה בזמן אמת', { exact: true }).click() + await page.waitForURL(/realtime/) const minutes = page.getByLabel('דקות') let getValueAttribute = await minutes.getAttribute('value') if (!getValueAttribute) return test.fail() diff --git a/tests/realtimemap.spec.ts b/tests/realtimemap.spec.ts index dbd0ce57..e1e6eba8 100644 --- a/tests/realtimemap.spec.ts +++ b/tests/realtimemap.spec.ts @@ -3,6 +3,7 @@ import { test } from '@playwright/test' test('realtime-map page', async ({ page }) => { await page.goto('/') await page.getByText('מפה בזמן אמת').click() + await page.waitForURL('**/realtime**') await page.getByLabel('בחירת תאריך, התאריך שנבחר הוא').click() await page.getByRole('gridcell', { name: '1', exact: true }).click() await page.getByLabel('דקות').fill('6') From 3cae31006829e7915a508b729bac643ba8ba6789 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Wed, 15 Nov 2023 23:30:55 +0200 Subject: [PATCH 08/14] fix: tests --- tests/clearButton.spec.ts | 4 ++-- tests/realtimemap.spec.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index 89d1dc5c..b60e69a1 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -63,7 +63,7 @@ test.describe('test clearButton ', () => { test('test in GapsPatternsPage', async ({ page }) => { await page.goto('/') await page.getByText('דפוסי נסיעות שלא יצאו', { exact: true }).click() - await page.waitForURL(/gaps-patterns/) + await page.waitForURL(/gaps_patterns/) }) test('test in SingleLineMapPage', async ({ page }) => { await page.goto('/') @@ -73,7 +73,7 @@ test.describe('test clearButton ', () => { test('test in RealtimeMapPage', async ({ page }) => { await page.goto('/') await page.getByText('מפה בזמן אמת', { exact: true }).click() - await page.waitForURL(/realtime/) + await page.waitForURL(/map/) const minutes = page.getByLabel('דקות') let getValueAttribute = await minutes.getAttribute('value') if (!getValueAttribute) return test.fail() diff --git a/tests/realtimemap.spec.ts b/tests/realtimemap.spec.ts index e1e6eba8..3706b09a 100644 --- a/tests/realtimemap.spec.ts +++ b/tests/realtimemap.spec.ts @@ -3,7 +3,7 @@ import { test } from '@playwright/test' test('realtime-map page', async ({ page }) => { await page.goto('/') await page.getByText('מפה בזמן אמת').click() - await page.waitForURL('**/realtime**') + await page.waitForURL(/map/) await page.getByLabel('בחירת תאריך, התאריך שנבחר הוא').click() await page.getByRole('gridcell', { name: '1', exact: true }).click() await page.getByLabel('דקות').fill('6') From 911764cc32ddc16231453f8c1e6e932c53baeb33 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 16 Nov 2023 20:34:54 +0200 Subject: [PATCH 09/14] ci: upload playwright artifacts --- .github/workflows/validate.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index c0f9a793..6b283f71 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -105,6 +105,11 @@ jobs: - run: yarn playwright install - name: Run test run: yarn test + - name: upload playwright artifacts + uses: actions/upload-artifact@v2 + with: + name: playwright + path: test-results test-unit: timeout-minutes: 60 runs-on: ubuntu-latest @@ -119,7 +124,6 @@ jobs: cmd: install - name: run the tests run: yarn test:unit - all-passed: runs-on: ubuntu-latest needs: [verify-clean-tree, lint, circular, test, test-unit] From 3539dc76c571bc4df6d8396c95d096c656717e59 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 16 Nov 2023 20:49:10 +0200 Subject: [PATCH 10/14] fix: `if always` for upload playwright artifacts --- .github/workflows/validate.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 6b283f71..f89f9314 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -106,6 +106,7 @@ jobs: - name: Run test run: yarn test - name: upload playwright artifacts + if: always() uses: actions/upload-artifact@v2 with: name: playwright From 4902696c0a7918d334a6b63c37e8b33a1db47f73 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 16 Nov 2023 21:05:49 +0200 Subject: [PATCH 11/14] wait for progress bar --- tests/clearButton.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index b60e69a1..4eec149b 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -59,6 +59,7 @@ test.describe('test clearButton ', () => { await page.goto('/') await page.getByText('נסיעות שלא יצאו', { exact: true }).click() await page.waitForURL(/gaps/) + await page.getByRole('progressbar').waitFor({ state: 'hidden' }) }) test('test in GapsPatternsPage', async ({ page }) => { await page.goto('/') From 36d67162b243a1c6e5039990a9d1e9904590ef0c Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 16 Nov 2023 21:16:20 +0200 Subject: [PATCH 12/14] test: wait for progress bar --- tests/clearButton.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index 4eec149b..e1028bc2 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -1,6 +1,8 @@ import { test, expect } from '@playwright/test' test.afterEach(async ({ page }, testInfo) => { + await page.getByRole('progressbar').waitFor({ state: 'hidden' }) + if (testInfo.title === 'test in RealtimeMapPage') return if (testInfo.title === 'test in GapsPatternsPage') { await page.getByLabel('בחירת תאריך').nth(0).click() @@ -59,7 +61,6 @@ test.describe('test clearButton ', () => { await page.goto('/') await page.getByText('נסיעות שלא יצאו', { exact: true }).click() await page.waitForURL(/gaps/) - await page.getByRole('progressbar').waitFor({ state: 'hidden' }) }) test('test in GapsPatternsPage', async ({ page }) => { await page.goto('/') From aebfaec7da5c72a48ff1b32271e831a9a1c7fba9 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 16 Nov 2023 21:34:31 +0200 Subject: [PATCH 13/14] refactor: tests --- tests/clearButton.spec.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index e1028bc2..ccde8b31 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/test' +import { test, expect, Page } from '@playwright/test' test.afterEach(async ({ page }, testInfo) => { await page.getByRole('progressbar').waitFor({ state: 'hidden' }) @@ -50,22 +50,21 @@ test.afterEach(async ({ page }, testInfo) => { await expect(stopSelect).not.toBeVisible() }) +async function visitPage(page: Page, pageName: string, url: RegExp) { + await page.goto('/') + await page.getByText(pageName).click() + await page.waitForURL(url) +} + test.describe('test clearButton ', () => { test('test in TimeLinePage', async ({ page }) => { - await page.goto('/') - await page.goto('/dashboard') - await page.locator('li').filter({ hasText: 'לוח זמנים היסטורי' }).click() - await page.waitForURL(/timeline/) + await visitPage(page, 'לוח זמנים היסטורי', /timeline/) }) test('test in GapsPage', async ({ page }) => { - await page.goto('/') - await page.getByText('נסיעות שלא יצאו', { exact: true }).click() - await page.waitForURL(/gaps/) + await visitPage(page, 'פערים', /gaps/) }) test('test in GapsPatternsPage', async ({ page }) => { - await page.goto('/') - await page.getByText('דפוסי נסיעות שלא יצאו', { exact: true }).click() - await page.waitForURL(/gaps_patterns/) + await visitPage(page, 'דפוסי נסיעות שלא יצאו', /gaps-patterns/) }) test('test in SingleLineMapPage', async ({ page }) => { await page.goto('/') @@ -76,6 +75,7 @@ test.describe('test clearButton ', () => { await page.goto('/') await page.getByText('מפה בזמן אמת', { exact: true }).click() await page.waitForURL(/map/) + await page.getByRole('progressbar').waitFor({ state: 'hidden' }) const minutes = page.getByLabel('דקות') let getValueAttribute = await minutes.getAttribute('value') if (!getValueAttribute) return test.fail() From e3b8ea2f2deb67d8232b793933f52fb230d2c3e8 Mon Sep 17 00:00:00 2001 From: Arkadi Koifman <76536506+ArkadiK94@users.noreply.github.com> Date: Sat, 18 Nov 2023 11:02:37 +0200 Subject: [PATCH 14/14] [Fix] Playwright clearButton Test and change structure (#227) --- tests/SelectorsModel.ts | 30 ++++++++ tests/clearButton.spec.ts | 141 +++++++++++++++++++++++++------------- tests/realtimemap.spec.ts | 5 +- 3 files changed, 125 insertions(+), 51 deletions(-) create mode 100644 tests/SelectorsModel.ts diff --git a/tests/SelectorsModel.ts b/tests/SelectorsModel.ts new file mode 100644 index 00000000..bd377686 --- /dev/null +++ b/tests/SelectorsModel.ts @@ -0,0 +1,30 @@ +import { Page, Locator } from '@playwright/test' + +export default class Selectors { + _operatorSelector: Locator + _routeSelector: Locator + _stopSelector: Locator + _lineNumberSelector: Locator + + constructor(page: Page) { + this._operatorSelector = page.locator('#operator-select') + this._lineNumberSelector = page.getByPlaceholder('לדוגמא: 17א') + this._routeSelector = page + .locator('div') + .filter({ hasText: /^בחירת מסלול נסיעה/ }) + .locator('#route-select') + this._stopSelector = page.locator('#stop-select') + } + get operator() { + return this._operatorSelector + } + get lineNumber() { + return this._lineNumberSelector + } + get route() { + return this._routeSelector + } + get stop() { + return this._stopSelector + } +} diff --git a/tests/clearButton.spec.ts b/tests/clearButton.spec.ts index ccde8b31..23ac6e94 100644 --- a/tests/clearButton.spec.ts +++ b/tests/clearButton.spec.ts @@ -1,81 +1,124 @@ -import { test, expect, Page } from '@playwright/test' +import { test, expect, type Locator, type Page } from '@playwright/test' -test.afterEach(async ({ page }, testInfo) => { +import Selectors from './SelectorsModel' + +async function visitPage(page: Page, pageName: string, url: RegExp) { + await page.goto('/') + await page.getByText(pageName, { exact: true }).click() + await page.waitForURL(url) await page.getByRole('progressbar').waitFor({ state: 'hidden' }) +} - if (testInfo.title === 'test in RealtimeMapPage') return - if (testInfo.title === 'test in GapsPatternsPage') { +async function fillDate(page: Page, twoDateElements: boolean = false) { + if (twoDateElements) { await page.getByLabel('בחירת תאריך').nth(0).click() await page.getByRole('gridcell', { name: '1', exact: true }).first().click() await page.getByLabel('בחירת תאריך').nth(1).click() } else { await page.getByLabel('בחירת תאריך').click() } - //clear LineNumber value test await page.getByRole('gridcell', { name: '2', exact: true }).first().click() - await page.locator('#operator-select').click() - await page.getByRole('option', { name: 'אלקטרה אפיקים' }).click() - await page.getByPlaceholder('לדוגמא: 17א').fill('64') - const routeSelect = page - .locator('div') - .filter({ hasText: /^בחירת מסלול נסיעה/ }) - .locator('#route-select') - const stopSelect = page.locator('#stop-select') +} - await routeSelect.click() +async function selectLineNumberAndRoute(page: Page, lineNumber: Locator, route: Locator) { + await lineNumber.fill('64') + await route.click() await page .getByRole('option', { name: 'הרב עובדיה יוסף/שלום צלח-פתח תקווה ⟵ מסוף כרמלית/הורדה-תל אביב יפו', }) .click() - if (testInfo.title === 'test in GapsPage') { - await page.getByLabel('רק פערים').check() - await page.getByLabel('רק פערים').uncheck() - } - await page.getByPlaceholder('לדוגמא: 17א').click() - await page.getByLabel('close').locator('svg').click() - await expect(routeSelect).not.toBeVisible() - await expect(stopSelect).not.toBeVisible() - //clear Operator value test - await page.getByPlaceholder('לדוגמא: 17א').fill('64') - await routeSelect.click() - await page - .getByRole('option', { - name: 'הרב עובדיה יוסף/שלום צלח-פתח תקווה ⟵ מסוף כרמלית/הורדה-תל אביב יפו', - }) - .click() - await page.locator('#operator-select').click() - await page.getByRole('button', { name: 'Clear' }).click() - await expect(routeSelect).not.toBeVisible() - await expect(stopSelect).not.toBeVisible() -}) - -async function visitPage(page: Page, pageName: string, url: RegExp) { - await page.goto('/') - await page.getByText(pageName).click() - await page.waitForURL(url) } test.describe('test clearButton ', () => { test('test in TimeLinePage', async ({ page }) => { await visitPage(page, 'לוח זמנים היסטורי', /timeline/) + await fillDate(page) + const { operator, lineNumber, route, stop } = new Selectors(page) + + //clear LineNumber value test + await operator.click() + await page.getByRole('option', { name: 'אלקטרה אפיקים' }).click() + await selectLineNumberAndRoute(page, lineNumber, route) + await lineNumber.click() + await page.getByLabel('close').locator('svg').click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() + + //clear Operator value test + await selectLineNumberAndRoute(page, lineNumber, route) + await operator.click() + await page.getByRole('button', { name: 'Clear' }).click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() }) test('test in GapsPage', async ({ page }) => { - await visitPage(page, 'פערים', /gaps/) + await visitPage(page, 'נסיעות שלא יצאו', /gaps/) + await fillDate(page) + const { operator, lineNumber, route, stop } = new Selectors(page) + + //clear LineNumber value test + await operator.click() + await page.getByRole('option', { name: 'אלקטרה אפיקים' }).click() + await selectLineNumberAndRoute(page, lineNumber, route) + await page.getByLabel('רק פערים').check() + await page.getByLabel('רק פערים').uncheck() + await lineNumber.click() + await page.getByLabel('close').locator('svg').click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() + + //clear Operator value test + await selectLineNumberAndRoute(page, lineNumber, route) + await operator.click() + await page.getByRole('button', { name: 'Clear' }).click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() }) test('test in GapsPatternsPage', async ({ page }) => { - await visitPage(page, 'דפוסי נסיעות שלא יצאו', /gaps-patterns/) + await visitPage(page, 'דפוסי נסיעות שלא יצאו', /gaps_patterns/) + await fillDate(page, true) + const { operator, lineNumber, route, stop } = new Selectors(page) + + //clear LineNumber value test + await operator.click() + await page.getByRole('option', { name: 'אלקטרה אפיקים' }).click() + await selectLineNumberAndRoute(page, lineNumber, route) + await lineNumber.click() + await page.getByLabel('close').locator('svg').click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() + + //clear Operator value test + await selectLineNumberAndRoute(page, lineNumber, route) + await operator.click() + await page.getByRole('button', { name: 'Clear' }).click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() }) test('test in SingleLineMapPage', async ({ page }) => { - await page.goto('/') - await page.getByText('מפה לפי קו', { exact: true }).click() - await page.waitForURL(/single-line/) + await visitPage(page, 'מפה לפי קו', /single-line/) + await fillDate(page) + const { operator, lineNumber, route, stop } = new Selectors(page) + + //clear LineNumber value test + await operator.click() + await page.getByRole('option', { name: 'אלקטרה אפיקים' }).click() + await selectLineNumberAndRoute(page, lineNumber, route) + await lineNumber.click() + await page.getByLabel('close').locator('svg').click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() + + //clear Operator value test + await selectLineNumberAndRoute(page, lineNumber, route) + await operator.click() + await page.getByRole('button', { name: 'Clear' }).click() + await expect(route).not.toBeVisible() + await expect(stop).not.toBeVisible() }) test('test in RealtimeMapPage', async ({ page }) => { - await page.goto('/') - await page.getByText('מפה בזמן אמת', { exact: true }).click() - await page.waitForURL(/map/) - await page.getByRole('progressbar').waitFor({ state: 'hidden' }) + await visitPage(page, 'מפה בזמן אמת', /map/) const minutes = page.getByLabel('דקות') let getValueAttribute = await minutes.getAttribute('value') if (!getValueAttribute) return test.fail() diff --git a/tests/realtimemap.spec.ts b/tests/realtimemap.spec.ts index 3706b09a..959fd2b8 100644 --- a/tests/realtimemap.spec.ts +++ b/tests/realtimemap.spec.ts @@ -2,9 +2,10 @@ import { test } from '@playwright/test' test('realtime-map page', async ({ page }) => { await page.goto('/') - await page.getByText('מפה בזמן אמת').click() + await page.getByText('מפה בזמן אמת', { exact: true }).click() await page.waitForURL(/map/) - await page.getByLabel('בחירת תאריך, התאריך שנבחר הוא').click() + await page.getByRole('progressbar').waitFor({ state: 'hidden' }) + await page.getByLabel('בחירת תאריך').click() await page.getByRole('gridcell', { name: '1', exact: true }).click() await page.getByLabel('דקות').fill('6') })