microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.42k stars 3.63k forks source link

Element timeout #12908

Closed Lakshmi-Yaswanth closed 2 years ago

Lakshmi-Yaswanth commented 2 years ago

I have multiple steps with in a test block, my timeout is 1200000 so with in the timeout all the test will pass, if I reduce the timeout then my test will fail. but let's say my element is wrong in that scenario test wont fail immediately. It wait till 1200000 then throws error. It will be great if we can have separate timeout for finding elements only.

Nav-2d commented 2 years ago

You can use actionTimeout and set it to for example - 30000ms.

Ref: https://playwright.dev/docs/test-timeouts#action-and-navigation-timeouts

Lakshmi-Yaswanth commented 2 years ago

I have used the actionTimeout but no luck it was not working as expected. For Example: This is my playwright configuration

const config: PlaywrightTestConfig = {
  /*sets timeout for each test case*/
  timeout: 12000000,
  /*global time for each test cases*/
  globalTimeout: 12000000,
  /*number of retries if test case fails*/
  retries: 0,
  workers: 1,
  projects: [
    {
      name: "Caliber",
      use: {
        /*Default timeout for each Playwright action in milliseconds*/
        actionTimeout: 10 * 1000,
        /* Configure the browser to use.*/
        browserName: `chromium`,
        /*Chrome Browser Config*/
        channel: `chrome`,
        /*Browser Mode*/
        headless: false,
        launchOptions: {
          slowMo: 0,
        },
        ignoreHTTPSErrors: true,
        //Browser height and width
        viewport: { width: 1920, height: 1080 },
        //Enable File Downloads in Chrome
        acceptDownloads: true,
        //Artifacts
        screenshot: `on`,
        video: `on`,
        trace: `on`,
      },
    }
  ],
  testMatch: [
    'login.test.ts',
    //'home.test.ts',
    //'manageBatch.test.ts',//38m
    //'settings.test.ts',
    //"pdp.test.ts",
    //'accessBatch.test.ts',//24m
    //'qualityAudit.test.ts'//18m
  ],
  //Reporters
  reporter: [[`list`], ["dot"],
  ["json", { outputFile: "test-result.json" }], //  -> JSON
  ['html', {
    open: "never"
  }], [`experimental-allure-playwright`]],
  globalTeardown: './helper/globalsetup.ts'
  // grep: [new RegExp("@smoke"), new RegExp("@slow"), new RegExp("@fast"), new RegExp("@reg"), new RegExp('@sanity')],
};

Test cases look like:

test.describe("Validation for Login page", () => {
    test("login as Vp_user", async ({ login }) => {
        await test.step('To verify user navigate to signup url', async () => {
        //some actions
        });
        await test.step('To verify view signUp page', async () => {
              //some actions
        });
        await test.step('To verify user can give invalid user for forgot password', async () => {
              //some actions
        });
        await test.step('To verify user can give valid user for forgot password', async () => {
             //some actions
        });
        await test.step('To verify user cannot login into caliber with valid username and invalid password', async () => {
             //some actions
        });
        await test.step('To verify user cannot login into caliber with invalid username and valid password', async () => {
           //some actions
        });
        await test.step('To verify user cannot login into caliber with invalid username and invalid password', async () => {
              //some actions
        });
        await test.step(' To verify user can login into caliber with valid username and valid password', async () => {
             //some actions
        });
        await test.step('To verify user can able to view all menus', async () => {
              //some actions
        });
        await test.step('Logout from vp_users', async () => {
            //some actions
        });
    });
    test("login as trainer", async ({ login }) => {
        await test.step('To verify user navigate to signup url', async () => {
              //some actions
        });
        await test.step('To verify view signUp page', async () => {
             //some actions
        });
        await test.step('To verify user can give valid user for forgot password', async () => {
             //some actions
        });
        await test.step(' To verify user can login into caliber with valid username and valid password', async () => {
              //some actions
        });
        await test.step('To verify user can able to view all menus', async () => {
         //some actions
        });
        await test.step('Logout from vp_users', async () => {
              //some actions
        });
    });
});

This is how my code looks.but let's say my element is wrong in that scenario test wont fail immediately. It wait till 1200000 then throws error. can u please help me to over come this. Thank u .

dgozman commented 2 years ago

@Lakshmi-Yaswanth Your actionTimeout: 10 * 1000 looks good. What do you do in the test? Mind sharing some specific actions you perform, e.g. locator.click() or something? When the test finally times out after 1200000, do you see any error? What does it say?

maksuda-islam commented 5 months ago

Is there any update on this one? I am following a similar issue. this is my config file.

// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
// require('dotenv').config();

/**
 * @see https://playwright.dev/docs/test-configuration
 */
module.exports = defineConfig({ //global setup
  testDir: './tests',

  timeout: 15 * 60 * 1000,
  /* Run tests in files in parallel */
  // fullyParallel: true,

  /* Fail the build on CI if you accidentally left test.only in the source code. */

  // forbidOnly: !!process.env.CI,

  /* Retry on CI only */
  //retries: process.env.CI ? 2 : 0,

  /* Opt out of parallel tests on CI. */
  // workers: process.env.CI ? 2 : undefined,
  workers: 1,

  /* Reporter to use. See https://playwright.dev/docs/test-reporters */

  // reporter:: monocart
  reporter: [
    ['list'],
    ['monocart-reporter', {
      name: "Test Report",
      outputFile: './test-results/Test-Report.html'
    }]
  ],

  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    actionTimeout: 20 * 1000,

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',
    permissions: ["clipboard-read"]
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        viewport: { width: 1920, height: 1080 },
        ignoreHTTPSErrors: true,
      },
    },

    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },

    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    }
});

While doing action on any locator, using await this.page.locator(some locator).click() (this.page since using POM) If the locator is not found it waits till the remaining time of the test (for example, if it encountered that "waiting for locator .." message after running the test block for 10 mins, it will keep waiting for the locator for the remaining time of the test block (5 mins for my case). But, wasn't it supposed to end running that test block after not finding that specific locator after trying for 20 sec (my defined actionTimeout)?

please, let me know if I am getting/doing something wrong. TIA.