简体   繁体   中英

Verify downloaded file contents on Jenkins

I am automating withJenkins. I am downloading the file in jenkins using selenium, but I want verify the downloaded file. Can I do this using selenium.(Upon downloading the file, file will be jenkins's folders, i need to verify that file has downloaded or not). I am able to download the file on my local drive on my machine.

No, selenium cannot assert file presence in file system. You have to use Java file handling classes to traverse through the directories and assert if a file exists in the workspace folder or not. A sample pseudocode will be like this:

File dir = new File("C:\\Users\\"+System.getProperty("user.name")+"\\Downloads") ;
File[] files = dir.listFiles();
for (File f : files) {
    fileName = f.getName();           
    if (fileName.startsWith(initials) && fileName.endsWith(".csv") && fileName.contains(strDate.substring(0,7))) {
        iCount++;
        System.out.println(strDate.substring(0,7));
        Reporter.log("Found file :"+fileName);
    }
}

Alternatively, you can also check at jenkins job level. Just execute a windows batch command and run the dir command to search for that downloaded file in the current workspace folder.

dir <youFileName>  /s /p

Apply selective, find or EQU operation to assert if file exists or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM