[Playwright] Migrate Teachers to playwright

This commit is contained in:
Aaro Koivukangas
2026-08-09 01:48:41 +03:00
committed by Aaro Koivukangas
parent 312f817694
commit 77e6c7f554
2 changed files with 83 additions and 56 deletions
-56
View File
@@ -1,56 +0,0 @@
import { test, expect } from '@playwright/test'
/// <reference types="cypress" />
test.describe('Teachers page tests', () => {
test.beforeEach(async ({ page }) => {
// login as admin = has teacher rights
cy.init('/teachers', 'admin')
cy.url().should('include', '/teachers')
})
const teacher1 = 'Luokkanen Liisa Viljami'
const teacher2 = 'Perälä Juhani Susanna'
const statisticsHeaders = ['Name', 'Credits', 'Credits transferred', 'Passed']
test('Check Statistics', async ({ page }) => {
cy.cs('semester-start').click()
page.locator('text=Syksy 2020').click()
cy.cs('course-providers').click()
page.locator('text=Matemaattisten tieteiden kandiohjelma').click()
page.locator('body').click(0, 0)
cy.cs('search-statistics').click()
cy.contains('Teacher')
expect(page.locator('table thead tr th')).toHaveCount(4)
statisticsHeaders.forEach((header, index) => {
cy.get('table thead tr th').eq(index).should('contain', header)
})
cy.contains('td', teacher1).siblings().eq(0).contains('235')
cy.contains('td', teacher1).siblings().eq(2).contains('97.40%')
cy.contains('td', teacher2).siblings().eq(0).contains('395')
cy.contains('td', teacher2).siblings().eq(2).contains('98.78%')
})
test('Teacher search works', async ({ page }) => {
cy.cs('Search').click()
cy.cs('teacher-search').type(teacher1.split(' ')[0])
expect(page.locator('table tbody tr')).toHaveCount(4)
cy.get('table tbody tr').eq(2).contains('td', teacher1)
})
test('Can check teacher page', async ({ page }) => {
cy.cs('Search').click()
cy.cs('teacher-search').type(teacher2)
// Prevent opening in new tab
cy.contains('a', teacher2).invoke('removeAttr', 'target').click()
cy.url().should('include', '/teachers/hy-hlo-49026530')
cy.contains(teacher2)
page.locator('text=Syksy 2023').click()
page.locator('text=Kev\u00E4t 2019').click()
cy.contains('tr', 'MAT12004').within(() => {
const rowContent = ['MAT12004', 'Tilastollinen päättely I', '120', '0', '92.31%']
rowContent.forEach((content, index) => {
cy.get('td').eq(index).contains(content)
})
})
})
test('Check leaderboad works', async ({ page }) => {
cy.cs('Leaderboard').click()
cy.cs('academic-year').click()
page.locator('text=2020-2021').click()
})
})
+83
View File
@@ -0,0 +1,83 @@
import { test, expect } from '@playwright/test'
import { init } from './support/commands'
test.describe('Teachers page tests', () => {
test.beforeEach(async ({ page }) => {
// login as admin = has teacher rights
await init(page, '/teachers', 'admin')
expect(page.url()).toContain('/teachers')
})
const teacher1 = 'Luokkanen Liisa Viljami'
const teacher2 = 'Perälä Juhani Susanna'
test('Check Statistics', async ({ page }) => {
await page.getByTestId('semester-start').click()
await page.getByText('Syksy 2020').click()
await page.getByTestId('course-providers').click()
await page.getByText('Matemaattisten tieteiden kandiohjelma').click()
await page.keyboard.press('Escape')
await page.getByTestId('search-statistics').click()
await expect(page.getByRole('columnheader')).toHaveCount(4)
await expect(page.getByText('Export to Excel')).toBeVisible()
const teacher1Row = page.locator('tr').filter({ hasText: teacher1 })
await expect(teacher1Row.getByText(teacher1)).toBeVisible()
await expect(teacher1Row.getByText('235')).toBeVisible()
await expect(teacher1Row.getByText('97.40%')).toBeVisible()
const teacher2Row = page.locator('tr').filter({ hasText: teacher2 })
await expect(teacher2Row.getByText(teacher2)).toBeVisible()
await expect(teacher2Row.getByText('395')).toBeVisible()
await expect(teacher2Row.getByText('98.78%')).toBeVisible()
})
test('Teacher search works', async ({ page }) => {
await page.getByTestId('Search').click()
await page
.getByTestId('teacher-search')
.getByPlaceholder('Search by entering a name or an id')
.fill(teacher1.split(' ')[0])
await expect(page.getByText(teacher1)).toBeVisible()
await expect(page.locator('tbody').locator('tr')).toHaveCount(4)
})
test('Can check teacher page', async ({ page, context }) => {
await page.getByTestId('Search').click()
await page.getByTestId('teacher-search').getByPlaceholder('Search by entering a name or an id').fill(teacher2)
await expect(page.getByText(teacher2)).toBeVisible()
expect(await page.getByText(teacher2).getAttribute('href')).toBe('/teachers/hy-hlo-49026530')
// Change to other tab
const pagePromise = context.waitForEvent('page')
await page.getByText(teacher2).click()
const newPage = await pagePromise
await newPage.waitForURL('**/teachers/hy-hlo-49026530')
await expect(newPage.getByRole('heading', { name: teacher2 })).toBeVisible()
await newPage.getByText('Syksy 2023').click()
await newPage.getByText('Kevät 2019').click()
await expect(newPage.getByText('MAT12004')).toBeVisible()
await expect(newPage.getByText('MAT22002')).toBeVisible()
await expect(newPage.getByText('MAT22003')).toBeVisible()
const courseRow = newPage.locator('tr').getByText('MAT12004')
const rowContent = ['MAT12004', 'Tilastollinen päättely I', '120', '0', '92.31%']
rowContent.map(content => expect(courseRow.getByText(content)))
})
test('Check leaderboad works', async ({ page }) => {
await page.getByTestId('Leaderboard').click()
await page.getByTestId('academic-year').click()
await page.getByText('2020-2021').click()
await expect(page.getByRole('columnheader')).toHaveCount(4)
await expect(page.getByText('Export to Excel')).toBeVisible()
await expect(page.getByText(teacher1)).toBeVisible()
})
})