feat(login): 更新登录功能并添加环境变量配置
- 在 .env 文件中添加 ACCOUNT 和 PASSWORD 环境变量 - 更新 baseFixture 中的 page.goto 方法,使用 baseURL 配置 - 移除 exportFixture 中未使用的 baseTest - 在 LoginPage 中添加 tenant 参数以支持多租户登录 - 更新 login.spec 中的测试用例,使用环境变量配置 - 调整 setup.ts 中的登录流程,使用新的登录方法
This commit is contained in:
parent
ed71f4682c
commit
627f423779
6
.env
6
.env
@ -1,2 +1,4 @@
|
||||
BASE_URL=https://px.meiguanjia.net/web/
|
||||
# BASE_URL=https://px.meiguanjia.net/prestg/web/
|
||||
BASE_URL=https://px.meiguanjia.net//web/#/frame/dashboard
|
||||
# BASE_URL=https://px.meiguanjia.net/prestg/web/
|
||||
ACCOUNT=17770898274
|
||||
PASSWORD=a123456
|
||||
@ -1,8 +1,8 @@
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
await page.goto('/');
|
||||
page: async ({ page, baseURL }, use) => {
|
||||
await page.goto(baseURL || '');
|
||||
await use(page);
|
||||
}
|
||||
});
|
||||
@ -1,9 +1,7 @@
|
||||
import { mergeTests } from '@playwright/test';
|
||||
import { test as baseTest } from '../fixtures/baseFixture';
|
||||
import { test as loginTest } from '../fixtures/loginFixture';
|
||||
|
||||
export const test = mergeTests(
|
||||
baseTest,
|
||||
loginTest
|
||||
);
|
||||
|
||||
|
||||
@ -20,16 +20,20 @@ export class LoginPage {
|
||||
this.first_menu = page.getByText('概况');
|
||||
}
|
||||
|
||||
async user_login(account: string, password: string) {
|
||||
async user_login(account: string, password: string, tenant?: string) {
|
||||
await this.login_account.fill(account);
|
||||
await this.account_pass_hint.waitFor();
|
||||
await this.login_password.fill(password);
|
||||
await this.login_protocol.click();
|
||||
await this.login_button.click();
|
||||
if (tenant) {
|
||||
await this.page.getByText(tenant).click();
|
||||
}
|
||||
}
|
||||
|
||||
user_login_success() {
|
||||
return this.first_menu;
|
||||
async user_login_success() {
|
||||
await expect(this.page).toHaveURL(/.*\/frame\/dashboard/);
|
||||
await expect(this.page.getByText('商城数据')).toBeVisible();
|
||||
}
|
||||
|
||||
}
|
||||
@ -42,7 +42,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'], storageState: 'state.json' },
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
dependencies: ['setup'],
|
||||
},
|
||||
],
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { expect, test } from '../fixtures/exportFixutre';
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
test('login success', async ({ page, loginPage }) => {
|
||||
await loginPage.user_login('17770898274', 'a123456');
|
||||
await expect(loginPage.user_login_success()).toBeVisible();
|
||||
await loginPage.user_login(process.env.ACCOUNT || '', process.env.PASSWORD || '', '海石XW');
|
||||
await loginPage.user_login_success();
|
||||
});
|
||||
@ -6,6 +6,6 @@ setup('state setup', async ({ page }) => {
|
||||
const loginPage = new LoginPage(page);
|
||||
await loginPage.user_login('17700000003', 'a123456');
|
||||
await page.pause();
|
||||
await loginPage.user_login_success().waitFor();
|
||||
await loginPage.user_login_success();
|
||||
await page.context().storageState({ path: 'state.json', indexedDB: true });
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user