我试图使用Playwright和Jest来自动化一些关于在Microsoft Teams频道中上传文件的测试。
这就是我所做的和工作:
it('should upload a file', async () => {
// Listen to file chooser popup and set file for upload
page.on('filechooser', async (fileChooser) => {
await fileChooser.setFiles('test-files/example.txt');
});
// wait for the content iframe to be loaded
const contentFrame = page.frameLocator('[name="embedded-page-container"]');
// @TODO here I would like to first make sure the file does not exist
//
// How could I do that ???
//
// upload file and check for existence in file list displayed
await contentFrame.locator('button[name="Upload"]').click();
await contentFrame.locator('button[name="Files"]').click();
await contentFrame.locator('button:has-text("example.txt")').waitFor({ state: "visible" });
});
**问题:**如何检查文件之前不存在?
基本上,我如何检查我等待在最后一行变得可见的button:has-text("example.txt")
元素在上传操作之前是否存在?
谢谢.
2条答案
按热度按时间uujelgoq1#
我用python而不是JavaScript做了类似的事情,但它应该对你有用。
我在一个helper中定义了自己的函数:
然后,您可以使用它来了解您的元素是否在DOM中,并基于此做出决策/流程
nbnkbykc2#
方法如下:
来源:Github issue outlines solution