Files
IGP-Fan-Reference/Playwright/pages/buildCalculator/armyComponent.js
T
2026-05-31 14:33:58 -04:00

53 lines
1.3 KiB
JavaScript

class ArmyComponent {
constructor(page) {
this.page = page;
}
armyView() {
return this.page.locator('.armyView');
}
displayValue(label) {
return this.page.locator('.displayContainer').filter({ hasText: label }).locator('.displayContent');
}
armyCards() {
return this.armyView().locator('.armyCard');
}
async getArmyCompletedAt() {
return await this.displayValue('Army Completed At').textContent();
}
async getArmyAttackingAt() {
return await this.displayValue('Army Attacking At').textContent();
}
async getArmyUnitNames() {
const cards = await this.armyCards().all();
const names = [];
for (const card of cards) {
const text = await card.innerText();
const match = text.match(/\d+x\s*(.+)/);
names.push(match ? match[1].trim() : text.trim());
}
return names;
}
async getArmyUnitCounts() {
const cards = await this.armyCards().all();
const counts = [];
for (const card of cards) {
const countEl = card.locator('.armyCount');
const nameEl = card.locator('div').last();
const count = await countEl.textContent();
const name = await nameEl.textContent();
const num = count ? parseInt(count.replace('x', ''), 10) : 0;
counts.push({ name: (name || '').trim(), count: num });
}
return counts;
}
}
module.exports = ArmyComponent;