Everyone!
about two days trying to find solution to choose the image file for upload using nightwatch.js
Code looks like this:
module.exports = {
'File Upload': function (client) {
client
.url('http://myurl.com')
.click('#selector')
.end();
}
};
we clicked on drag and drop so something like this .setValue('input#fileUpload', require('path').resolve(__dirname + '/testfile.jpg')) can't be exists. And
.keys(client.Keys.DOWN_ARROW)
.keys(client.Keys.ENTER)
not works for this finder window:
I need something like sendKeys() in Selenium to choose the file from finder. Nightwatch.js .keys() works only for internet browser (Firefox for me) window. I need for popup finder to choose the file.
Thx.
Are you heard about online image sharing ,igmur/photobucket, upload the image then save the URL in your 'globals', for example we will have a file images.js in "globals_path":
module.exports ={
image1: 'www.imgur.com/iamge1',
image2: 'www.imgur.com/iamge2',
}
And in your test :
module.exports = {
'File Upload': function (client) {
const images = client.images;
client
.url('http://myurl.com')
.click('#choose-button')
.setValue('#txt-path',iamges.image1)
.click('#submit-button');
.end();
}
};
Related
I'm quite confused on how to use the Amplify library to actually download an mp3 file stored in my s3 bucket. I am able to list the bucket contents and parse it all out into a tree viewer for users to browse the various files, but once I select a file I can't get it to trigger a download.
I'm confident my amplify configuration is correct since I can see all my expected directories and when I select the file I want to download, I see the response size being correct:
You can see it takes 2+ seconds and appears to be downloading the data/mp3 file, but the user is never prompted to save the file and it's not in my Downloads folder.
Here is a capture of my file metadata setup from my bucket:
And the method I'm calling:
getFile (fileKey) {
Storage.get(fileKey, {download: true})
}
Without the "download : true" configuration, I get the verified URL back in the response. I'd like to avoid making a 2nd request using that URL download the file if possible. Anything else I may have missed? Is it better for s3 operations to go back to the standard aws-sdk? Thanks in advance!
I ended up using a combination of this answer:
https://stackoverflow.com/a/36894564
and this snippet:
https://gist.github.com/javilobo8/097c30a233786be52070986d8cdb1743
So the file gets downloaded in the response data(result), I added more meta data tags to the files to get the file name and title. Finally adding the link to the DOM and executing a click() on it saves the file named correctly. Full solution below:
getFile (fileKey) {
Storage.get(fileKey, {download: true}).then(result => {
console.log(result)
let mimeType = result.ContentType
let fileName = result.Metadata.filename
if (mimeType !== 'audio/mp3') {
throw new TypeError("Unexpected MIME Type")
}
try {
let blob = new Blob([result.Body], {type: mimeType})
//downloading the file depends on the browser
//IE handles it differently than chrome/webkit
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName)
} else {
let objectUrl = URL.createObjectURL(blob);
let link = document.createElement('a')
link.href = objectUrl
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
} catch (exc) {
console.log("Save Blob method failed with the following exception.");
console.log(exc);
}
})
}
}
I have a stored pdf, xls, doc, etc.. file in list, I have a actual path of a file URL, I am create documents Gallery in my app with download option, when i'm click download icon i have to download a that particular document.
Working fine for PDF and XLS and XLSX file Tested. But Word Document(.doc,.docx) File has been not properly downloaded.
It Shows alert is success. But while opening time it shows,
Unable to open the document.File appears to be corrupted like this.
I have tried
file trasfer plugin
i can't achieve pls help me to solve this problem.
here my tried code.
this.download("Sample Document.docx","https://abcd.sharepoint.com/samplesite/Shared Documents/Sample Document.docx");
download(fileName: string, filePath: any) {
const url= encodeURI(filePath);
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(url, this.file.externalRootDirectory + fileName, true).then((entry) => {
//show toast message as success
}, (error) => {
//show toast message as error
});
}
here is my output,
pls give some idea to download a word document file. Is there any other way is available to download a file using url in ionic3?
I have modified the code.
Please check and let me know if you have any issues.
this.download("sample.docx","https://abcd.sharepoint.com/samplesite/Shared Documents/Sample Document.docx");
download(fileName: string, filePath: any) {
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(filePath, this.file.externalRootDirectory + fileName, true).then((entry) => {
//show toast message as success
console.log('download complete: ' + entry.toURL());
}, (error) => {
//show toast message as error
});
}
NOTE : If the error message is still appearing (The file appears to be corrupted).Try with some other files in share-point list or add more files and try with them.This is a working code and the issue may be in share-point side.
I am doing azure ad authentication in my node js bot.
in the last step it is showing a pop windows with magic code.
I want to close that magic window pop up automatically after 5 sec.
this is code
res.send('Welcome ' + req.user.displayName + '! Please copy this number and paste it back to your chat so your authentication can complete: ' + magicCode);
this line send a window pop with magic code. iwant to close this window after 5 sec automatically.
my code
server.get('/api/OAuthCallback/',
passport.authenticate('azuread-openidconnect', { failureRedirect: '/login' }),
(req, res) => {
console.log('OAuthCallback');
console.log(req);
const address = JSON.parse(req.query.state);
const magicCode = crypto.randomBytes(4).toString('hex');
const messageData = { magicCode: magicCode, accessToken: req.user.accessToken, refreshToken: req.user.refreshToken, userId: address.user.id, name: req.user.displayName, email: req.user.preferred_username };
magicNum = magicCode;
var continueMsg = new builder.Message().address(address).text(JSON.stringify(messageData));
console.log(continueMsg.toMessage());
test_name = JSON.parse(req.user._raw).preferred_username.split("#")[0]
bot.receive(continueMsg.toMessage());
res.send('Sign-in successful');
}
);
Thanks in advance
It looks like you are using botauth lib, if so, there should be a html page which you need to use to display magic code.
This html should contain a similar js script code like:
document.getElementById("magic_code").innerText = (window.location.hash || '').replace('#', '');
And you can add following code to close the window in 5 secs
setTimeout(() => {
window.close();
}, 5000);
The similar code sample at https://github.com/CatalystCode/node-authbot. And all use the OAuth 2.0 process, which once user success signin the authenticate provider, it will redirect to your return url you configed in your server.
In your code, your auth return route simply send a string in browser. Also, you can render a HTML page to your user, however, you will face the issue
Scripts may close only the windows that were opened by it.
The same as the question you provide in comment.
Unfortunately, there are several question for this on SO:
window.close() doesn't work - Scripts may close only the windows that were opened by it
window.close and self.close do not close the window in Chrome, and currently no good solution for this.
I'm trying to generate report with cucumber-html-reporter. On it's GitHub page I saw a fancy bootstrap report, where a screenshot is attached to the failed step itself.
https://www.npmjs.com/package/cucumber-html-reporter
I'm working with cucumber-js 2.3.1 and cannot attach a screenshot to the StepResult.
I can attach a screenshot only in the After hook, where the World is available.
After(function (scenario) {
if (scenario.isFailed()) {
const world = this;
return browser.takeScreenshot().then(function (screenShot) {
world.attach(screenShot, 'image/png');
});
}
});
This is working fine, but unfortunately the screenshot is attached to the "After" step, not to the failed one.
I have tried this:
registerHandler('StepResult', function (StepResult) {
if (StepResult.isFailed()) {
return browser.takeScreenshot().then(function (screenShot) {
var decodedImage = new Buffer(screenShot, 'base64');
StepResult.attachments.push({
data: decodedImage.toString('base64'),
mimeType: 'image/png'
});
});
}
});
It works, the attachment is added, but not rendered into the report, since the cucumber json_formatter.handleStepResult is executed BEFORE the 'StepResult' hook is invoked.
Can someone show me a solution?
Thanks!
The reporter would show the Screenshot link in the failed STEP if you capture screenshot in the STEP itself. If you capture at the AFTER hook, it will show in the hook.
On the example shown in the Github page, it attaches the screenshot to the Step, and so it shows to the "then" step. Please take a look at here for more info.
I have a script to test that - on click - generates an iFrame which downloads a file. How can I intercept the response with CasperJS?
I already tried the sequence:
casper.click('element');
casper.withFrame('frame', function(){
console.log(this.getCurrentUrl()); // only return about:blank, but should have URL
console.log("content: " + this.getHTML()); // Yep, empty HMTL
this.on('resource.received', function(resource){
console.log(resource.url); // never executed
});
});
I need the content of the file but can not really produce the URL without clicking the element or changing the script I'm testing.
Ideas?
I tried other events, but none got fired when downloading via the iframe. I found another solution that works - but if you have something better, I'd like to try it.
Here it comes:
// Check downloaded File
.then(function(){
// Fetch URL via internals
var url = this.evaluate(function(){
return $('__saveReportFrame').src; // JavaScript function in the page
});
var file = fs.absolute('plaintext.txt');
this.download(url, file);
var fileString = fs.read(file);
// Whatever test you want to make
test.assert(fileString.match(/STRING/g) !== null, 'Downloaded File is good');
})