简体   繁体   English

在使用 Selenium Grid 时,我们如何从 Hub 机器访问 Node 机器中下载的文件?

[英]While using Selenium Grid, How do we access downloaded file in Node machine from Hub machine?

Here is my scenario:这是我的场景:

I am using Selenium Grid concept and we trigger test script execution from Hub (Machine-1) and script execute on chrome browser of Node machine (Machine-2).我正在使用 Selenium 网格概念,我们从 Hub(Machine-1)触发测试脚本执行,并在 Node 机器(Machine-2)的 chrome 浏览器上执行脚本。 In one of my test script when I click on export button, it downloads an excel file in default download folder of Node machine (ie Machine-2)在我的一个测试脚本中,当我单击导出按钮时,它会在节点机器(即 Machine-2)的默认下载文件夹中下载 excel 文件

Issue: Further in script I need to read content of the downloaded file, but as the downloaded file resides in Node machine, script does not able to access it from Hub.问题:在脚本中,我需要读取下载文件的内容,但由于下载的文件位于节点机器中,脚本无法从 Hub 访问它。

So, How do we access downloaded file in Node machine from Hub machine?那么,我们如何从 Hub 机器访问 Node 机器中下载的文件呢?

Local file detector本地文件检测器

The Local File Detector allows the transfer of files from the client machine to the remote server. 本地文件检测器允许将文件从客户端机器传输到远程服务器。 In case a test needs to upload a file to a web application, a remote WebDriver can automatically transfer the file from the local machine to the remote web server during runtime.如果测试需要将文件上传到 web 应用程序,远程WebDriver可以在运行时自动将文件从本地机器传输到远程 web 服务器。 This allows the file to be uploaded from the remote machine running the test.这允许从运行测试的远程机器上载文件。 It is not enabled by default and can be enabled as follows:默认不启用,可以如下启用:

  • Java : Java

     driver.setFileDetector(new LocalFileDetector());
  • Python : Python

     from selenium.webdriver.remote.file_detector import LocalFileDetector driver.file_detector = LocalFileDetector()
  • C# : C#

     var allowsDetection = this.driver as IAllowsFileDetection; if (allowsDetection.= null) { allowsDetection;FileDetector = new LocalFileDetector(); }

This usecase这个用例

If you are running your tests on Selenium Grid then you need to let your remote driver know that the file that needs to be uploaded is residing on the local machine and not on remote machine.如果您在Selenium Grid上运行测试,那么您需要让远程驱动程序知道需要上传的文件位于本地计算机上而不是远程计算机上。 In those cases, to upload a file from the client machine to the remote server, WebDriver can automatically transfer the file from the local machine to the remote web server during runtime you can use the following code block:在这些情况下,要将文件从客户端机器上传到远程服务器, WebDriver可以在运行时自动将文件从本地机器传输到远程 web 服务器,您可以使用以下代码块:

WebElement addFile = driver.findElement(By.xpath("//input[@type='file']"));
((RemoteWebElement)addFile).setFileDetector(new LocalFileDetector());
addFile.sendKeys("C:\\daten\\test2.xml");

Outro奥特罗

Selecting and uploading files while running your tests on Selenium Grid 在 Selenium Grid 上运行测试时选择和上传文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在同一台机器上运行 selenium 网格集线器和节点 - Run selenium grid hub and node the same machine 如何使用Selenium网格通过远程机器节点浏览器直接将文件下载到我的中心机器(存在我的项目代码工作空间的地方)? - How to directly download a file using remote machine node browser to my hub machine(where my project code workspace is present) using selenium grid? 在 Node 机器上执行批处理文件 - Selenium Grid - Execute batch file on Node machine - Selenium Grid 如何通过使用 Selenium Grid 将文件从本地机器传输到远程 web 服务器来上传文件 - How to upload a file by transfering the file from the local machine to the remote web server using Selenium Grid 我们如何使用Java从本地计算机打开远程计算机上存在的文件? - How can we open a file present on remote machine from local machine using java? Selenium Grid:如何以编程方式从HUB检索节点信息? - Selenium Grid: How to retrieve node information from HUB programatically? Selenium 网格集线器和节点来自 Java 代码 - Selenium Grid Hub and Node from Java Code 虚拟机上的Selenium Grid-如何配置 - Selenium Grid on virtual machine - how to configure 如何使用Java从一台计算机到另一台计算机执行SSH - How to do a ssh from one machine to another machine using Java 如何在不使用sendkey的情况下从窗口弹出菜单中从本地计算机中选择Selenium Webdriver中的文件 - How to select file in selenium webdriver from local machine from window popup without using sendkeys
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM