const ScreenType = Object.freeze({ Desktop: 'desktop', Tablet: 'tablet', Mobile: 'mobile' }); class Website { constructor(page, options = {}) { this.page = page; this.screenType = ScreenType.Desktop; this.runAgainstProduction = options.production || process.env.RUN_AGAINST_PRODUCTION === 'true'; if (this.runAgainstProduction) { this.baseUrl = 'https://igpfanreference.ca'; } else { const hook = process.env.TEST_HOOK || ''; this.deploymentType = hook.includes('localhost') ? 'Local' : 'Dev'; this.baseUrl = 'https://localhost:7234'; } const BuildCalculatorPage = require('../pages/buildCalculatorPage'); const HarassCalculatorPage = require('../pages/harassCalculator.page'); const DatabasePage = require('../pages/database.page'); const DatabaseSinglePage = require('../pages/databaseSingle.page'); const NavigationBar = require('../shared/navigationBar'); const WebsiteSearchDialog = require('../shared/websiteSearchDialog'); this.buildCalculatorPage = new BuildCalculatorPage(this); this.harassCalculatorPage = new HarassCalculatorPage(this); this.databasePage = new DatabasePage(this); this.databaseSinglePage = new DatabaseSinglePage(this); this.navigationBar = new NavigationBar(this); this.websiteSearchDialog = new WebsiteSearchDialog(this); } locator(selector) { return this.page.locator(selector); } find(byId) { return this.page.locator(`#${byId}`); } findWithParent(byId, withParentId) { return this.page.locator(`#${withParentId} #${byId}`); } findScreenSpecific(byId) { return this.page.locator(`#${this.screenType}-${byId}`); } findAll(byId) { return this.page.locator(`#${byId}`); } findAllWithTag(tag) { return this.page.locator(tag); } findAllWithTagFromElement(element, tag) { return element.locator(tag); } findButtonWithLabel(label) { return this.page.locator(`button[label="${label}"]`); } findChildren(ofId, tagname) { return this.page.locator(`#${ofId} ${tagname}`); } async findText(byId) { return (await this.page.locator(`#${byId}`).textContent()) || ''; } async findInt(byId) { const text = await this.findText(byId); return parseInt(text, 10); } async clickSearchBackground() { await this.page.locator('#searchBackground').click(); } async clickElement(element) { await element.click(); } async enterInput(element, value) { await element.fill(String(value)); await element.press('Enter'); } async goto(path) { if (path) { await this.page.goto(`${this.baseUrl}/${path}`); } else { await this.page.goto(this.baseUrl); } } } module.exports = { Website, ScreenType };