简体   繁体   English

在Jenkins上验证下载的文件内容

[英]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. 我正在使用硒在jenkins中下载文件,但是我想验证下载的文件。 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). 我可以使用selenium吗?(下载文件后,文件将是jenkins的文件夹,我需要确认文件是否已下载)。 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. 您必须使用Java文件处理类来遍历目录并断言工作空间文件夹中是否存在文件。 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. 只需执行Windows批处理命令并运行dir命令,即可在当前工作空间文件夹中搜索该下载文件。

dir <youFileName>  /s /p

Apply selective, find or EQU operation to assert if file exists or not. 应用选择, findEQU操作来断言文​​件是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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