1

I want to use Playwright UI Mode to run a specific test-file and be able to import some lines from a helper file Login.js.

  • It works as long as i do not import from a local file

  • If i try to import {Login_user_foo} from '../commons/Login'; then ui reports that there are no tests

The purpose of the helper file is to not repeat code lines in different test but reuse them like this await login_user_foo(page)

This code works with only 1 import

import { test, expect } from '@playwright/test';
// import {Login_user_foo} from '../commons/Login'; // <-- if uncommented then it fails 

test.use({ storageState: './auth/auth_user_foo_qa.json', locale: 'en-US' });

test('Login', async ({ page }) => {
   ... 
});
test('Open list', async ({ page }) => {
   ... 
});

But it fails if a second import is added.

import { test, expect } from '@playwright/test';
// the next line causes playwright test --ui to not find any tests
import {Login_user_foo} from '../commons/Login'; 

test('Login', async ({ page }) => {
    ....

This is how the error looks like with import {Login_user_foo} from '../commons/Login';

Playwright_UI_mode_no_tests_if_import

The file Login.js that is imported looks like this:

import { test, expect } from '@playwright/test';

async function Login_user_foo(page) {

    await page.goto('<our-qa-stage>');
    await page.getByLabel('Remember me').check();                
    await page.getByLabel('Password').fill('<our-password>');    
    await page.getByRole('button', { name: 'Log In to Sandbox' }).click();   
}

export {Login_user_foo};

I start playwright ui mode with this command:

// run a specific testfile in ui mode
npx playwright test --ui tests/my_new_test.spec.js

Questions

  • Is this a problem with my code or something that ui mode can not handle?
  • What do i need to change to be able to import functions from another file?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.