npm init -ynpm init playwright@latest
- Create a test file
GetSnapshot.test.ts
import { test, expect } from '@playwright/test';
| FROM mcr.microsoft.com/playwright:v1.56.1-noble | |
| RUN apt-get update && apt-get install -y \ | |
| libx11-xcb1 \ | |
| libxcomposite1 \ | |
| libxdamage1 \ | |
| libxrandr2 \ | |
| libgbm1 \ | |
| libasound2t64 && rm -rf /var/lib/apt/lists/* |
| import { Page } from '@playwright/test'; | |
| import { interpret } from 'xstate'; | |
| import { chatMachine } from './chatMachine' | |
| export class ChatTestHelper { | |
| private service: any; | |
| private page: Page; |
| async function gotoWithRetry(page: Page, url: string, options = {}) { | |
| const maxRetries = 3; | |
| const defaultOptions = { timeout: 20000, waitUntil: 'load' as ('load') }; | |
| const mergedOptions = { ...defaultOptions, ...options }; | |
| for (let attempt = 1; attempt <= maxRetries; attempt++) { | |
| try { | |
| await page.goto(url, mergedOptions); | |
| return; | |
| } catch (error) { |
| import express from 'express'; | |
| import { create } from 'zustand'; | |
| const useStore = create((set, get) => ({ | |
| state: {}, | |
| setState: (key, value, ttl) => { | |
| const expiresAt = ttl ? Date.now() + ttl * 1000 : null; | |
| set((state) => ({ | |
| state: { ...state.state, [key]: { value, expiresAt } } | |
| })); |
| { | |
| "compilerOptions": { | |
| "module": "ESNext", | |
| "target": "es5", | |
| "moduleResolution": "Node" | |
| } | |
| } |
| export class Base { | |
| readonly helloBtn: Locator; | |
| constructor(page: Page) { | |
| this.page = page | |
| this.helloBtn = this.page.locator("hello") | |
| } | |
| public sendHello = async () => { |
| import React, { Component } from "react"; | |
| import ReactDOM from "react-dom"; | |
| interface IProps { | |
| from: number; | |
| } | |
| interface IState { | |
| current: number; | |
| isPause: boolean; |
| const getSnail = (size = 5) => { | |
| const snail = Array.from({ length: size }, () => | |
| Array.from({ length: size }) | |
| ); | |
| for (round = 0, value = 0; round < size / 2; ++round) { | |
| for (j = round; j < size - 1 - round; ++j) { | |
| snail[round][j] = ++value; | |
| } | |
| for (i = round; i < size - 1 - round; ++i) { | |
| snail[i][size - 1 - round] = ++value; |
| const webpack = require('@cypress/webpack-preprocessor'); | |
| const execa = require('execa'); | |
| const findBrowser = () => { | |
| const browserPath = '/usr/bin/yandex-browser'; | |
| return execa(browserPath, ['--version']).then(result => { | |
| const [, version] = /Yandex (\d+\.\d+\.\d+\.\d+)/.exec(result.stdout); | |
| const majorVersion = parseInt(version.split('.')[0]); | |
| return { |