You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ghost/e2e/helpers/pages/admin/analytics/AnalyticsWebTrafficPage.ts

67 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import {Locator, Page} from '@playwright/test';
import {AdminPage} from '../AdminPage';
export class AnalyticsWebTrafficPage extends AdminPage {
// 总浏览数 / 总访问量 选项卡的定位器
readonly totalViewsTab: Locator;
// 唯一访客数 选项卡的定位器
readonly totalUniqueVisitorsTab: Locator;
// 页面中展示流量折线/图表的容器定位器(使用 data-testid
private readonly webGraph: Locator;
// “Top content” 卡片及其内部的选项卡定位器Posts & pages / Posts / Pages
readonly topContentCard: Locator;
readonly postsAndPagesButton: Locator;
readonly postsButton: Locator;
readonly pagesButton: Locator;
// “Top sources” 卡片的定位器(显示来源统计)
public readonly topSourcesCard: Locator;
constructor(page: Page) {
super(page);
// 页面对应的 hash 路由,用于 goto() 等导航判断
this.pageUrl = '/ghost/#/analytics/web';
// 使用可访问性角色定位选项卡(便于稳定定位)
this.totalViewsTab = page.getByRole('tab', {name: 'Total views'});
this.totalUniqueVisitorsTab = page.getByRole('tab', {name: 'Unique visitors'});
// 使用 data-testid 定位图表容器,便于直接读取文本或存在性检查
this.webGraph = page.getByTestId('web-graph');
// Top content 卡片及内部按钮定位
this.topContentCard = page.getByTestId('top-content-card');
this.postsAndPagesButton = this.topContentCard.getByRole('tab', {name: 'Posts & pages'});
this.postsButton = this.topContentCard.getByRole('tab', {name: 'Posts', exact: true});
this.pagesButton = this.topContentCard.getByRole('tab', {name: 'Pages', exact: true});
this.topSourcesCard = page.getByTestId('top-sources-card');
}
// 返回 webGraph 的文本内容(可用于断言图表上方的汇总数或提示文本)
async totalViewsContent() {
return await this.webGraph.textContent();
}
// 返回“Unique visitors”选项卡的文本内容通常包含数字或标签
async totalUniqueVisitorsContent() {
return await this.totalUniqueVisitorsTab.textContent();
}
// 切换到“Total views”选项卡模拟用户点击
async viewTotalViews() {
await this.totalViewsTab.click();
}
// 切换到“Unique visitors”选项卡模拟用户点击
async viewTotalUniqueVisitors() {
await this.totalUniqueVisitorsTab.click();
}
// 读取 webGraph 的文本内容(方法名表示读取图表内容)
async viewWebGraphContent() {
await this.webGraph.textContent();
}
}