在selenium网格上创建并上传文件 [英] Create and upload a file on selenium grid

查看:221
本文介绍了在selenium网格上创建并上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试用例之一是将文件上传到应用程序。通过创建伪造文件并获取文件的绝对路径并填充输入字段并单击上载,可以轻松完成Witouth网格。但是,当我使用网格时,该文件不在托管节点的计算机上。无论如何要么将文件发送到节点或告诉节点创建文件并获取绝对路径。

One of tthe test cases that I have is to upload a file to the application. Witouth grid this can be easily done by creating a bogus file and get absolute path of the file and fill the input field and click upload. However when I am using grid, the file is not on the machine that hosted the node. Is there anyway to either send the file to the node or tell the node to create the file and get the absolute path.

推荐答案

一旦你知道如何设置本地文件检测器,它实际上非常简单。

It's actually pretty simple once you know how, just set a local file detector.

import org.openqa.selenium.remote.LocalFileDetector
import org.openqa.selenium.remote.RemoteWebDriver

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox());
driver.setFileDetector(new LocalFileDetector())

然后只需正常上传,Selenium会通过电线将文件触发到节点。

Then just upload as normal and Selenium will fire the file across the wire to the node.

这篇关于在selenium网格上创建并上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