I tried the code below but it isn't working. Can someone help me understand how to upload a file using autoit in protractor?
var path = require('path');
var file = "../Snaptrude/plans/"+filepath+"";
console.log('file path',file)
var filePath = path.resolve(__dirname, file);
// browser.sleep(3000);
element(by.css('input[type="file"]')).sendKeys(filePath);
var path = require('path');
var appRoot = require('app-root-path');
var uploadFile = appRoot + '/path of the file which you want to upload';
var deferred = protractor.promise.defer();
var control = element(by.xpath('you need to take the xpath of uploaded file'));
control.getText().then(function(text) {
if (text == 'filename') {
enter code hereconsole.log("success");
}
without using autoit you can upload the file using above way, if you are work on any web application.
Related
I may be asking the basics just now, sorry.
I want to convert Uint8Array back to a file and save it in db.
Is there anyone who can help me?
document.getElementById('upload_0').onchange = function(event) {
var ext = $('[name=upload_0]').val().split('.').pop().toLowerCase();
var file = event.target.files[0];
var fileReader = new FileReader();
fileReader.onload = async function() {
var typedarray = new Uint8Array(this.result);
const pdfSrcDoc = await PDFLib.PDFDocument.load(typedarray);
const pdfNewDoc = await PDFLib.PDFDocument.create();
const pages = await pdfNewDoc.copyPages(pdfSrcDoc, [0,1,2]);
pages.forEach((page) => pdfNewDoc.addPage(page));
const newpdf = await pdfNewDoc.save();
download(newpdf, "sample.pdf", "application/pdf");
}
-> download(newpdf, "sample.pdf", "application/pdf");
I want to convert this part into a file, not download it, and save it in db.
Also, I want to save the file name as the original name.
Can you tell me what I want to know?
Thank you.
Please help me. I want to upload file in my input-file.
My code is working fine in Chrome70 version. But after it stoped working. I am using this function.
Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {
return cy.get(selector).then(subject => {
cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = subject[0];
const testFile = new File([blob], fileName, {
type: fileType
});
const dataTransfer = new DataTransfer();
dataTransfer.items.add(testFile);
el.files = dataTransfer.files;
});
});
});
And in test I writing
const fileName = 'PNG.png';
const fileType = 'aplication/png';
const fileInput = '.editor-image-component .t-file-uploader-input';
cy.uploadFile(fileName, fileType, fileInput);
But it not working now. And not working "cypress-file-upload" plugin too.
Can anyone help me.
Note: when I am trying to upload fake file (which one not in my fixture folder), I have a assertion error
I am currently playing with the file upload functionality.
Using the example from: https://github.com/circuit/node-sdk-example/blob/master/index.js
var FileAPI = require('file-api');
var File = FileAPI.File;
//*********************************************************************
//* getFiles -- helper
//*********************************************************************
this.getFiles = function(path) {
var files = [];
var fileNames = fs.readdirSync(path);
fileNames.forEach(function (element) {
var file = new File(path + element);
files.push(file);
});
logger.debug('[APP]: getFiles' + files);
return files;
};
//*********************************************************************
//* Circuit - Post Logs
//*********************************************************************
this.postLog = function () {
logger.info('[APP]: Log Message will be posted');
//Get post content from File
var text = fs.readFileSync(config.log_message,'utf8')
logger.info('[APP]: Log Message extracted :', text);
//Get files from folder
var files = self.getFiles(config.log_folder);
var message = {
content: text,
attachments: [files]
};
return client.addTextItem(config.conversationID, message);
};
Could it be that it is not supported in the latest Node version?
I get the following error message:
TypeError: mime.lookup is not a function\n
at new File (/GIT/logToCircuit/node_modules/File/File.js:37:35)\n
at /GIT/logToCircuit/app.js:109:24\n
at Array.forEach (native)\n
at LogToCircuit.getFiles (/GIT/logToCircuit/app.js:108:19)\n
at LogToCircuit.postLog (/GIT/logToCircuit/app.js:128:26)\n
at /GIT/logToCircuit/app.js:84:18\n
at /GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:18119:25\n
at Array.forEach (native)\n
at BaseEventTarget.dispatch (/GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:18117:34)\n
at /GIT/logToCircuit/node_modules/circuit-sdk/circuit.js:49132:27","time":"2018-06-24T11:52:28.631Z","v":0}
mime.lookup was renamed to mime.getType see https://www.npmjs.com/package/mime.
What version of file-api are you including? The node-sdk-example includes git://github.com/voodoohop/file-api.git for exactly this reason. See https://github.com/node-file-api/file-api/issues/4.
I have a problem getting an image from filesystem. On iOS works fine.
First of all, I save a remote image in the filesystem with this function:
img.imagen = url from the remote image (e.g. http://onesite.es/img2.jpeg)
function descargarImagen(img, callback){
var path = img.imagen;
var filename = path.split("/").pop();
var xhr = Titanium.Network.createHTTPClient({
onload: function() {
// first, grab a "handle" to the file where you'll store the downloaded data
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, filename);
f.write(this.responseData); // write to the file
Ti.API.debug("-- Imagen guardada: " + f.nativePath);
callback({path: f.nativePath});
},
timeout: 10000
});
xhr.open('GET', path);
xhr.send();
}
Now, I want to share this image creating an Android Intent:
args.image = f.nativePath(in the previous function)
var intent = null;
var intentType = null;
intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND
});
// add text status
if (args.status){
intent.putExtra(Ti.Android.EXTRA_TEXT, args.status);
}
// change type according to the content
if (args.image){
intent.type = "image/*";
intent.putExtraUri(Ti.Android.EXTRA_STREAM, args.image);
}else{
intent.type = "text/plain";
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
}
// launch intent
Ti.Android.currentActivity.startActivity(Ti.Android.createIntentChooser(intent, args.androidDialogTitle));
What I'm doing wrong?
I'm able to create the JSZip object in my code, but I'm having trouble saving that to local storage in my windows 8 app. The examples I'm able to find set the browser's location.href to trigger a download, which isn't really an option for me.
I've included my code below. The zip file I end up with is invalid and can't be opened. Any help would be appreciated.
For reference: JSZip
function _zipTest() {
var dbFile = null;
var zipData = null;
Windows.Storage.StorageFile.getFileFromPathAsync(config.db.path)
.then(function (file) {
dbFile = file;
return Windows.Storage.FileIO.readBufferAsync(file);
})
.then(function (buffer) {
//Read the database file into a byte array and create a new zip file
zipData = new Uint8Array(buffer.length);
var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer);
dataReader.readBytes(zipData);
dataReader.close();
var localFolder = Windows.Storage.ApplicationData.current.localFolder;
return localFolder.createFileAsync(dbFile.displayName.concat('.zip'), Windows.Storage.CreationCollisionOption.replaceExisting)
})
.then(function (file) {
//Write the zip data to the new zip file
var zip = new JSZip();
zip.file(dbFile.displayName, zipData);
var content = zip.generate();
return Windows.Storage.FileIO.writeTextAsync(file, content);
});
}
you can do something on these lines. This code seem to generate valid .zip file in the temp folder.
var zip = new JSZip();
var storage = Windows.Storage;
storage.StorageFile.getFileFromApplicationUriAsync(new Windows.Foundation.Uri('ms-appx:///images/logo.png')).then(function ongetfile(file)
{
var blob = MSApp.createFileFromStorageFile(file);
var url = URL.createObjectURL(blob, { oneTimeOnly: true });
return WinJS.xhr({ url: url, responseType: 'arraybuffer' });
}).then(function onreadbuffer(req)
{
var b = req.response;
zip.file('logo.png', b);
return storage.ApplicationData.current.temporaryFolder.createFileAsync('a.zip', storage.CreationCollisionOption.replaceExisting);
}).then(function onnewfile(out)
{
var content = zip.generate({ type: 'uint8array' });
return storage.FileIO.writeBytesAsync(out, content);
}).then(null, function onerror(error)
{
// TODO: error handling
});