zipファイルが正常のjava-セレンwebdriverをを使用していないダウンロードまたはされているかどうかどうかを確認する方法?

ラーフル:

私は、アプリケーションから複数のzipファイルをダウンロードしていますし、それぞれのファイルには、異なるサイズを有します。もちろん、ダウンロード時間は、ファイルサイズに依存します。私はそれだけで10秒を待っていると、ラインの次のセットに継続することにより、ループを終了していexpected.Itとして活躍されていない.But、ファイルサイズに基づいて、ダウンロードを確認するためにJava以下のコードを持っています。誰かが私は、この問題を解決してくださいもらえますか?

public void isFileDownloaded(String downloadPath, String folderName) {

        String source = "downloadPath" + folderName + ".zip";

        long fileSize1;
        long fileSize2;
        do {
            System.out.println("Entered do-while loop to check if file is downloaded successfully");

            String tempFile = source + "crdownload";
            fileSize1 = tempFile.length(); // check file size
            System.out.println("file size before wait time: " + fileSize1 + " Bytes");
            Thread.sleep(10); // wait for 10 seconds
            fileSize2 = tempFile.length(); // check file size again
            System.out.println("file size after wait time: " + fileSize2 + " Bytes");

        } while (fileSize2 != fileSize1);

        }

待ち時間の前と後のファイルサイズは、常に43のバイトを返しています。

pburgr:

これは私がダウンロードしたファイルを管理する方法です。

public class Rahul {

    String downloadDir = "C:\\Users\\pburgr\\Downloads\\";

    public WebDriverWait waitSec(WebDriver driver, int sec) {
        return new WebDriverWait(driver, sec);
    }

    public File waitToDownloadFile(WebDriver driver, int sec, String fileName) {
        String filePath = downloadDir + fileName;
        waitSec(driver, 30).until(new Function<WebDriver, Boolean>() {
          public Boolean apply(WebDriver driver) {
            if (Files.exists(Paths.get(filePath))) {
              System.out.println("Downloading " + filePath + " finished.");
              return true;
            } else {
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
                 System.out.println("Downloading " + filePath + " not finished yet.");
              }
            }
            return false;
          }
        });
        File downloadedFile = new File(filePath);
        return downloadedFile;
      }
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=188721&siteId=1