08ea5fbe98
添加用户管理视图、API和状态管理文件
179 lines
5.2 KiB
TypeScript
179 lines
5.2 KiB
TypeScript
import { Page } from 'playwright';
|
|
|
|
export class MiniProgramSearchPage {
|
|
constructor(private page: Page) {}
|
|
|
|
async navigate() {
|
|
await this.page.goto('http://localhost:9527/#/pages/search/index');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async search(keyword: string) {
|
|
await this.page.fill('.search-input input', keyword);
|
|
await this.page.click('.search-button');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async clearSearch() {
|
|
await this.page.click('.clear-button');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getSearchResults() {
|
|
const results = await this.page.locator('.search-result').allTextContents();
|
|
return results;
|
|
}
|
|
|
|
async getResultCount() {
|
|
const count = await this.page.locator('.search-result').count();
|
|
return count;
|
|
}
|
|
|
|
async hasResults() {
|
|
const count = await this.getResultCount();
|
|
return count > 0;
|
|
}
|
|
|
|
async noResults() {
|
|
const noResults = this.page.locator('.no-results');
|
|
return await noResults.isVisible();
|
|
}
|
|
|
|
async tapResult(index: number) {
|
|
await this.page.tap(`.search-result:nth-child(${index + 1})`);
|
|
}
|
|
|
|
async longPressResult(index: number) {
|
|
const element = this.page.locator(`.search-result:nth-child(${index + 1})`);
|
|
await element.tap();
|
|
await this.page.waitForTimeout(500);
|
|
}
|
|
|
|
async getResultTitle(index: number) {
|
|
const title = await this.page.locator(`.search-result:nth-child(${index + 1}) .result-title`).textContent();
|
|
return title || '';
|
|
}
|
|
|
|
async getResultDescription(index: number) {
|
|
const description = await this.page.locator(`.search-result:nth-child(${index + 1}) .result-description`).textContent();
|
|
return description || '';
|
|
}
|
|
|
|
async getResultDate(index: number) {
|
|
const date = await this.page.locator(`.search-result:nth-child(${index + 1}) .result-date`).textContent();
|
|
return date || '';
|
|
}
|
|
|
|
async filterByType(type: string) {
|
|
await this.page.click(`.filter-type[data-type="${type}"]`);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async filterByDate(startDate: string, endDate: string) {
|
|
await this.page.click('.filter-date');
|
|
await this.page.fill('.filter-start-date input', startDate);
|
|
await this.page.fill('.filter-end-date input', endDate);
|
|
await this.page.click('.apply-filter');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async sortBy(sortType: string) {
|
|
await this.page.click('.sort-button');
|
|
await this.page.click(`.sort-option[data-sort="${sortType}"]`);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getCurrentSort() {
|
|
const currentSort = await this.page.locator('.current-sort').textContent();
|
|
return currentSort || '';
|
|
}
|
|
|
|
async getActiveFilters() {
|
|
const activeFilters = await this.page.locator('.active-filter').allTextContents();
|
|
return activeFilters;
|
|
}
|
|
|
|
async clearFilters() {
|
|
await this.page.click('.clear-filters');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async saveSearch(keyword: string) {
|
|
await this.search(keyword);
|
|
await this.page.click('.save-search-button');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getSavedSearches() {
|
|
const savedSearches = await this.page.locator('.saved-search').allTextContents();
|
|
return savedSearches;
|
|
}
|
|
|
|
async deleteSavedSearch(keyword: string) {
|
|
await this.page.click(`.saved-search[data-keyword="${keyword}"] .delete-button`);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getRecentSearches() {
|
|
const recentSearches = await this.page.locator('.recent-search').allTextContents();
|
|
return recentSearches;
|
|
}
|
|
|
|
async clearRecentSearches() {
|
|
await this.page.click('.clear-recent');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getSearchSuggestions(keyword: string) {
|
|
await this.page.fill('.search-input input', keyword);
|
|
await this.page.waitForTimeout(500);
|
|
const suggestions = await this.page.locator('.search-suggestion').allTextContents();
|
|
return suggestions;
|
|
}
|
|
|
|
async selectSuggestion(index: number) {
|
|
await this.page.tap(`.search-suggestion:nth-child(${index + 1})`);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async swipeLeft() {
|
|
await this.page.touchscreen.tap(0, 0);
|
|
await this.page.touchscreen.tap(100, 0);
|
|
}
|
|
|
|
async swipeRight() {
|
|
await this.page.touchscreen.tap(100, 0);
|
|
await this.page.touchscreen.tap(0, 0);
|
|
}
|
|
|
|
async swipeUp() {
|
|
await this.page.touchscreen.tap(0, 100);
|
|
await this.page.touchscreen.tap(0, 0);
|
|
}
|
|
|
|
async swipeDown() {
|
|
await this.page.touchscreen.tap(0, 0);
|
|
await this.page.touchscreen.tap(0, 100);
|
|
}
|
|
|
|
async getSearchHistory() {
|
|
const searchHistory = await this.page.locator('.search-history').allTextContents();
|
|
return searchHistory;
|
|
}
|
|
|
|
async clearSearchHistory() {
|
|
await this.page.click('.clear-search-history');
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
|
|
async getHotSearches() {
|
|
const hotSearches = await this.page.locator('.hot-search').allTextContents();
|
|
return hotSearches;
|
|
}
|
|
|
|
async tapHotSearch(index: number) {
|
|
await this.page.tap(`.hot-search:nth-child(${index + 1})`);
|
|
await this.page.waitForLoadState('networkidle');
|
|
}
|
|
}
|