Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Javascript __doPostBack missing in browser opened by playwright. #21766

Closed
1 task done
quldude opened this issue Mar 17, 2023 · 2 comments
Closed
1 task done

[BUG] Javascript __doPostBack missing in browser opened by playwright. #21766

quldude opened this issue Mar 17, 2023 · 2 comments

Comments

@quldude
Copy link

quldude commented Mar 17, 2023

System info

  • Playwright Version: v1.31.2
  • Operating System: All
  • Browser: All

Source code

  • I provided exact source code that allows reproducing the issue locally.

Config file

// playwright.config.ts
const config: PlaywrightTestConfig = {
  testDir: '.',
  /* Maximum time one test can run for. */
  timeout: 300 * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 5 * 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,
  retries: 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: 'html',
  globalSetup: require.resolve('./lib/global-setup'),
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    headless: false,
    // channel: 'msedge',

    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: 0,
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL: process.env.CI ? process.env.TEST_SERVER_URL : 'http://localhost:3000',

    /* Use data-qa as the default test-id attribute */
    testIdAttribute: 'data-qa',

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on',

    // This is not read when projects section is defined. Ref: https://github.com/microsoft/playwright/issues/16077
    userAgent: customUserAgent,
  },

  /* Folder for test artifacts such as screenshots, videos, traces, etc. */
  outputDir: 'test-results/',
};

Test file (self-contained)

await test.step('Navigate to url.', async () => {
    await page.goto(
      'https://some.url',
    );
  });

Steps

  • Run playwright test that opens browser and navigates to a specific page.

Expected

Page html should have following script:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

Actual

Page is missing the expected javascript. So we get error:

Uncaught ReferenceError: __doPostBack is not defined
    at HTMLButtonElement.onclick

This only happens in the browser that is opened by playwright. Wanted to see if there is some setting I'm missing.

@quldude
Copy link
Author

quldude commented Mar 17, 2023

Update-1: the issue is happening because of userAgent defined in config. If I remove it, then it works.

@quldude
Copy link
Author

quldude commented Mar 17, 2023

Update-2: I was able to resolve this by appending the custom user agent based on convo in here.

@quldude quldude closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant