Cómo comprobar si un archivo zip se descarga correctamente o no el uso de WebDriver java-selenio?

Rahul:

Estoy descargando varios archivos zip desde una aplicación y cada archivo tiene un tamaño diferente. Obviamente, el tiempo de descarga depende del tamaño del archivo. Tengo el siguiente código java para comprobar la descarga basado en el tamaño del archivo .Pero no está funcionando como expected.It está a la espera de 10 segundos y que termina el bucle de continuar con el siguiente conjunto de líneas. Podría alguien por favor me ayude a resolver este problema?

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);

        }

L tamaño de archivo antes y después del tiempo de espera siempre está regresando 43 bytes.

pburgr:

Así es como me las arreglo descarga de archivos:

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;
      }
}

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=188724&siteId=1
Recomendado
Clasificación