Skip to content

Commit 876352d

Browse files
authored
Merge pull request #5 from vOrigins/feature/playground-localhost
Fix checking playground on localhost
2 parents 70009af + 3e99b18 commit 876352d

File tree

9 files changed

+50
-21
lines changed

9 files changed

+50
-21
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ Before starting test execution, you need to set environment variables in any con
2626

2727
**TEST_USER_PASSWORD** - The password that will be used by test users.
2828

29+
**PLAYGROUND_BACKEND_HOST** - Only Required for testing on **localhost**. The host that will be used in the test to create a custom server for sending requests. More information can be found at the [link](https://github.com/Netcracker/qubership-apihub/issues/18).
30+
31+
**DEV_PROXY_MODE** - Only Required for testing on **localhost** in dev proxy mode.
32+
33+
`true` - skip tests that cannot be executed in this mode.
34+
2935
### Optional environment variables:
3036
**TICKET_SYSTEM_URL** - Base address of the ticket management system. Adds interactivity to links to test cases and issues.
3137

@@ -69,7 +75,11 @@ Before starting test execution, you need to set environment variables in any con
6975
### Local test running
7076
Example of running tests for the Portal with three workers:
7177
```Shell
72-
npx playwright test --project=Portal --j=3
78+
npx playwright test --project=Portal --workers=3
79+
```
80+
Example of running only the tests that failed in the previous run:
81+
```Shell
82+
npx playwright test --project=Portal --last-failed
7383
```
7484
You can open the HTML report with the following command:
7585
```Shell

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
"version": "2.36.1-dev.0",
44
"license": "Apache-2.0",
55
"scripts": {
6-
"pw-report": "playwright show-report reports/playwright",
7-
"debug": "playwright test --headed --project=Portal --debug",
6+
"html-report": "playwright show-report reports/playwright",
7+
"debug": "playwright test --project=Portal --debug",
8+
"test-e2e-portal": "playwright test --project=Portal",
9+
"test-e2e-portal-last-failed": "playwright test --project=Portal --last-failed",
10+
"cleanup": "playwright test --project=Cleanup",
811
"lint": "eslint . --ext .ts,.tsx,.json --ignore-path .gitignore --max-warnings 0 --report-unused-disable-directives",
912
"format": "npm run lint --fix",
1013
"feature-start": "feature-start --featureName",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default defineConfig<Fixtures>({
4747
/* Fail the build on CI if you accidentally left test.only in the source code. */
4848
forbidOnly: !!process.env.CI,
4949
/* Retry on CI only */
50-
retries: process.env.CI ? 2 : 0,
50+
retries: 2,
5151
/* Opt out of parallel tests on CI. */
5252
workers: process.env.CI ? 10 : 3,
5353
/* Limit the number of failures on CI to save resources */

src/services/utils/browser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { type Credentials, type DownloadedTestFile, ROOT_DOWNLOADS } from '@shar
1919
import { readFile } from 'fs/promises'
2020
import { stringifyError } from './errors'
2121
import path from 'node:path'
22-
import { BASE_URL } from '@test-setup'
22+
import { BASE_ORIGIN, BASE_URL, PLAYGROUND_BACKEND_HOST } from '@test-setup'
23+
import process from 'process'
2324

2425
export const asyncTimeout = async (milliseconds: number): Promise<void> => {
2526
await new Promise(resolve => setTimeout(resolve, milliseconds))
@@ -55,3 +56,15 @@ export const getDownloadedFile = async (download: Download): Promise<DownloadedT
5556
export const isLocalHost = (): boolean => {
5657
return BASE_URL.hostname === 'localhost'
5758
}
59+
60+
export const isDevProxyMode = (): boolean => {
61+
return process.env.DEV_PROXY_MODE === 'true'
62+
}
63+
64+
export const getPlaygroundCustomServer = (): string => {
65+
if (isLocalHost()) {
66+
if (!PLAYGROUND_BACKEND_HOST) throw Error(`You run tests on localhost but PLAYGROUND_BACKEND_HOST is ${PLAYGROUND_BACKEND_HOST}`)
67+
return `${PLAYGROUND_BACKEND_HOST}/api/v1`
68+
}
69+
return `${BASE_ORIGIN}/api/v1`
70+
}

src/test-setup/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ export const BASE_ORIGIN = BASE_URL.origin
2323
const ticketSystemUrl = process.env.TICKET_SYSTEM_URL ? new URL(process.env.TICKET_SYSTEM_URL as string).origin : ''
2424

2525
export const TICKET_BASE_URL = ticketSystemUrl ? `${ticketSystemUrl}/browse/` : ''
26+
27+
export const { PLAYGROUND_BACKEND_HOST } = process.env

src/tests/global-setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ async function globalSetup(): Promise<void> {
2828
// Print environment variables
2929
logEnvVars([
3030
'BASE_URL',
31+
'PLAYGROUND_BACKEND_HOST',
32+
'DEV_PROXY_MODE',
3133
'TICKET_SYSTEM_URL',
3234
'AUTH',
3335
'CREATE_TD',

src/tests/portal/04-entity-actions/4.3.2-package-editing-publishing.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ test.describe('4.3.2 Package publishing via Portal', () => {
6666
await expect(configureVersionTab.filesUploader).toBeVisible()
6767
})
6868

69+
//Does not support localhost execution
6970
if (!isLocalHost()) {
7071
await test.step('Agent option', async () => {
7172
await portalPage.gotoPackage(testPackage)

src/tests/portal/05-view-details/5.2.1-package-details.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
V_P_PKG_WITHOUT_LABELS_R,
3434
} from '@test-data/portal'
3535
import { SYSADMIN } from '@test-data'
36-
import { isLocalHost } from '@services/utils'
36+
import { isDevProxyMode } from '@services/utils'
3737

3838
test.describe('5.2.1 Package details', () => {
3939

@@ -215,7 +215,7 @@ test.describe('5.2.1 Package details', () => {
215215
annotation: { type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-4655` },
216216
},
217217
async ({ sysadminPage: page }) => {
218-
test.skip(isLocalHost(), 'Does not support localhost execution')
218+
test.skip(isDevProxyMode(), 'Does not support dev proxy')
219219

220220
const portalPage = new PortalPage(page)
221221
const { versionPackagePage: versionPage } = portalPage

src/tests/portal/11-operations-details/11.1.1-details-rest-api-package.spec.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
V_P_PKG_OPERATIONS_REST_R,
3333
V_P_PKG_PLAYGROUND_R,
3434
} from '@test-data/portal'
35-
import { BASE_ORIGIN, SEARCH_TIMEOUT, TICKET_BASE_URL } from '@test-setup'
35+
import { SEARCH_TIMEOUT, TICKET_BASE_URL } from '@test-setup'
36+
import { getPlaygroundCustomServer } from '@services/utils'
3637

