cucumber test file download

后端 未结 5 1255
渐次进展
渐次进展 2020-12-10 02:32

Anybody have idea how to test file download using cucumber?

5条回答
  •  伪装坚强ぢ
    2020-12-10 02:54

    For Chrome you can set the capability providing chrome options. Refer below code

          String downloadFilepath = "path to specify download location e.g. C:\\Downloads";      
          Map chromePrefs = new HashMap();
          chromePrefs.put("profile.default_content_settings.popups", 0);
          chromePrefs.put("download.default_directory", downloadFilepath);
          ChromeOptions options = new ChromeOptions();
          options.setExperimentalOption("prefs", chromePrefs);
          DesiredCapabilities cap = DesiredCapabilities.chrome();       
          cap.setCapability(ChromeOptions.CAPABILITY, options);
          WebDriver driver = new ChromeDriver(cap);
    

    then you can use exists() method of java.io.File to make sure if file exists.

        File file = new file(downloadFilepath+filename);
        assert file.exists() : "File not downloaded";
    

提交回复
热议问题