在酱汁实验室运行测试时,有没有办法通过文件选择器对话框访问文件?

发布于 2025-01-18 14:56:43 字数 1098 浏览 0 评论 0 原文

我正在使用硒和酱汁实验室进行自动跨浏览器测试。测试的Web应用程序需要通过文件选择器对话框访问文件。我想在Sauce Labs运行测试时使用Selenium访问这些文件。在本地运行测试(不使用酱汁实验室)时,我能够成功与文件选择器对话框进行交互以访问文件,但是当通过酱汁实验室运行测试时,我无法执行此操作,因为我不don' t知道呈现的本机文件选择器对话框的Web元素定位器。

我有以下问题:

  1. 是否可以将文件上传到Sauce Labs虚拟机上,以后从运行浏览器的虚拟机上的文件系统下载它们?
  2. 是否有一种方法(使用硒)可以与在酱汁实验室虚拟机上执行测试时呈现的本机文件选择器对话框进行交互?目标是将键盘输入发送到“文件选择器”对话框,并指定文件的路径。

我已经检查了Sauce Labs文档以获取有关此信息的信息。 这些是我引用的文件: https://support.saucelabs.com/hc/en-us/articles/115003685593-uploading-files-files-files-to-auce-to-auce-labs-virtual-virtual-machine-machine-machine-machine-during-during-a-a-test

是否有人成功地将文件上传到酱汁实验室,并在测试执行过程中通过介绍的本机文件选择器对话框访问了这些文件?

I am performing automated cross-browser testing using Selenium and Sauce Labs. The web application under test requires files to be accessed via a file chooser dialog. I’d like to access these files using Selenium while tests are being run by Sauce Labs. When running the tests locally (without the use of Sauce Labs), I am successfully able to interact with the file chooser dialog to access files, but have not been able to do this when the tests are run via Sauce Labs, since I don’t know the web element locator for the native file chooser dialog that is presented.

I have the following questions:

  1. Is it possible to upload files to a Sauce Labs virtual machine, to later download them from the filesystem on the virtual machine where the browser is run?
  2. Is there a way (using Selenium) to interact with the native file chooser dialog that is presented while the test is executing on the Sauce Labs virtual machine? The goal would be to send keyboard input to the file chooser dialog, specifying the path to the file.

I have checked Sauce Labs documentation for information on this.
These are the documents I referenced:
https://support.saucelabs.com/hc/en-us/articles/115003685593-Uploading-Files-to-a-Sauce-Labs-Virtual-Machine-during-a-Test
https://support.saucelabs.com/hc/en-us/articles/115005860628-Testing-PDF-Downloads

Has anyone successfully uploaded files to Sauce Labs, and accessed them during test execution via the native file chooser dialog that is presented?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你的手,一向走下去 2025-01-25 14:56:43

是的,这是可能的,您需要采取的步骤在 存储库。这个示例是用 JavaScript 编写的,但希望您可以将其翻译成您最喜欢的语言。

基本步骤是:

  1. Sauce Labs VM 无法访问您的本地 VM,因此您需要将文件上传到 Sauce Labs 并重新运行可执行文件。这是一个将在硒测试开始之前执行的脚本。
  2. Selenium 无法与这些弹出窗口交互,因此您需要在输入字段中设置要上传的文件的路径。根据上传字段/按钮的创建方式,您可能需要使输入字段可见才能与其交互。这可以通过向页面注入一些JS并将元素设置为可见来完成。这需要如何完成取决于开发人员如何编写页面。这没有什么灵丹妙药。

Yes, this is possible, the steps that you need to take are explained in this repository. This example is written with JavaScript, but hopefully you can translate this to your favourite language.

The basic steps are:

  1. The Sauce Labs VM doesn't have access to your local VM, so you need to upload a file to Sauce Labs with a re-run executable. This is a script that will be executed before your selenium test will be started.
  2. Selenium can't interact with those pop-ups, so you need to set the path of file to be uploaded in the input field. Depending how the the upload field / button has been created you might need to make the input field visible to be able to interact with it. This can be done by injecting some JS into the page and set the element to visible. How this needs to be done depends on how the developers have written the page. There's no silver bullet for this.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文