3738
test.describe('11.1.1 Operations details REST API (Package)', () => {
3839

@@ -300,7 +301,7 @@ test.describe('11.1.1 Operations details REST API (Package)', () => {
300301

301302
await test.step('Add server 2 and select it', async () => {
302303
await operationPage.playgroundPanel.serverSlt.addCustomServerBtn.click()
303-
await operationPage.playgroundPanel.addServerDialog.urlTxtFld.fill(`${BASE_ORIGIN}/api/v1`)
304+
await operationPage.playgroundPanel.addServerDialog.urlTxtFld.fill(getPlaygroundCustomServer())
304305
await operationPage.playgroundPanel.addServerDialog.addBtn.click()
305306
await operationPage.playgroundPanel.serverSlt.click()
306307

@@ -311,22 +312,19 @@ test.describe('11.1.1 Operations details REST API (Package)', () => {
311312
})
312313
})
313314

314-
//Playground doesn't work on localhost
315-
if (!portalPage.url().includes('localhost')) {
316-
await test.step('Send request without token (negative)', async () => {
317-
await operationPage.playgroundPanel.sendBtn.click()
315+
await test.step('Send request without token (negative)', async () => {
316+
await operationPage.playgroundPanel.sendBtn.click()
318317

319-
await expect(operationPage.playgroundPanel).toContainText('"message": "Unauthorized",')
320-
})
318+
await expect(operationPage.playgroundPanel).toContainText('"message": "Unauthorized",')
319+
})
321320

322-
await test.step('Send request with token and filters', async () => {
323-
await operationPage.playgroundPanel.tokenTxtFld.fill(accessToken)
321+
await test.step('Send request with token', async () => {
322+
await operationPage.playgroundPanel.tokenTxtFld.fill(accessToken)
324323

325-
await operationPage.playgroundPanel.sendBtn.click()
324+
await operationPage.playgroundPanel.sendBtn.click()
326325

327-
await expect(operationPage.playgroundPanel).toContainText('"backendVersion"')
328-
})
329-
}
326+
await expect(operationPage.playgroundPanel).toContainText('"backendVersion"')
327+
})
330328

331329
await test.step('Close Playground', async () => {
332330
await operationPage.toolbar.playgroundBtn.click()

0 commit comments

Comments
 (0)