test: basic e2e usercase

pull/81/head
moonrailgun 3 years ago
parent 854bac53ea
commit 747ac33f7b

@ -1,3 +1,4 @@
node_modules/
test-results/
playwright-report/
auth.json

@ -6,10 +6,10 @@
"license": "MIT",
"private": true,
"scripts": {
"test": "playwright test",
"test:chromium": "playwright test --project=chromium",
"test": "playwright test --project=chromium",
"test:all": "playwright test",
"test:debug": "playwright test --debug",
"codegen": "playwright codegen wikipedia.org"
"codegen": "playwright codegen http://localhost:11011"
},
"devDependencies": {
"@playwright/test": "^1.19.2"

@ -28,9 +28,11 @@ const config: PlaywrightTestConfig = {
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
// reporter: 'html',
reporter: 'line',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: 'http://localhost:11011',
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */

@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
test.describe('entry page', () => {
test('should auto jump to entry page', async ({ page }) => {
await expect(page).toHaveURL('/entry/login');
});
test('auto goto entry if not login', async ({ page }) => {
await page.goto('/main');
await expect(page).toHaveURL('/entry/login?redirect=%2Fmain'); // should with redirect
});
test('registry', async ({ page }) => {
await page.locator('text=注册账号').click();
await expect(page).toHaveURL('/entry/register');
await page.locator('button:has-text("注册账号")').click();
await expect(page.locator('p.text-red-500')).toHaveText('邮箱不能为空');
await page.locator('[name="reg-email"]').click();
await page.locator('[name="reg-email"]').fill('123456789');
await page.locator('button:has-text("注册账号")').click();
await expect(page.locator('p.text-red-500')).toHaveText('邮箱格式不正确');
await page.locator('[name="reg-email"]').click();
await page.locator('[name="reg-email"]').fill('test@moonrailgun.com');
await page.locator('button:has-text("注册账号")').click();
await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');
await page.locator('[name="reg-password"]').click();
await page.locator('[name="reg-password"]').fill('1234');
await page.locator('button:has-text("注册账号")').click();
await expect(page.locator('p.text-red-500')).toHaveText('密码不能低于6位');
});
});

@ -0,0 +1,12 @@
import { loginToDemoUser } from './utils/user';
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page, context }) => {
await loginToDemoUser(page, context);
});
test.describe('Main Process', () => {
test('Check Personal Route', () => {
console.log('TODO');
});
});

@ -0,0 +1,23 @@
import { BrowserContext, expect, Page } from '@playwright/test';
const storagePath = './auth.json';
/**
*
*
*
*/
export async function loginToDemoUser(page: Page, context: BrowserContext) {
await page.goto('/entry/login');
await page
.locator('input[name="login-email"]')
.fill('tailchat-demo@msgbyte.com');
await page.locator('input[name="login-password"]').fill('tailchat-demo');
await page.locator('button:has-text("登录")').click();
await expect(page).toHaveURL('/main/personal/friends'); // should with redirect
await context.storageState({
path: storagePath,
});
}
Loading…
Cancel
Save