Skip to content

Commit

Permalink
Improve Playwright GitHub Actions cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jun 27, 2023
1 parent 1ae840a commit f854a94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
9 changes: 5 additions & 4 deletions pwa/tests/Page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Browser, Page} from "@playwright/test";
import {Browser, expect, Page} from "@playwright/test";

export class Pages {
private page: Page | undefined;
Expand All @@ -9,13 +9,14 @@ export class Pages {
public async getHomePage(browser: Browser) {
this.page = await (await browser.newContext({ignoreHTTPSErrors: true})).newPage();
await this.page.goto('https://localhost' + this.url)
await this.page.waitForTimeout(1500)
await this.page.waitForURL('https://localhost' + this.url)
return this.page
}

public async changePage(locator: string) {
await this.page?.getByLabel(locator, {exact: true}).click()
await this.page?.waitForTimeout(1500)
const element = this.page?.getByLabel(locator, {exact: true})
await element.click()
await expect(element).toHaveCount(0)
}

public async getPages(browser: Browser) {
Expand Down
4 changes: 2 additions & 2 deletions pwa/tests/admin/OpenApi/Books.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('Go to Admin Books Create Open Api', async ({browser}) => {
await page.getElsClickable('link', 'Create')
await page.getPages(browser).then(async (page) => {
await page.reload()
await page.waitForTimeout(1500)
await page.waitForSelector('input:nth(4)')
await page.locator('input').nth(4).fill('2023-05-02T15:51')
await page.getByLabel('Add').click()
await page.locator('input').last().fill(reviewsUrl.replaceAll('"', ''))
Expand All @@ -69,7 +69,7 @@ test('Go to Admin Books Edit Open Api', async ({browser}) => {
await expect((await page.getPages(browser)).url()).toContain(url)
await page.getPages(browser).then(async (page) => {
await page.reload()
await page.waitForTimeout(1500)
await page.waitForSelector('button[aria-label="Add"]')
await page.getByLabel('Add').click()
await page.locator('input').last().fill(reviewsUrl.replaceAll('"', ''))
})
Expand Down
25 changes: 14 additions & 11 deletions pwa/tests/admin/PageAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export class PageAdmin {
public async getAdminPage(browser: Browser) {
this.page = await (await browser.newContext({ignoreHTTPSErrors: true})).newPage()
await this.page.goto('https://localhost/admin#/login')
await this.page.waitForTimeout(1500)
await this.page.getByRole('button', {name: 'SIGN IN'}).click()
await this.page.waitForTimeout(1500)
await this.page.waitForURL('https://localhost/admin#/login')
const signInButton = this.page.getByRole('button', {name: 'SIGN IN'});
await signInButton.click()
await expect(signInButton).toHaveCount(0)
await expect(this.page.url()).toEqual('https://localhost/admin#/books')
return this.page
}
Expand All @@ -23,8 +24,9 @@ export class PageAdmin {
}

public async getElsClickable(role: "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "deletion" | "dialog" | "directory" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "meter" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "paragraph" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem", name: string) {
await this.page?.getByRole(role, {name: name, exact: true}).last().click()
await this.page?.waitForTimeout(1500)
const element = this.page?.getByRole(role, {name: name, exact: true}).last()
await element.click()
await expect(element).toHaveCount(0)
}

public async fillData(label: string, data: string) {
Expand All @@ -38,26 +40,27 @@ export class PageAdmin {

public async goToReviews() {
await this.getElsClickable('menuitem', 'Reviews')
await this.page?.waitForTimeout(1500)
await this.page?.waitForResponse('https://localhost/reviews')
await expect(this.page?.url()).toEqual('https://localhost/admin#/reviews')
}

public async goToTopBooks() {
await this.page?.getByRole('menuitem', {name: 'Top books'}).click()
await this.page?.waitForTimeout(1500)
await this.page?.waitForResponse('https://localhost/top_books')
await expect(this.page?.url()).toEqual('https://localhost/admin#/top_books')
}

public async changePage(locator: string) {
await this.page?.getByLabel(locator, {exact: true}).click()
await this.page?.waitForTimeout(1500)
const element = this.page?.getByLabel(locator, {exact: true})
await element.click()
await expect(element).toHaveCount(0)
}

public async goToOpenApi() {
await this.page?.getByRole('button', {name: 'Hydra'}).click()
await this.page?.waitForTimeout(300)
await expect(this.page?.locator('div#doc-type-menu')).toHaveCount(1)
await this.page?.locator('ul').last().locator('li').last().click()
await this.page?.waitForTimeout(300)
await expect(this.page?.locator('div#doc-type-menu')).toHaveCount(0)

}
}

0 comments on commit f854a94

Please sign in to comment.