Relative path issue test cafe during file upload test using set files to upload() - testing

I am trying to validate a file upload using test cafe.the things are fine when I give absolute path of the file with in the t.setFilesToUpload() but when I give relative path its not finding the files and says could not find the required file. Can anyone help with this?
I tried using relative path of the file to be uploaded.

It's not clear how you validate file upload. Please refer to the related help topic in the TestCafe documentation. If you still have issues after reviewing it, please share an example that reproduces the issue.

Related

Can I use links in setValue in file upload using nightwatch

Can I use links in different site in setValue in file upload using nightwatch? I look up a link in stackoverflow and see this: File Upload Testing in Nightwatch.js but the answer said that it will not work if the file is coming from 'http://localhost:3000/testfile.txt'. Is this not possible?
The simple answer is no you can not specify the web server path.
You can read more about here.
What you can do is First download file and then use its absolutes or relative paths to upload.

How do I download a file in a custom directory?

I googled it and no help. I am making a program here people register and then they can download some indie games i am creating. But i am having problems with the download function. When i go to download the game / program i am getting a error saying i need a file extension here is the code i am trying
My.Computer.Network.DownloadFile("https://www.dropbox.com/sh/yioya7ek0dq1r60/AABzT-98B4DWPdgv1edYC5SMa?dl=0", "C:\ProgramData\GamingcenterApp\games")
I need it to be like this because it is downloading a games folder that the gaming center will know it is installed so it can open the app.
Thanks GamingBlock
Let me explain what to do. DownloadFile downloads a file to your PC, and not a folder. Here is the fixed code:
My.Computer.Network.DownloadFile("C:\ProgramData\GamingcenterApp\games", "READ_ME.txt")
Folders are purposely not supposed to be downloaded by the DownloadFile call. I haven't tested your code but it could generate an exception.
Argument 1 is the file you want to download from the internet, and Arguement 2 is the file name. Not the directory you want it to download to. Also, You can't set the text in the .txt file by code. And of course this will generate an exception because I tested your code.
If this does not help, Simply comment on this answer and I will try to improve it.

File upload path in a test

A geb test tests file upload in a grails application. According to the documentation the absolute path of the file has to be specified in the test. Is it possible to make the test a bit more portable between developers/machines by including a file in the grails source tree and then getting its absolute path from the geb test?
You may be interested in doing something like this
http://www.mkyong.com/java/how-to-get-the-filepath-of-a-file-in-java/
In the Get file path example he creates a temporal file and then gets its filePath. If you need a specific file then I recomend you to build / write on it after creating it, this way you have a User/enviroment free file to access from your app anytime.
I ran into a problem like this once, uploading a photo to a server with grails, and for test or repetitive actions I created it and added the base64 code on runtime.
Hope it helps. Good luck! :)
I just ended up using System.properties['base.dir'] to get real path to my application.
String cd = new File(".").getAbsolutePath().replace(".","");
String file = cd + "file.jpg"
println file
It's work for me, on windows an linux.
it's need for CI and local building test.

docx4j: help converting docx to PDF

My goal is to take an existing .docx file and convert it, from a Linux command-line, to PDF using docx4j (http://www.docx4java.orghttp://www.docx4java.org). The "getting started" guide (http://www.docx4java.org/svn/docx4j/trunk/docx4j/docs/Docx4j_GettingStarted.html) refers to a samples directory that isn't actually included in the latest (2.8.1) package. Regardless, I located the samples directory in their SVN browser, created a 'samples/' subdirectory in my docx4j folder containing all the .jar files, and downloaded the CreatePdf.java file into the samples directory. Then I tried running:
java -cp docx4j-2.8.1.jar:log4j-1.2.15.jar org.docx4j.samples.CreatePdf my-file.docx
And I get the error:
Error: Could not find or load main class samples.org.docx4j.samples.CreatePdf
Any help would be greatly appreciated.
The samples are included in 2.8.1. Nothing has changed there, except the name of the sample, which is now ConvertOutPDF
Please try that instead.
btw, the SVN repository has been superseded since May. See docx4j-from-github-in-eclipse

Intellij Idea problem with text file impossible to read

I have a problem using Intellij Idea.
I am absolutely unable to load text file as InputStream - it doesnt matter where do I put the file (main/java, main/resources...) it just can't find the file - in Eclipse everything works just fine.
I tried setings->compiler->resource patterns and added ?*.txt but that doesn't seem to work either.
Any help is appreciated.
If you load it as a File, make sure that Working Directory is properly set in IDEA Run/Debug Configuration, since it's the default directory where Java will look for a file when you try to access it like new File("file.txt"). Working directory should be set to the directory of your project containing .txt files.
If you load files as a classpath resource, then they should reside somewhere under Source root and will be copied to the classpath according to Settings | Compiler | Resource Patterns.
If you can't get it working, upload your project somewhere including IDEA project files so that we can point to your mistake.
Look at the image, notice that the txt files are in the project root, and not the source folders (in blue).
If you open the Project Structure dialog, and click on Modules and select your module - are the correct folders marked as Source Folders on the sources tab?
Link for how to get to Project Structure dialog
Also, if you print out the absolute path of that file you are trying to read, is that anywhere near where you expect it to be?
An easy way to figure out the same would be to try creating a file in the same fashion and see where it gets created in your project. You can put your input file at the same location and it should work just fine (if it doesn't, you should check your resource pattern which might be causing the file to be not copied over in the build output).
This method actually gives you the working directory of your intellij settings which is pointed out in the accepted answer. Just sharing as I had similar trouble and I figured out this way. :)