[英]How to write a file into unix folder from windows folder using java
[英]How to upload a file from project folder regardless of the OS(Windows or Unix) When the tests are executed on Selenium Grid
我編寫了一個測試(帶有Java的Selenium WebDriver),其中必須從OS文件瀏覽器(上傳窗口)上傳文件。
我用了,
String path =System.getProperty("user.dir")+ File.separator +"TestDoc"+File.separator+"File.pdf";
它可以在我的本地計算機(Windows Machine)上運行,但是當我嘗試使用Jenkins在AWS服務器上運行時出現錯誤。
error: NullPointerException.
調試后,我看到的是它使用我的本地計算機文件夾地址(C:\\Users\\...\\...\\TestDoc\\File.pdf)
是否有其他方法可以從項目文件夾上載具有該特定計算機的文件夾地址的文件,無論如何?
如果在網格上運行測試,並且文件的位置位於不同操作系統的遠程計算機上,並且測試是在不同操作系統的計算機上執行的,則應讓遠程驅動程序知道需要上傳的文件位於本地計算機而不是遠程計算機上。
String path =System.getProperty("user.dir")+ File.separator +"FolderName"+File.separator+"File.pdf";
WebElement El = driver.findElement(By.id("'fileUploadField'"));
RemoteWebElement ele=(RemoteWebElement) ((RemoteWebDriver)baseSeleniumTest.driver).switchTo().activeElement();
ele.setFileDetector(new LocalFileDetector());
ele.sendKeys(path);
您可以使用:
String path =System.getProperty("user.dir")+ File.separator +"FolderName"+File.separator+"File.pdf";
WebElement El = driver.findElement(By.id("'fileUploadField'"));
El.sendKeys(path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.