|
1 | 1 | import { test, expect } from '@playwright/test'
|
| 2 | +import { format } from 'prettier' |
| 3 | + |
| 4 | +function delay(ms: number) { |
| 5 | + return new Promise((resolve) => setTimeout(resolve, ms)) |
| 6 | +} |
2 | 7 |
|
3 | 8 | test('RTK / RTKQ Interactions', async ({ page }) => {
|
4 | 9 | await page.goto('http://localhost:3000')
|
5 | 10 |
|
6 | 11 | const counterValue = page.getByTestId('counter-value')
|
7 |
| - expect(counterValue).toHaveText('0', { timeout: 0 }) |
| 12 | + const counterText = await counterValue.innerText({ timeout: 0 }) |
| 13 | + expect(counterText).toBe('0') |
8 | 14 |
|
9 | 15 | const increment = page.getByRole('button', { name: 'Increment value' })
|
10 | 16 | await increment.click()
|
11 | 17 |
|
12 |
| - expect(counterValue).toHaveText('1') |
| 18 | + const counterText2 = await counterValue.innerText({ timeout: 0 }) |
| 19 | + expect(counterText2).toBe('1') |
13 | 20 |
|
14 |
| - const timeValue = page.getByTestId('time-value') |
15 |
| - await timeValue.getByText(/\d+:\d+:\d+ (A|P)M/).waitFor({ timeout: 10000 }) |
| 21 | + console.log('CounterText2: ', counterText2) |
| 22 | + |
| 23 | + // expect(counterValue).toHaveText('1') |
16 | 24 |
|
| 25 | + async function logHTML(message = '') { |
| 26 | + const html = await page.innerHTML('div#root') |
| 27 | + const formattedHTML = format(html, { parser: 'html' }) |
| 28 | + console.log(message, formattedHTML) |
| 29 | + } |
| 30 | + |
| 31 | + logHTML('Page: ') |
| 32 | + |
| 33 | + const timeValue = page.getByTestId('time-value') |
17 | 34 | const postValue = page.getByTestId('post-value')
|
18 |
| - await postValue.getByText('A sample post').waitFor({ timeout: 10000 }) |
19 | 35 |
|
20 |
| - // expect(timeValue).toHaveText(, {timeout: 5000, }); |
| 36 | + await expect(timeValue).toHaveText(/\d+:\d+:\d+ (A|P)M/, { timeout: 10000 }) |
| 37 | + await expect(postValue).toHaveText('A sample post', { timeout: 10000 }) |
| 38 | + |
| 39 | + // console.log('timeValue before: ', await timeValue.innerText()) |
| 40 | + // console.log('postValue before: ', await postValue.innerText()) |
| 41 | + // await delay(5000) |
| 42 | + |
| 43 | + // console.log('timeValue after: ', await timeValue.innerText()) |
| 44 | + // console.log('postValue after: ', await postValue.innerText()) |
| 45 | + // |
| 46 | + // await page.getByText(/\d+:\d+:\d+ (A|P)M/).waitFor({ timeout: 10000 }) |
| 47 | + |
| 48 | + // |
| 49 | + // |
| 50 | + // await page.getByText('A sample post').waitFor({ timeout: 10000 }) |
| 51 | + |
| 52 | + // try { |
| 53 | + // } catch (err) { |
| 54 | + // } finally { |
| 55 | + // logHTML('After timevalue') |
| 56 | + // } |
| 57 | + |
| 58 | + // try { |
| 59 | + // } catch (err) { |
| 60 | + // } finally { |
| 61 | + // logHTML('After postvalue') |
| 62 | + // } |
21 | 63 | })
|
0 commit comments