code.gitea.io/gitea@v1.21.7/tests/e2e/example.test.e2e.js (about)

     1  // @ts-check
     2  import {test, expect} from '@playwright/test';
     3  import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js';
     4  
     5  test.beforeAll(async ({browser}, workerInfo) => {
     6    await login_user(browser, workerInfo, 'user2');
     7  });
     8  
     9  test('Load Homepage', async ({page}) => {
    10    const response = await page.goto('/');
    11    await expect(response?.status()).toBe(200); // Status OK
    12    await expect(page).toHaveTitle(/^Gitea: Git with a cup of tea\s*$/);
    13    await expect(page.locator('.logo')).toHaveAttribute('src', '/assets/img/logo.svg');
    14  });
    15  
    16  test('Test Register Form', async ({page}, workerInfo) => {
    17    const response = await page.goto('/user/sign_up');
    18    await expect(response?.status()).toBe(200); // Status OK
    19    await page.type('input[name=user_name]', `e2e-test-${workerInfo.workerIndex}`);
    20    await page.type('input[name=email]', `e2e-test-${workerInfo.workerIndex}@test.com`);
    21    await page.type('input[name=password]', 'test123test123');
    22    await page.type('input[name=retype]', 'test123test123');
    23    await page.click('form button.ui.primary.button:visible');
    24    // Make sure we routed to the home page. Else login failed.
    25    await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
    26    await expect(page.locator('.dashboard-navbar span>img.ui.avatar')).toBeVisible();
    27    await expect(page.locator('.ui.positive.message.flash-success')).toHaveText('Account was successfully created. Welcome!');
    28  
    29    save_visual(page);
    30  });
    31  
    32  test('Test Login Form', async ({page}, workerInfo) => {
    33    const response = await page.goto('/user/login');
    34    await expect(response?.status()).toBe(200); // Status OK
    35  
    36    await page.type('input[name=user_name]', `user2`);
    37    await page.type('input[name=password]', `password`);
    38    await page.click('form button.ui.primary.button:visible');
    39  
    40    await page.waitForLoadState('networkidle');
    41  
    42    await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
    43  
    44    save_visual(page);
    45  });
    46  
    47  test('Test Logged In User', async ({browser}, workerInfo) => {
    48    const context = await load_logged_in_context(browser, workerInfo, 'user2');
    49    const page = await context.newPage();
    50  
    51    await page.goto('/');
    52  
    53    // Make sure we routed to the home page. Else login failed.
    54    await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
    55  
    56    save_visual(page);
    57  });