-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5204 from Gustry/pom-project-page-playwright
Tests - Start Page Object Model for Playwright
- Loading branch information
Showing
6 changed files
with
215 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// @ts-check | ||
import {expect, Locator, Page} from '@playwright/test'; | ||
import { gotoMap } from '../globals'; | ||
|
||
export class ProjectPage { | ||
/** @type {Page} */ | ||
page; | ||
|
||
// Metadata | ||
/** | ||
* Project name metadata | ||
* @type {string} | ||
*/ | ||
project; | ||
/** | ||
* Repository name metadata | ||
* @type {string} | ||
*/ | ||
repository; | ||
|
||
// Menu | ||
/** | ||
* Layer switcher menu | ||
* @type {Locator} | ||
*/ | ||
switcher; | ||
/** | ||
* Editing menu | ||
* @type {Locator} | ||
*/ | ||
buttonEditing; | ||
|
||
// Docks | ||
/** | ||
* Attribute table dock | ||
* @type {Locator} | ||
*/ | ||
attributeTable; | ||
/** | ||
* Main left dock | ||
* @type {Locator} | ||
*/ | ||
dock; | ||
/** | ||
* Right dock | ||
* @type {Locator} | ||
*/ | ||
rightDock; | ||
/** | ||
* Bottom dock | ||
* @type {Locator} | ||
*/ | ||
bottomDock; | ||
/** | ||
* Mini dock | ||
* @type {Locator} | ||
*/ | ||
miniDock; | ||
/** | ||
* Top search bar | ||
* @type {Locator} | ||
*/ | ||
search; | ||
|
||
// Messages | ||
/** | ||
* Foreground message bar | ||
* @type {Locator} | ||
*/ | ||
warningMessage; | ||
|
||
/** | ||
* Attribute table for the given layer name | ||
* @param {string} name Name of the layer | ||
* @returns {Locator} | ||
*/ | ||
attributeTableHtml = (name) => | ||
this.page.locator(`#attribute-layer-table-${name}`); | ||
|
||
/** | ||
* Constructor | ||
* @param {Page} page The playwright page | ||
* @param {string} project The project name | ||
* @param {string} repository The repository name, default to testsrepository | ||
*/ | ||
constructor(page, project, repository = 'testsrepository') { | ||
this.page = page; | ||
this.project = project; | ||
this.repository = repository; | ||
this.dock = page.locator('#dock'); | ||
this.rightDock = page.locator('#right-dock'); | ||
this.bottomDock = page.locator('#bottom-dock'); | ||
this.miniDock = page.locator('#mini-dock-content'); | ||
this.warningMessage = page.locator('#lizmap-warning-message'); | ||
this.search = page.locator('#search-query'); | ||
this.switcher = page.locator('#button-switcher'); | ||
this.buttonEditing = page.locator('#button-edition'); | ||
} | ||
|
||
/** | ||
* open function | ||
* Open the URL for the given project and repository | ||
*/ | ||
async open(){ | ||
await gotoMap(`/index.php/view/map?repository=${this.repository}&project=${this.project}`, this.page); | ||
} | ||
|
||
/** | ||
* openAttributeTable function | ||
* Open the attribute table for the given layer | ||
* @param {string} layer Name of the layer | ||
* @param {boolean} maximise If the attribute table must be maximised | ||
*/ | ||
async openAttributeTable(layer, maximise = false){ | ||
await this.page.locator('a#button-attributeLayers').click(); | ||
if (maximise) { | ||
await this.page.getByRole('button', { name: 'Maximize' }).click(); | ||
} | ||
await this.page.locator('#attribute-layer-list-table').locator(`button[value=${layer}]`).click(); | ||
} | ||
|
||
/** | ||
* editingSubmitForm function | ||
* Submit the form | ||
* @param {string} futureAction The action to do after submit : can be close/create/edit. | ||
*/ | ||
async editingSubmitForm(futureAction = 'close'){ | ||
await this.page.locator('#jforms_view_edition_liz_future_action').selectOption(futureAction); | ||
await this.page.locator('#jforms_view_edition__submit_submit').click(); | ||
if (futureAction === 'close'){ | ||
await expect(this.page.locator('#edition-form-container')).toBeHidden(); | ||
} else { | ||
await expect(this.page.locator('#edition-form-container')).toBeVisible(); | ||
} | ||
await expect(this.page.locator('#lizmap-edition-message')).toBeVisible(); | ||
} | ||
|
||
/** | ||
* openEditingFormWithLayer function | ||
* Open the editing panel with the given layer name form | ||
* @param {string} layer Name of the layer | ||
*/ | ||
async openEditingFormWithLayer(layer){ | ||
await this.buttonEditing.click(); | ||
await this.page.locator('#edition-layer').selectOption({ label: layer }); | ||
await this.page.locator('a#edition-draw').click(); | ||
} | ||
|
||
/** | ||
* clickOnMap function | ||
* Click on the map at the given position | ||
* @param {number} x Position X on the map | ||
* @param {number} y Position Y on the map | ||
*/ | ||
async clickOnMap(x, y){ | ||
await this.page.locator('#newOlMap').click({ | ||
position: { | ||
x: x, | ||
y: y | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
// @ts-check | ||
import { test, expect } from '@playwright/test'; | ||
import { gotoMap } from './globals'; | ||
import { ProjectPage } from './pages/project'; | ||
|
||
test.describe('Project warnings in CFG as admin', () => { | ||
test.use({ storageState: 'playwright/.auth/admin.json' }); | ||
|
||
test('Visit map with a warning', async ({ page }) => { | ||
const url = '/index.php/view/map?repository=testsrepository&project=project_cfg_warnings'; | ||
await gotoMap(url, page) | ||
|
||
await expect(page.locator("#lizmap-warning-message")).toBeVisible(); | ||
const project = new ProjectPage(page, 'project_cfg_warnings'); | ||
await project.open(); | ||
await expect(project.warningMessage).toBeVisible(); | ||
}); | ||
|
||
}); | ||
|
||
test.describe('Project warnings in CFG as anonymous', () => { | ||
|
||
test('Visit map without a warning', async ({ page }) => { | ||
const url = '/index.php/view/map?repository=testsrepository&project=project_cfg_warnings'; | ||
await gotoMap(url, page) | ||
|
||
await expect(page.locator("#lizmap-warning-message")).toHaveCount(0); | ||
const project = new ProjectPage(page, 'project_cfg_warnings'); | ||
await project.open(); | ||
await expect(project.warningMessage).toHaveCount(0); | ||
}); | ||
|
||
}); |
Oops, something went wrong.