Aloha All. I am struggling with why my code works in the test case itself, but when I created a keyword it does not.
Test Case:
import java.nio.file.StandardCopyOption as StandardCopyOption
import java.io.IOException as IOException
import java.nio.file.Files as Files
import java.nio.file.Path as Path
import java.nio.file.Paths as Paths
Path sourceDir = Paths.get(GlobalVariable.dept152srcfolder)
assert Files.exists(sourceDir)
Path sourceFile = Paths.get(GlobalVariable.dept152srcfolder + GlobalVariable.dept152srcfile_1)
assert Files.exists(sourceFile)
Path targetDir = Paths.get(GlobalVariable.dept152importfolder)
assert Files.exists(targetDir)
Path targetFile = Paths.get(GlobalVariable.dept152importfolder + GlobalVariable.dept152srcfile_1)
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING) //copy with REPLACE_EXISTING option
assert Files.exists(targetFile)
The above runs just fine. The file shows up in the targetDir.
I want to create a keyword of the above and then pass the parameters like so:
CustomKeywords.‘global.filefolderops.copyFileToFolder’(GlobalVariable.dept152srcfolder, GlobalVariable.dept152srcfile_1, GlobalVariable.dept152importfolder)
Keyword is:
import java.nio.file.StandardCopyOption
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
public class filefolderops {
@Keyword
def copyFileToFolder(String sourceDir, String sourceFile, String targetDir) {
println('Source Directory: ' + sourceDir)
println(' Source File: ' + sourceFile)
println('Target Directory: ' + targetDir)
Path targetFile = Paths.get(GlobalVariable.dept152importfolder + GlobalVariable.dept152srcfile_1)
println(' Target File: ' + targetFile)
//assert Files.exists(sourceDir)
//assert Files.exists(sourceFile)
//assert Files.exists(targetDir)
//Path path = Files.copy(sourceFile, targetFile,StandardCopyOption.REPLACE_EXISTING);//copy with REPLACE_EXISTING option
Files.copy(sourceFile, targetFile,StandardCopyOption.REPLACE_EXISTING);//copy with REPLACE_EXISTING option
//assert Files.exists(targetFile)
}
}
I get:
2022-11-03 11:03:41.293 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass -
groovy.lang.MissingMethodException: No signature of method: static java.nio.file.Files.copy() is applicable for argument types: (java.lang.String, sun.nio.fs.WindowsPath, java.nio.file.StandardCopyOption) values: [152-CA_DUE1_5Records.txt, \wc1na01\WalzEnvFS\INTSE\CertifiedPro\ImportFolders\152\152-CA_DUE1_5Records.txt, …]
Possible solutions: copy(java.nio.file.Path, java.nio.file.Path, [Ljava.nio.file.CopyOption;), copy(java.nio.file.Path, java.io.OutputStream), copy(java.io.InputStream, java.nio.file.Path, [Ljava.nio.file.CopyOption;), any(), notify(), wait()
2022-11-03 11:03:41.302 ERROR c.k.katalon.core.main.TestCaseExecutor
I have spent several hours googling and trying to figure this out, but am not understanding what the issue was. I saw some posts saying the signature error meant I was not passing the same number of parameters that the keyword was expecting, but I am passing 3 and expect 3. I saw mentions that maybe the keywords cannot accept more than one parameters, but that seems unreasonable.
Thank you in advance for any help anyone can provide. This is driving me nuts!
Dave
