How to upload a file in Katalon - katalon-studio

So I want the automated test case to find the file and upload it. This is what I found with my research but no luck with it.
WebUI.openBrowser('C:\\\\Users\\\\User\\\\Desktop\\\\Katalon Articles\\\\File Upload\\\\UploadFile.html')
'Maximize the window\r\n'
WebUI.maximizeWindow()
'Uploading the File using Send Keys method by passing the File path'
WebUI.sendKeys(findTestObject('Upload File'), 'C:\\\\Users\\\\Public\\\\Pictures\\\\Sample Pictures\\\\Desert.jpg')
'Capturing the file name after upload and storing it in a variable'
FilePath = WebUI.getAttribute(findTestObject('Upload File'), 'value')
'Verifying the Actual path and Expected path of file'
WebUI.verifyMatch(FilePath, 'C:\\fakepath\\Desert.jpg', false)

Related

Write text to file in Flutter(Dart)

I want to be able to create a new file and write a string into it. Examples that I can find all seems to pertain to writing to an existing file.
String fileName = 'myFile.txt';
String contents = 'hello';
void writeToFile(String fileName, String contents){
File outFile = File('content://com.android.providers.media.documents/document/document/document_root/' + fileName);
outFile.writeAsString(contents);
}
This results in the following error, as expected
Unhandled Exception: FileSystemException: Cannot open file, path = 'content://com.android.providers.media.documents/document/document/document_root/myFile.txt' (OS Error: No such file or directory, errno = 2)
How can I create a new file in which I can write my contents?
Are you sure that the path exists? writeAsString does create the file if it doesn't exists, but it doesn't create the full folder structure up to the file you're trying to write to. Also, you might not have the rights to write in the path you've specified.
Anyway, you'd better use this plugin to get the folders' path instead of hard-coding them.

How to download a dropbox file?

Here is some code I got from one of the other responses:
UrlDownloadToFile, https://gist.github.com/gimoya/5821469/raw/034b2766bbcbe70e2a8e93b72d1ec8723351a8f8/Veg%C3%96K-Abk%C3%BCrzungen, hotstrings.ahk
if(ErrorLevel || !FileExist("hotstrings.ahk") ) {
msgbox, Download failed!
ExitApp
}
Run, hotstrings.ahk
I tried to modify it to my needs by changing the URL but it just shows this sign:
Download failed and that the compressed zip folder is invalid.
If you just get the direct download link for the Dropbox file, it works just fine:
URLDownloadToFile, % "https://www.dropbox.com/s/t1emirfeqbnu8tu/hello.txt?dl=1", % "my_cool_file.txt"
(Thanks to the first link on Google for this random example Dropbox file)
Adding ?dl=1 gives the direct link.

Batch Printing files to new folder as PDF's

I have a folder of 2000+ PDF files that I need to print and resave as new PDF files in a separate folder using the original file name. Is there a way to do this in powershell or using a CMD?
I have tried to select multiple files in the folder to print at the same time by right clicking and selecting the print option. However this gets stuck at the window requesting a new file name and a destination folder which I am unable to provide as each file needs to have the original file name.
// the directory to store the output.
string directory = Environment.GetFolderPath
(Environment.SpecialFolder.MyDocuments);
// initialize PrintDocument object
PrintDocument doc = new PrintDocument() {
PrinterSettings = new PrinterSettings() {
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.Print();
I would like to see the new PDF file saved as a new PDF in the destination directory folder with the same file name as the origin directory.
Origin Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\NonRedacted --> Origin File name "Random_Name.PDF"
Destination Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\Redacted --> Destination File Name "Random_Name.PDF"

citrus waitFor().file fails to read a file

I’m trying to use waitFor() in my Citrustest to wait for an output file on disk to be written by the process I’m testing. I’ve used this code
outputFile = new File “/esbfiles/blesbt/bl03orders.99160221.14289.xml");
waitFor().file(outputFile).seconds(65L).interval(1000L);
after a few seconds, the file appears in the folder as expected. The user I’m running the test code as has permissions to read the file. The waitFor(), however, ends in a timeout.
09:46:44 09:46:44,818 DEBUG dition.FileCondition| Checking file path '/esbfiles/blesbt/bl03orders.99160221.14289.xml'
09:46:44 09:46:44,818 WARN dition.FileCondition| Failed to access file resource 'class path resource [esbfiles/blesbt/bl03orders.99160221.14289.xml] cannot be resolved to URL because it does not exist'
What could be the problem? Can’t I check for files outside the classpath?
This is actually a bug in Citrus. Citrus is working with the file path instead of the file object and in combination with Spring's PathMatchingResourcePatternResolver this causes Citrus to search for a classpath resource instead of using the absolute file path as external file system resource.
You can fix this by providing the absolute file path instead of the file object like this:
waitFor().file(“file:/esbfiles/blesbt/bl03orders.99160221.14289.xml")
.seconds(65L)
.interval(1000L);
Issue regarding broken file object conversion has been opened: https://github.com/christophd/citrus/issues/303
Thanks for pointing to it!

Display HTML page inside mail body with Email-ext plugin

I'm facing a little problem using Email-ext plugin on Jenkins.
I added the following line to inject my surefire html result to the email sent by the plugin :
${FILE,path="server/target/site/surefire-report.html"}
and I put contenant type as HTML (text/html)
I'm using Jenkins 1.651.1 and Email-ext plugin 2.42
I receive an e-mail in the end of my build with the following contenent
${FILE,path="server/target/site/surefire-report.html"}
It's like the plugin did not understand any thing.
Do you have an idea ?
any update on that ?
my project structure is like this :
workspace
master
commun
server/target/surefire-report/surefire-report.html
If you use a custom path this answer is for you
I had a complication trying to achieve this result because my path was dynamically changing and I had to use a variable inside a FILE variable. So when I tried any of the following
body: '${FILE,path=${report}}'
body: "${FILE,path=${report}}"
body: '''${FILE,path=${report}}'''
and many more, it didn't work. On the other hand I couldn't read the file with groovy because of Jenkins restrictions
My workaround was to read the html directly with groovy sh command like so
html_body = sh(script: "cat ${report}", returnStdout: true).trim()
and then just send the email
emailext replyTo: '$DEFAULT_REPLYTO',
subject: "subject",
to: EMAIL,
mimeType: 'text/html',
body: html_body
where ${report} was a path to html file like /var/jenkins/workspace_318/report.html
Please note that file path is relative to the workspace , if file resides in the root of your workspace , filename alone in the path will work , if it resides in a different location try somthing like this below :
${FILE,path="target/surefire-reports/emailable-report.html"}
I was also having the prob where the mail had the command with error coould not find file. Like mentioned above, the html file should be present exactly under the jenkins workspace folder. if not then give the relative path, even an extra "/" in front seems to throw error.
ex:
My file is in C:\CICDJenkins\ReadyAPIReport\summary.html
My jenkins workpace (im using custom workspace) is C:\CICDJenkins
what worked for me is:
${FILE, path="ReadyAPI_report/overview-summary.html"}