[英]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 机器中下载的文件呢?
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(); }
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");
Selecting and uploading files while running your tests on Selenium Grid 在 Selenium Grid 上运行测试时选择和上传文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.