Image upload functional testing in Geb - grails

When i am testing the image upload in Geb ,how i click the Open option when we
have to select image from the system My code is:
class UploadImageTestSpec extends GebReportingSpec{
def "test for UploadImage"()
{
when:
to LandingPage
waitFor(20) {title.endsWith("Jobulo")}
loginButton.click()
j_username="candidate2"
j_password="p"
login.click()
then:
at DashBoardPage
when:
at DashBoardPage
waitFor(20) {title.endsWith("Jobulo")}
uploadImage.click()
// uploadImage1.click()
Thread.sleep(1000)
//new File(".").getAbsolutePath().replace("..","");
// cd=new File(".").getAbsolutePath().replace("..",""); + "images.jpeg"
driver.manage().timeouts().implicitlyWait(200,TimeUnit.SECONDS)
crop.click();
then:
at DropDownPage
}
}

It is not possible to do image upload using geb.
Refer this link: http://www.gebish.org/manual/current/#file-upload
It’s currently not possible with WebDriver to simulate the process of a user clicking on a file upload control and choosing a file to upload via the normal file chooser. However, you can directly set the value of the upload control to the absolute path of a file on the system where the driver is running and on form submission that file will be uploaded.
<input type="file" name="csvFile">
$("form").csvFile = "/path/to/my/file.csv"
-- From the link

Related

Upload file using Jenkins Active Choices Reactive References plugin

I am using Jenkins Active Choice plugin. I want to provide a file upload function based on reference variable
The below setting allows me to enter text when i select reference parameter scan_type as vulnerability-Web
What i want is , instead of taking text input it should upload file , and content of the file should be assigned to SELENIUM_RECORDED_FILE
I tried using below groovy
if (scan_type.equals("Vulnerability-Web")) {
inputBox = "<body> <form action='upload.php' method='post' enctype='multipart/form-data'> Select file to upload: <input type='file' name='fileToUpload' id='fileToUpload'> </form>"
return inputBox
}
its adding file upload option but the file content is not stored in SELENIUM_RECORDED_FILE
Please let me know how can we achieve this
Reading through HERE, it looks like you must have
<input type="file" name="file">

Ability to prevent/stop loading 'Page load' in Cypress when clicked a hyperlink

In my Cypress test,
I need to test a link which downloads a .txt, .xlsx and a .zip file when clicked, but when I use "click()" to click the hyperlink, it starts a page load and expects a new action to happen as a result of clicking a link.
As an alternative to this I tried using the cy.downloadFile() to download the files directly through the link but the link I am using is dynamically generated hence I am unable to use that as well. Hence I want to store the newly generated link in the variable and then use it in cy.downloadFile() every time I run the test.
Are there any other ways to test a hyperlink or how to store the dynamically generated link every time the test is run?
Hi there i been through this problem before.
I think it is the same scenario where the cypress test runner just keep waiting page load event and not go to the next test command while file are successfully downloaded.
Add custom cy.window event to listen the click event and add timeout to "force" reload current page, you need to tweak the timeout value so it suitable for your test.
it.only('tes button download', ()=> {
// visit url
cy.visit("/spmb/list_nilaiseleksi");
cy.get('#wrap-button > .btn').click()
//download
cy.window().document().then(function (doc) {
doc.addEventListener('click', () => {
setTimeout(function () { doc.location.reload() }, 5000)
})
cy.get(':nth-child(9) > .col-md-12 > .btn').click()
})
})
More details and discussion available here on cypress github issue :
https://github.com/cypress-io/cypress/issues/14857
I found a way to store the link of the element I want to click. Since I am able to store the link, I am able to solve the requirement by using cy.downloadFile().
cy.get('#selector', {timeout: 15000}).then(($input) => {
cy.downloadFile($input.attr('href'),'cypress/downloads','filename.csv')
});
For me, the problem was resolved after I added the download attribute to the link, This is changing the element in the DOM, but it keeps the solution simple:
cy.get('[href="download?type=php"]')
.then((el) => {
el.attr('download', '');
})
.click();

TCPDF generated PDF to automatically display in Acrobat Reader

I am able to use TCPDF and generate a PDF in the browser using JQuery/JavaScript:
window.open("", "pdfWindow",scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
$("#" + formID).attr('action','tcpdf/example/genReport.pdf').attr('target','pdfWindow');
In genReport.pdf, I am using $pdf->Output('genReport.pdf', 'I');
When genReport.pdf is generated, it appears in a new tab with the standard browser settings. I wanted to know if there is a way to have the generated PDF automatically display in Acrobat Reader?
Any help will be greatly appreciated.
According to the documentation of the output() function, the second parameter can be one of those:
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects
the "Save as" option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local server file with the name given by name.
S: return the document as a string (name is ignored).
FI: equivalent to F + I option
FD: equivalent to F + D option
E: return the document as base64 mime multi-part email attachment (RFC 2045)
So I'd suggest using $pdf->Output('genReport.pdf', 'D'); this will open the download dialog and the user can choose to either open or download the file.

Linking a .doc file on a mvc view page

For something which seems so simple I can't find a solution, I have a word .doc file which I want to be linked on one of my pages so that a user can click on a link and open/download it (whichever is easier) and then read it on the machine with MS word.
Right now I have it in my content folder and tried to display it in both an and but no luck.
Is this an issue of IIS or just I'm going about this all wrong?
Present dir setup:-
Solution>Project>Content>File.doc
Solution>Project>Views>Home>NewRecord.cshtml
File location 1st followed by page I'm trying to display file on.
If I understand your problem correctly that you want to make User to Click and he/she will be promoted to download the .doc then.....
You can achieve with submit button which will be styled with CSS as LINK, then you perform the HTTP GET to the server within HTML form tag, Form will target the action on Server, which will return FileContentResult,
public FileContentResult GetWordDocument(string Id)
{
var contentDisposition = new ContentDisposition
{
FileName = "WordDoc.doc",
Inline = false;
};
FileContentResult documentResult= File(secureDoc.SecuredFileBytes,"application/msword", contentDisposition.FileName);
documentResult.ExecuteResult(this.ControllerContext);
return documentResult;
}
Content-Disposition:What are the differences between "inline" and "attachment"?
http://msdn.microsoft.com/en-us/library/system.web.mvc.filecontentresult(v=vs.108).aspx
Hope this will help to resolve.

Upload document from local machine to server without using file input type

We are trying to upload a document from our local machine to server. We know that .NET browse control can be used for this but our requirement is to just have a button and call that as "Save Document". On click we know the path and also the document name, all we need to do is search the document in local machine (inside temp folder) and if the document is available then pick it and save it to our APP data folder on the server.
it's easy to achieve this using .NET borwse control but not sure how to do that same using normal button?
To find a file in a folder:
FileInfo file = Directory.GetFiles(#"c:\folder")
.FirstOrDefault(f => f.name = whatever);
To copy file:
File.Copy(file.FullName, targetPath, true);

Resources