login.e2e.js 1.3 KB
Newer Older
valleykid's avatar
valleykid committed
1
import puppeteer from 'puppeteer';
偏右's avatar
偏右 committed
2 3

describe('Login', () => {
valleykid's avatar
valleykid committed
4
  let browser;
偏右's avatar
偏右 committed
5
  let page;
valleykid's avatar
valleykid committed
6 7

  beforeAll(async () => {
jim's avatar
fix ci  
jim committed
8
    browser = await puppeteer.launch({ args: ['--no-sandbox'] });
valleykid's avatar
valleykid committed
9 10 11 12
  });

  beforeEach(async () => {
    page = await browser.newPage();
ζ„šι“'s avatar
ζ„šι“ committed
13
    await page.goto('http://localhost:8000/user/login', { waitUntil: 'networkidle2' });
valleykid's avatar
valleykid committed
14
    await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest'));
偏右's avatar
偏右 committed
15 16
  });

valleykid's avatar
valleykid committed
17 18
  afterEach(() => page.close());

偏右's avatar
偏右 committed
19
  it('should login with failure', async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
20 21 22
    await page.waitForSelector('#userName', {
      timeout: 2000,
    });
valleykid's avatar
valleykid committed
23 24 25 26
    await page.type('#userName', 'mockuser');
    await page.type('#password', 'wrong_password');
    await page.click('button[type="submit"]');
    await page.waitForSelector('.ant-alert-error'); // should display error
偏右's avatar
偏右 committed
27 28
  });

afc163's avatar
afc163 committed
29
  it('should login successfully', async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
30 31 32
    await page.waitForSelector('#userName', {
      timeout: 2000,
    });
valleykid's avatar
valleykid committed
33 34 35 36 37
    await page.type('#userName', 'admin');
    await page.type('#password', '888888');
    await page.click('button[type="submit"]');
    await page.waitForSelector('.ant-layout-sider h1'); // should display error
    const text = await page.evaluate(() => document.body.innerHTML);
偏右's avatar
偏右 committed
38 39
    expect(text).toContain('<h1>Ant Design Pro</h1>');
  });
valleykid's avatar
valleykid committed
40 41

  afterAll(() => browser.close());
偏右's avatar
偏右 committed
42
});