Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UImprove tests. Use page.initScript instead context.initScript #69

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ha-beta-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ jobs:
- name: Install
run: pnpm install
- name: E2E Tests
run: TAG=beta pnpm test:ci
run: TAG=beta pnpm test:ci
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-report
path: |
playwright-report
retention-days: 30
10 changes: 9 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ jobs:
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-report
path: |
playwright-report/
coverage/
retention-days: 30
6 changes: 5 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ export default defineConfig({
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry'
trace: 'on-first-retry',
screenshot: 'only-on-failure'
},
expect: {
timeout: 15000
},
/* Configure projects for major browsers */
projects: [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/01 - panels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { stubGlobalTestElements } from './utils';

test.describe('HAQuerySelector for dashboards', () => {

test.beforeEach(async ({ page, context }) => {
await stubGlobalTestElements(page, context);
test.beforeEach(async ({ page }) => {
await stubGlobalTestElements(page);
});

test('All the elements should exist', async ({ page }) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/02 - low-event-timestamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { stubGlobalTestElements } from './utils';

test.describe('HAQuerySelector events with low timestamp', () => {

test.beforeEach(async ({ page, context }) => {
test.beforeEach(async ({ page }) => {
await stubGlobalTestElements(
page,
context,
{
eventThreshold: 800
}
Expand Down
4 changes: 2 additions & 2 deletions tests/03 - more-info-dialogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { stubGlobalTestElements } from './utils';

test.describe('HAQuerySelector for more-info dialogs', () => {

test.beforeEach(async ({ page, context }) => {
await stubGlobalTestElements(page, context);
test.beforeEach(async ({ page }) => {
await stubGlobalTestElements(page);
});

test.afterEach(async ({ page }) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/04 - non-existent-elements.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { stubGlobalTestElements } from './utils';

test.describe('HAQuerySelector for lovelace dashboards', () => {

test.beforeEach(async ({ page, context }) => {
test.beforeEach(async ({ page }) => {
await stubGlobalTestElements(
page,
context,
{
retries: 5,
delay: 5
Expand Down
3 changes: 1 addition & 2 deletions tests/05 - non-lovelace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { stubGlobalTestElements } from './utils';

test.describe('HAQuerySelector for non-lovelace dashboards', () => {

test.beforeEach(async ({ page, context }) => {
test.beforeEach(async ({ page }) => {
await stubGlobalTestElements(
page,
context,
{
pathname: 'history',
retries: 5,
Expand Down
8 changes: 4 additions & 4 deletions tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page, BrowserContext } from '@playwright/test';
import { Page } from '@playwright/test';
import { expect } from 'playwright-test-coverage';
import path from 'path';
import { BASE_URL, SELECTORS } from './constants';
Expand All @@ -12,11 +12,10 @@ interface Options {

export const stubGlobalTestElements = async (
page: Page,
context: BrowserContext,
options?: Options
) => {

await context.addInitScript({
await page.addInitScript({
path: path.join(__dirname, '..', './node_modules/sinon/pkg/sinon.js'),
});

Expand Down Expand Up @@ -76,5 +75,6 @@ export const stubGlobalTestElements = async (
window.__instance.listen();

}, options || {});
await page.waitForFunction(() => !!window.__onListen?.firstCall?.firstArg);
// Timeout to allow the events to be triggered
await page.waitForTimeout(500);
};
Loading