测试只能在调试模式下进行,但不能进入,为什么?
单击表单按钮取消后,应该会出现一个警报(您确实要丢弃结果吗?)。测试尝试等待警报但它仅在调试模式下有效。在其他模式下,整个表单都会关闭而不显示警报。为什么?
const {test, expect} = require('@playwright/test');
const myProject = 'demo-project-nuremberg';
test('click form-button-cancel does not show alert ', async ({page}) => {
//login:
await page.goto('https://dmitrygozman.fieldcode.com');
await page.locator('[id="username"]').fill('dgozman.demo@gmail.com');
await page.locator('[id="password"]').fill('Dgozman123');
await page.locator('[id="fc-login-button"]').click();
//open sidebar:
await page.locator('svg[data-icon="angle-double-right"] >> nth=0').waitFor();
await page.locator('svg[data-icon="angle-double-right"] >> nth=0').click();
//click button-create-ticket:
await page.locator('[id="sidebarMenu"] >> [title="Create ticket"]').waitFor();
await page.locator('[id="sidebarMenu"] >> [title="Create ticket"]').click();
//chose project to open form:
const selector_myproject = '[data-ui-test="ticketCreationProject"] >> text='+myProject+'';
await page.locator(selector_myproject).waitFor({state:"visible"});
//await page.locator(selector_myproject).click({delay:1000, force:true});
await page.locator(selector_myproject).click({delay:1000});
//check form is open:
await page.locator('text=Create ticket for project').waitFor({state:"visible"});
await expect(page.locator('text=Create ticket for project')).toBeVisible;
//click form-button-cancel:
/*
Here is the problem , it works in mode-debug but not --headed ,etc. Why?
after click -> await page.locator(buttonCancel).click({delay:500});
the whole form disappears, without showing the alert-discard-results
*/
const buttonCancel = 'button:has-text("Cancel")';
await page.locator(buttonCancel).waitFor({state:"visible"});
await page.locator(buttonCancel).focus();
await page.locator(buttonCancel).hover({force:true});
await page.locator(buttonCancel).click({delay:500}); // What am I doing wrong in this click????
//ERROR HERE! playwright can't find the dialog locator
await page.locator('text=Do you really want to discard the results?').waitFor();
await page.locator('button:has-text("Yes")').waitFor();
await page.locator('button:has-text("Yes")').click({delay:500});
//check form is closed:
const selector = 'text=Create ticket for project';
await page.locator(selector).waitFor({state:"detached"});
await expect(page.locator(selector)).toHaveCount(0);
});