首页 > 系统服务 > 详细

[Selenium] Upload File on Remote Node Machines

时间:2020-01-03 14:42:21      阅读:92      评论:0      收藏:0      [点我收藏+]

Problem: 

In web UI automation testing, we always need to upload files, it will work well on local machines, but doesn‘t work on remote node machines when using Seleniuim Grid to run.

Solution:

No
Description
Recommendation Index
1

1.Use PathUtils to get file‘s path under project

2.Convert input WebElement to RemoteWebElement

3.Call setFileDetector for the RemoteWebElement

4.Call sendKeys for input WebElement

Note: for input element

技术分享图片技术分享图片技术分享图片技术分享图片技术分享图片
2

1.Copy upload file to a share folder

2.Call sendKeys with above file path in share folder

技术分享图片技术分享图片技术分享图片

Code:

Solution 1:

String filePath = pathUtils.getFilePathFromResources(fileName);

public void uploadDocument(String filepath) {
    WebElement button = page.getUploadDocument();
    ((RemoteWebElement) button ).setFileDetector(new LocalFileDetector());
    button.sendKeys(filepath);
}

Solution 2:

技术分享图片

 

 

 

[Selenium] Upload File on Remote Node Machines

原文:https://www.cnblogs.com/MasterMonkInTemple/p/12144522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!