feat: playwright tests withability tio test running or not server not lonly in localhost mode
This commit is contained in:
parent
bd4aa9c0ac
commit
49d6f17779
|
@ -2,6 +2,8 @@
|
|||
import https from 'node:https'
|
||||
import { type Page, expect, test } from '@playwright/test'
|
||||
|
||||
const baseHost = process.env.BASE_URL || 'https://localhost:3000'
|
||||
|
||||
/* Global starting test config */
|
||||
|
||||
let page: Page
|
||||
|
@ -44,7 +46,7 @@ async function waitForServer(url: string, timeout = 150000) {
|
|||
test.beforeAll(async ({ browser }) => {
|
||||
console.log('Waiting for the server to start...')
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
const baseURL = 'https://localhost:3000'
|
||||
const baseURL = `${baseHost}`
|
||||
await waitForServer(baseURL)
|
||||
page = await browser.newPage()
|
||||
test.setTimeout(150000)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
import https from 'node:https'
|
||||
import { type Page, expect, test } from '@playwright/test'
|
||||
|
||||
const baseHost = process.env.BASE_URL || 'https://localhost:3000'
|
||||
|
||||
/* Global starting test config */
|
||||
|
||||
let page: Page
|
||||
|
@ -44,7 +46,7 @@ async function waitForServer(url: string, timeout = 150000) {
|
|||
test.beforeAll(async ({ browser }) => {
|
||||
console.log('Waiting for the server to start...')
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
const baseURL = 'https://localhost:3000'
|
||||
const baseURL = `${baseHost}`
|
||||
await waitForServer(baseURL)
|
||||
page = await browser.newPage()
|
||||
test.setTimeout(150000)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
import https from 'node:https'
|
||||
import { type Page, expect, test } from '@playwright/test'
|
||||
|
||||
const baseHost = process.env.BASE_URL || 'https://localhost:3000'
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
let context: any
|
||||
let page: Page
|
||||
|
@ -46,7 +48,7 @@ async function waitForServer(url: string, timeout = 150000) {
|
|||
test.beforeAll(async ({ browser }) => {
|
||||
console.log('Waiting for the server to start...')
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
const baseURL = 'https://localhost:3000'
|
||||
const baseURL = `${baseHost}`
|
||||
await waitForServer(baseURL)
|
||||
context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import { expect, test } from '@playwright/test'
|
||||
|
||||
const baseHost = process.env.BASE_HOST || 'https://localhost:3000'
|
||||
|
||||
const pagesTitles: { [key: string]: RegExp } = {
|
||||
'/': /Дискурс/,
|
||||
'/feed': /Лента/,
|
||||
'/edit/new': /Выберите тип публикации/,
|
||||
'/guide/support': /Поддержите Дискурс/,
|
||||
'/author': /Авторы/,
|
||||
'/topic': /Темы и сюжеты/,
|
||||
'/inbox': /Входящие/
|
||||
}
|
||||
|
||||
Object.keys(pagesTitles).forEach((res: string) => {
|
||||
test(`страница ${res}`, async ({ page }) => {
|
||||
await page.goto(`${baseHost}${res}`)
|
||||
const title = pagesTitles[res]
|
||||
await expect(page).toHaveTitle(title)
|
||||
})
|
||||
})
|
|
@ -1,37 +0,0 @@
|
|||
import { chromium } from 'playwright'
|
||||
;(async () => {
|
||||
const browser = await chromium.launch()
|
||||
const context = await browser.newContext()
|
||||
|
||||
// Define the URLs to visit
|
||||
const pagesToVisit = [
|
||||
'https://localhost:3000/',
|
||||
'https://localhost:3000/feed',
|
||||
'https://localhost:3000/edit/new',
|
||||
'https://localhost:3000/guide/support',
|
||||
'https://localhost:3000/author',
|
||||
'https://localhost:3000/topic',
|
||||
'https://localhost:3000/inbox'
|
||||
]
|
||||
|
||||
// Loop through the pages and visit each one
|
||||
for (const pageUrl of pagesToVisit) {
|
||||
const page = await context.newPage()
|
||||
|
||||
// Log a message before visiting the page
|
||||
console.log(`Visiting page: ${pageUrl}`)
|
||||
|
||||
await page.goto(pageUrl)
|
||||
|
||||
// Add your test assertions here if needed
|
||||
|
||||
// Log a message after visiting the page
|
||||
console.log(`Finished visiting page: ${pageUrl}`)
|
||||
|
||||
// Close the page before moving to the next one
|
||||
await page.close()
|
||||
}
|
||||
|
||||
// Close the browser
|
||||
await browser.close()
|
||||
})()
|
|
@ -2,6 +2,8 @@
|
|||
import https from 'node:https'
|
||||
import { type Page, expect, test } from '@playwright/test'
|
||||
|
||||
const baseHost = process.env.BASE_URL || 'https://localhost:3000'
|
||||
|
||||
/* Global starting test config */
|
||||
|
||||
let page: Page
|
||||
|
@ -44,7 +46,7 @@ async function waitForServer(url: string, timeout = 150000) {
|
|||
test.beforeAll(async ({ browser }) => {
|
||||
console.log('Waiting for the server to start...')
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
const baseURL = 'https://localhost:3000'
|
||||
const baseURL = `${baseHost}`
|
||||
await waitForServer(baseURL)
|
||||
page = await browser.newPage()
|
||||
test.setTimeout(150000)
|
||||
|
|
Loading…
Reference in New Issue
Block a user