Is there any way to upload folders using testcafe? - javascript

I have to write an e2e test for folder upload by drag-drop functionality in my portal using testcafe. I know there is a method setFilesToUpload() to upload files but is there any method using which we can upload a folder/directory structure?

At present, you cannot specify a folder for the setFilesForUpload action.
You need to specify all file paths in the folder.
Here is an example:
await t
.setFilesToUpload('#upload-input', [
'folder1/1.jpg',
'folder1/2.jpg',
'folder1/3.jpg'
])
I've created a suggestion regarding your case - https://github.com/DevExpress/testcafe/issues/3206. You can track it to be notified of our progress.

Related

Is there a way to overwrite CKAN Javascript files in a plugin?

I'm writing a custom plugin for CKAN and in this plugin I want to overwrite the file https://github.com/ckan/ckan/blob/2.8/ckan/public/base/javascript/modules/image-upload.js from CKAN with a new implementation. Is there a way to do this?
I tried adding the file on the same path in the plugin, but that didn't work.
You can create a fanstatic directory in your extension and move the files there. Then use add_resource function to register that directory as explained here. As an additional example check this extension(register, directory)

How to download the complete project structure from cdnjs using Python

I want to download the complete project from the cdnjs cloud to local folder.
I have tried this:
import requests
files = requests.get("https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1")
with open("mathjax.js","w") as file:
file.write(files.text)
Now this download the js file. When I tried using the same code to get the project instead of the js file, the output was weird.
So I tried using the cdnjs and check what happens when I use cdnjs cloud and when I use local file.
I have got this difference as shown in the images:
Using cdnjs:
Using Local file:
How I can get the similar structure as I get when I use cdnjs?
Kindly, advise me.
The URL you are providing to requests module is just the URL of one file MathJax.js, that is why you are getting only that file as output.
What you want is to download the complete directory mathjax/2.7.5/. However, if we request the whole directory, the server forbids such requests.
An alternate approach is to get relative paths of all the files from the main directory, which you already have as you showed in image. You can then download each of the file independently and store it into its respective folder. You'll have the whole directory ready at the end.
Try the following code for this purpose.
import requests
import os
baseUrl="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/" #Base URL for the main directory
#List containing relative paths of all required files
relativePaths=['config/Safe.js?V=2.7.5',
'config/TeX-AMS-MML_HTMLorMML.js?V=2.7.5',
'extensions/Safe.js?V=2.7.5',
'jax/output/SVG/fonts/TeX/fontdata.js?V=2.7.5',
'jax/output/SVG/jax.js?V=2.7.5',
'MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1']
parentDir='\\'.join(baseUrl.split('/')[-3:]) #Parent directory from URL
for path in relativePaths: #For all files
req=requests.get(baseUrl+path) #forming url
filename=path.split("/")[-1].split("?")[0] #extracting filename out of url
directory=os.path.join(parentDir,"\\".join(path.split('/')[:-1])) #Extracting directories path for local path formation
if not os.path.exists(directory): #Creating local direcories if they do not exist
os.makedirs(directory)
with open(os.path.join(directory,filename),"wb+") as file: #Storing results into files
file.write(req.content)
Local Directory Structure Output:
Beyond iterating over a defined list of files, you could also look at a couple of other options that could take a more dynamic approach to fetch files from the CDN.
cdnjs is powered by a GitHub repository, so you could explore cloning it and extracting files (I'd recommend use sparse-checkout if you do this due to repo size) or you could look at using the GitHub API to navigate the repository an extract files: github.com/cdnjs/cdnjs/tree/master/ajax/libs/mathjax/2.7.5
We actually have an API available for cdnjs, which allows you to rather easily get all the files within a version of a library. Using that list, you could then perform a similar iterative solution to what Hamza suggested to get a copy of all the files locally: https://api.cdnjs.com/libraries/mathjax?fields=assets (annoyingly we've not yet implemented API navigation per version)
Hope that helps!
Matt, cdnjs maintainer.

Electron modify file store in .asar

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.
I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?
I see the extraResources option but I did not understand how its work.
It's also important that the config file stay in myapp/config folder.
Thanks for your help :)
What build tool do you use? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here
I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.
fs.chmod(filename, 0666, (error) => {
console.log('Changed file permissions');
});
...
code to modify file
...
asar is in readonly
as you mentioned asar intended to be readonly package. For runtime-changing config, you should place it outside of asar and change values accordingly.
To manage settings you should use a node package that's specifically designed for this, like electron-settings or preferences.
As an alternative one may manually read an write config files that you place in the platform's native config directory.
Mutable application settings shouldn't be stored in the asar file. If it's required to replace a file in an asar archive for any other reason, use the the asar program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.
To unpack .asar files -> asar extract electron.asar app
modify as per your needs
To pack .asar files -> asar pack . electron.asar

create-react-app exclude folder from triggering reload

I have a use case where I'm dynamically storing a pdf file in my public folder.
public/print-preview/.
The issue here is that the application reloads and the state gets lost after such a file was created and stored.
How can I exclude such a folder from being watched? And is there a way to achieve this without ejecting?
from https://github.com/facebook/create-react-app/issues/2541 :
I don't think we'll do this as it seems like people generally don't
use public folder for uploads. And it wouldn't work in production
anyway.
I would recommend to use a separate server (which you need anyway) and
separate folder for image uploads, and have the app load images from a
different host/port (just like it would in production, e.g. from a
CDN).
You can open the file node_modules\react-scripts\config\webpackDevServer.config.js and change the watchOptions.ignored setting to include the public folder like this:
watchOptions: {
ignored: [ ignoredFiles(paths.appSrc), paths.appPublic ]
},
Of course this is only temporary as reinstall/updates to node_modules will remove this.

How to upload folder in php

Hi i wanted to upload folder and move to some destination is it possible doing in php ? or at least i can read the folder name and create same folder in divination and copy all files into created folder.
You can do this with the new HTML5 directory capabilities. Just put the directory attributes in your input field. After you got the directory server-side, you can do everything you want with it.
URL for a simple guide:
http://www.w3bees.com/2013/03/directory-upload-using-html-5-and-php.html

Categories

Resources