How do I test file download using intern framework? - intern

I have a requirement where I need to write functional test for download a file and testing its contents.
So i can say there are two parts.
1) Ensure clicking on a link downloads a file
2) Reading the file an checking its contents. Its a csv file, so I Can possibly do some manipulation with the content.

There are several issues with doing this. One is that if you're running a browser on a remote system, you'll need a way to get the file back to the system running Intern. The second issue is that you'll need to know where the downloaded file ended up when it was downloaded. A third issue is that some browsers (FF and IE) pop open OS-level dialogs that Selenium can't deal with.
The first question is: do you really need to download a file in the browser? It sounds like you may be testing a service rather than the browser, in which case you may be able to just download the file using Intern and inspect it there.
Assuming you do need to download a file via the browser, you should be able to configure a browser to not open a confirm dialog and to download the file to a known location, which at least handles 2 of the 3 issues mentioned above. Note that I haven't actually tested this.
In Firefox you can setup a test profile and use it when running tests. You'll likely need to configure the following properties:
browser.download.dir: 'path to download folder'
browser.download.folderList: 2
browser.helperApps.neverAsk.saveToDisk: 'text/csv'
browser.download.manager.showWhenStarting: false
For Chrome you'll pass options through the environment descriptor. The specific options should be:
'profile.default_content_settings.popups': 0
'download.default_directory': 'path to download folder'
Once you've setup the browser, your test code would need to click the link, then wait for some indeterminate amount of time (Selenium doesn't provide any sort of download progress data), then grab the file from the Intern test itself (using a network request or local file operation) to inspect it.

Related

Run Buffer(.exe) without writing files in Nodejs

Suppose I had a console app in the terminal I created using C language, shouting "Hello world!"
The program is called hello.exe.
I upload hello.exe to static server.
Now I can download the file by typing the following address in the chrome.
http://localhost:8080/hello.exe
Or I can get a Blob object using the http method in Nodejs.
Is there a way to run this obtained Blob object right away without making a file? And get string Hello world!
No similar topics were found.
Do I need to create and run the file and erase it right away?
I want is for the files to run and not remain on my PC.
I'm not aware of any way to run an .exe file without first putting it on disk. You would essentially need to write your own exe loader that worked from memory instead of disk and that would be no small effort.
Keep in mind that a client that just automatically runs some executable it gets from a URL like http://somedomain.com/hello.exe without any user intervention could be a very dangerous client as rogue web servers could send it any arbitrary executable that did all sorts of harm (viruses, ransom-ware, etc...).
Do I need to create and run the file and erase it right away?
Yes, erase it after the program is done running.
I want is for the files to run and not remain on my PC.
You will just have to clean it up at some point after it has run. If you have a programmatic client, it should be no big deal to put the file in an application-level temporary directory that your app can regular clean up. If this is from a browser, then he user controls where the file goes on disk and the user controls when it gets deleted - you can't manage that yourself from within a webpage.
Or I can get a Blob object using the http method in Nodejs.
You can download a binary. Not sure exactly what you're asking here.

Update some chrome extension files from own server

I am writing a chrome extension in which some script and an XML file in which I data is to be read by the script are changed almost twice per day. If I include a link to it on every page load, my hosting server load will probably suffer. Isn't it possible to get a copy of my script and XML Files each time that the browser is launched in order to update them in my extension ?
PS : I resorted to this solution since it is not possible to get the Update of the extension directly from my server since chrome's last upgrades.
- Any other way to update my extension is welcomed .

Is there a way to use a downloaded (xml-esque) file in an extension?

I'm attempting to write an emusic download manager extension for Chrome. This would essentially involve parsing the .emx file (xml-esque) downloaded from the site to get the temporary music file URL.
I've gone through everything I can find online about extensions working with downloads, but the problem comes in that the .emx file isn't directly accessible from the web. The link to download it seems to pass through a counter for your account so that it can deduct the cost, and then it pushes a file 0.emx to be downloaded. It doesn't seem to work with any hotlinking, even copying and pasting the button's destination URL into the same browser tab.
I think the only way to get the file is to wait for the 0.emx file to be pushed. Is there any way I can use an extension to intercept that file before it goes to the downloads folder or use it after it's already downloaded?
Thanks!

