playwright-demo/tests/mes/login.test.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-08-02 09:50:12 +08:00
import { describe, it, expect } from '@jest/globals'
2021-05-27 15:25:25 +08:00
import { chromium } from "playwright";
describe("mes登录", function () {
it('login', async function () {
const browser = await chromium.launch({
// headless: false
});
const context = await browser.newContext();
// Open new page
const page = await context.newPage();
// Go to http://sc.ihome6.cf/
await page.goto('http://sc.ihome6.cf/');
// Click [placeholder="账号"]
await page.click('[placeholder="账号"]');
// Fill [placeholder="账号"]
await page.fill('[placeholder="账号"]', 'dj');
// Press Tab
await page.press('[placeholder="账号"]', 'Tab');
// Fill [placeholder="密码"]
await page.fill('[placeholder="密码"]', '123456');
// Click button:has-text("登录")
await page.click('button:has-text("登录")');
await page.waitForTimeout(1000)
let path = await page.evaluateHandle(()=>window.location.hash.substr(1))
2024-08-02 09:50:12 +08:00
expect(await path.jsonValue()).toEqual('/dashboard')
2021-05-27 15:25:25 +08:00
2024-08-02 09:50:12 +08:00
2021-05-27 15:25:25 +08:00
// ---------------------
2024-08-02 09:50:12 +08:00
await context.close();
await browser.close();
2021-05-27 15:25:25 +08:00
})
})