0

I'm using playwright 1.32 against a web application developed with Oracle Apex 20.2. I'm writing a dummy test (see below) just to learn how to control if the error message is shown, to make the test fail:

This is the result of bellow code. The yellow box indicates several errors: enter image description here

When the button "Create" is clicked for second time, the page is submitted to the server and when it's rendered again, the yellow box is shown.

My problem is that if I run the test, I get the green arrow indicating that it's fine, but if I debug it slowly, I get the test failed (which is the expected overcome).

How should I fix this? Thanks, Jose.

test('check yellow notification', async ({ page }) => {
  await page.goto('https://xxxxx.yyyyy.com/ords/f?p=500:1:8793700790638'); //8793700790638 is the value read from the SQL

  //Go to application menu and click into Create button:
  await page.getByRole('listitem').filter({ hasText: /^Projects$/ }).locator('span').first().click();
  await page.getByRole('treeitem', { name: 'All Projects' }).click();
  await page.getByRole('button', { name: 'Create' }).click();

  //Do not fill any data, so all the mandatory field validations will be triggered  
  await page.getByRole('button', { name: 'Create' }).click();
  
  //Check if error message is shown/not shown
  const locator = page.locator('#t_Alert_Notification');
  await expect(locator, 'Error amarillo visualizado').not.toBeVisible();

});
  • I've tried this, after the second click in Create button: ```await new Promise(r => setTimeout(r, 2000));``` and it seems to work. Is this a good choice? Thanks! – JoseAróstegui Mar 29 '23 at 12:11
  • I don't get if you want to test whether the banner will be there or not. – hardkoded Mar 29 '23 at 12:23
  • 1
    I would advise against using hardcoded setTimeout but instead you could use [.toPass()](https://stackoverflow.com/questions/75030787/how-to-wait-for-multiple-locators-to-be-visible/75031781#75031781) or [polling](https://playwright.dev/docs/test-assertions#polling) to wait for expected outcome. – AJG Mar 29 '23 at 12:33
  • It's hard to say for sure without having access to the site, but it sounds like if it works with a timeout, you're probably missing a predicate or DOM change of some sort that occurs once the first click does whatever it's supposed to. As AJG suggested, encode whatever that selector or predicate is using `waitForFunction` or a locator of some sort. – ggorlen Mar 29 '23 at 13:15
  • @hardkoded I need to check if the banner is shown or not. The way the test is written, (leaving many mandatory fields empty) then should always fails as the banner will be always shown, no matter if I run or debug the test. – JoseAróstegui Mar 29 '23 at 14:29

0 Answers0