У нас четыре файла:
import { chromium, test} from '@playwright/test'
import * as videoPageData from '../services/data/videoPage.data.json'
import VideoPageSteps from '../services/steps/videoPage.steps'
import VideoPage from '../services/pages/videoPage'
test.describe('Test suite', () => {
let videoPage: VideoPage
let videoPageSteps: VideoPageSteps
test.beforeAll(async () => {
const browser = await chromium.launch()
const page = await browser.newPage()
videoPageSteps = new VideoPageSteps(page, videoPage)
await page.goto(videoPageData.data.baseURL, {waitUntil: 'load'})
})
test('Entering a search query', async () => {
await videoPageSteps.insertQueryText(videoPageData.data.queryText)
})
})
import { Page } from 'playwright'
import VideoPage from '../pages/videoPage'
export default class VideoPageSteps {
private page: Page
private videoPage: VideoPage
constructor(page: Page, videoPage: VideoPage) {
this.page = page
this.videoPage = videoPage
}
async insertQueryText(queryText: string) {
await this.videoPage.getInput().isVisible()
await this.videoPage.getInput().fill(queryText)
}
}
import { Locator, Page } from '@playwright/test'
import * as selectors from '../../selectors.json'
export default class VideoPage {
constructor(page: Page) {
this.page = page;
}
private page: Page
public getInput(): Locator {
return this.page.locator(selectors.videoPage.input)
}
}
selectors.json:
{
"videoPage": {
"input": "//input[contains(@class, 'suggest__input')]",
}
}
Ошибка при запуске:
TypeError: Cannot read properties of undefined (reading 'getInput')
Буду признателен за подсказку