[Selenium] Upload File on Remote Node Machines
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:
相关推荐
xiangxiaojun 2020-09-23
Reiki 2020-08-16
letheashura 2020-08-14
tiankele0 2020-07-29
curiousL 2020-07-18
王练 2020-07-18
tiankele0 2020-07-18
amei0 2020-07-08
Reiki 2020-07-06
Ronnyxie 2020-07-06
xiangxiaojun 2020-07-05
zhanghaibing00 2020-06-28
xiongyouqiang 2020-06-28
Ronnyxie 2020-06-27
amei0 2020-06-26
letheashura 2020-06-26
tiankele0 2020-06-26
王练 2020-06-25