Skip to content

Commit 3e99b18

Browse files
committed
feat: handle running UI tests on localhost
1 parent 0b3519a commit 3e99b18

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
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

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
V_P_PKG_WITHOUT_LABELS_R,
3434
} from '@test-data/portal'
3535
import { SYSADMIN } from '@test-data'
36+
import { isDevProxyMode } from '@services/utils'
3637

3738
test.describe('5.2.1 Package details', () => {
3839

@@ -214,6 +215,7 @@ test.describe('5.2.1 Package details', () => {
214215
annotation: { type: 'Test Case', description: `${TICKET_BASE_URL}TestCase-A-4655` },
215216
},
216217
async ({ sysadminPage: page }) => {
218+
test.skip(isDevProxyMode(), 'Does not support dev proxy')
217219

218220
const portalPage = new PortalPage(page)
219221
const { versionPackagePage: versionPage } = portalPage

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +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'
36-
import { isLocalHost } from '@services/utils'
35+
import { SEARCH_TIMEOUT, TICKET_BASE_URL } from '@test-setup'
36+
import { getPlaygroundCustomServer } from '@services/utils'
3737

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

@@ -262,7 +262,6 @@ test.describe('11.1.1 Operations details REST API (Package)', () => {
262262
const { operationPage } = portalPage
263263
const accessToken = (await getAuthDataFromPage(page)).token
264264
const testPackage = P_PK_PGND
265-
const testCustomServerHost = isLocalHost() ? 'http://host.docker.internal:8081/api/v1' : `${BASE_ORIGIN}/api/v1`
266265

267266
await portalPage.gotoOperation(versionPlayground, GET_SYSTEM_INFO)
268267
await operationPage.toolbar.playgroundBtn.click()
@@ -302,7 +301,7 @@ test.describe('11.1.1 Operations details REST API (Package)', () => {
302301

303302
await test.step('Add server 2 and select it', async () => {
304303
await operationPage.playgroundPanel.serverSlt.addCustomServerBtn.click()
305-
await operationPage.playgroundPanel.addServerDialog.urlTxtFld.fill(testCustomServerHost)
304+
await operationPage.playgroundPanel.addServerDialog.urlTxtFld.fill(getPlaygroundCustomServer())
306305
await operationPage.playgroundPanel.addServerDialog.addBtn.click()
307306
await operationPage.playgroundPanel.serverSlt.click()
308307

0 commit comments

Comments
 (0)