/* Shared steps for the browser tests: log in through the real UI, get from the workshop into the lobby. */ 'use strict'; const { expect } = require('@playwright/test'); const mode = page => page.locator('body').getAttribute('data-mode'); // open the game in online mode and log in with name + password through the login card async function login(page, name, pass) { await page.goto('/?online'); await page.locator('#oLogin').fill(name); await page.locator('#oPass').fill(pass); await page.locator('#oGo').click(); await chooseCountry(page); await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage'); await expect(page.locator('#hUser')).toContainText(name); } // first start asks for a country - take the default async function chooseCountry(page) { const go = page.locator('#cfGo'); try { await go.waitFor({ timeout: 4000 }); await go.click(); } catch (e) { /* already chosen */ } } async function toLobby(page) { await page.locator('#bLeague').click(); await expect(page.locator('body')).toHaveAttribute('data-mode', 'lobby'); } // the header shows big amounts short like Kit.fmt does ("10.8K", "1.20M", "3B") const UNIT = { K: 1e3, M: 1e6, B: 1e9 }; const parseCredits = text => { const m = String(text).replace(/[,\s]/g, '').match(/([\d.]+)([KMB]?)/i); return m ? Math.round(parseFloat(m[1]) * (UNIT[(m[2] || '').toUpperCase()] || 1)) : NaN; }; const credits = async page => parseCredits(await page.locator('#hMoney').textContent()); module.exports = { mode, login, chooseCountry, toLobby, credits, parseCredits };