File size: 729 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Accept inline, accessible HTML-dialog and native prompt editing flows.
async function editQuestion(page, button, text) {
  const promptHandler = dialog => dialog.type() === 'prompt' ? dialog.accept(text) : dialog.dismiss();
  page.on('dialog', promptHandler);
  try {
    await button.click();
    const dialog = page.getByRole('dialog');
    if (await dialog.count() && await dialog.first().isVisible()) {
      const field = dialog.first().locator('input,textarea').first();
      if (await field.count()) await field.fill(text);
      await dialog.first().getByRole('button', {name: /save|保存|确认|确定/i}).first().click();
    }
  } finally { page.off('dialog', promptHandler); }
}
module.exports = {editQuestion};