Making a Windows Installer communicate with a Chrome extension without NPAPI

I have a windows application which installs a Chrome extension via the windows registry. I wish for this application to generate some one-time information for Chrome to read based on information typed in by the user during the installation process.
Assuming I am not using NPAPI in the Chrome extension, is there anywhere the installer can place information such that the extension will see it?
Edit: I also wish to launching chrome at the end of the installation.
Another way you can pass information to an installed extension from outside of Chrome is to have a page with your extension that you then open Chrome too and pass the info in the hash...such as....
chrome.exe "chrome-extension://emcggffhhapbbkcodabdliakappfibcf/showHash.html#info"
Problem with this method is your installing the extension using the simple registry method (Im guessing) and not using the Policy method. With the Policy method you can force an install and it will happen even if Chrome is allready open (where as according to the docs the simple method happens the next time Chrome is opened). Downside to this is you will have to make an uninstaller yourself as you cant uninstall an extension from Chrome that is installed with this method. Im also not sure how quick/often it will be before the extension is installed (couldnt find it in the docs and too lazy to try it ;)) and youd need to make your installer wait a bit for it to be installed....
http://www.chromium.org/developers/how-tos/adding-new-policies
http://dev.chromium.org/administrators/policy-list-3#ExtensionInstallForcelist
http://dev.chromium.org/administrators/policy-templates (says where in the registry to add them)
Another possible method could be to pack the extension at install time and add a file with the info that the extension could read. Problem with this method is that the extensions ID would change (might not be a problem for you?) or youll have to include the PEM in your installer which you probably dont want to do....
chrome.exe --pack-extension="C:\simple-example" --no-message-box
Many people wish there were an event firing on extension installing.
There's a workaround, not elegant way to send info to the browser from outside: launch chrome asking to open an url.
I use it with a local html file. My application execute a command line like:
"pathToChrome\Chrome.exe" "file://pathToHtmlFile/myFile.html?param1=value1&param2=value2"
The info I pass are the page's parameters.
The catch is that this page is read by the extensions in one of many ways:
You can write a content script this page will fire
You can put some javascript on this page to write down the parameters as cookies, for the extension to read in the future (without calling the extension at this time)
It hasn't to be a local page. If your page is on a server, it can save the parameters in the server, ir it worthy.
It hasn't to be even your page. You can call any page on Internet, but beeing sure it will fire your content script extension, and it will read your "customized" parameters.
Instead of communicating through the windows registry, you can create a WebSQL from the installer and from the extension read the data from there.
You will need to a bit of research about how to this, but this is possible. the steps should be:
The installer will create the database and register to chrome (maybe with the Databases.db)
The extension will use openDatabase to create a connection to the database
The extension will do a transaction and read the needed file.
Another option is to add file to the crx for example "installer_info.json" and do an AJAX request from the extension to the "installer_info.json" file.
There is no formal way for doing this things, little research and you will have a way.

How can I open a local file with a local program through my browser?

On my webpage, I have placed a link to a local file (e.g. "text.docx" on my local HD). I would like to double click on this link, and have a third party software which is installed locally on my PC (e.g. Microsoft Word) open it.
I would like to be able to do this with Firefox and Google Chrome. Obviously, I am a newbie to web programming.. can somebody show me the way? I have looked around and had the impression that I need to write and add an extension, maybe?
Thanks for your time. Jakob
This is only possible if you know either the absolute path to the file or the relative path from whatever working directory your browser runs from. You the create a link with
href="file://relative/path/to/file/text.docx"
or
href="file:///absolute/path/to/file/text.docx"
and any modern browser will query the system database for the mimetype of the file depending on its extension, thus prompting to open the correct application.
EDIT
I inawarently introduced a unixism in the previous code: Distinction bewteen absolute and realtive paths as above works well on current *nix desktops, but in Windows an absolute path will most likely look like
href="file://C:/drive/absolute/path/to/test.docx"
Mind the 2 (not 3) slashes a the beginning, and the forward (not backward) slashes.
As far as I know, you can't link to local files from a website. If you upload it to where your files are, you could then be able to download it.
I was able to execute code locally, using Firefox, by adding an extension which used the XPCOM interface. One such extension was "commandrun", and may be found here: https://github.com/aabeling/commandrun .

Resources