How to get form values in browser to watir webdriver - ruby-on-rails

I have installed my application and it is running on following URL
http://localhost:3000
Above URL will the load form with some fields, Then I will the fill the data in the required field and then submit form. My div element will displayed at the bottom of the page. Picture will be displayed inside the iframe with in the div element.
User will the above URL and then submit form. After submitting the form, Picture should be downloaded into their local machine.
Right I am calling the following line after form submission, how can I get the existing page into the browser object and download screenshot?
browser = Watir::Browser.new
b.div(:id => "phone_shell").screenshot("/home/user/Documents/preview.png")

I found few problems in your code
screenshot method is not available for element object, it's available for browser object and also you need to call the method save to save the file in the destination folder. So write the following code, it would work.
Code to get the html of the page
b.html
Code to take the screenshot
b.screenshot.save("/home/user/Documents/preview.png")
Now this will save the image in the destination folder.

Related

GlassMapper Link not rendered when %20 in subject

I have an interesting situation where I am trying to render a link which could be a URL to a site or a mailTo tag.
The issue is that when I put any spaces in the subject field these get converted into %20's when I save the link then the link doesn't get pulled into the rendering at all (it just returns null in the view).
Interestingly if I manually remove the %20's after I save the link (this can be done in the page editor) the link comes through fine!
Now if I save and publish the link returns null but if I manually edit and remove the %20 GlassMapper grabs the link fine.
Any ideas why GlassMapper wont get the link when there is %20's in there?

Navigating back after a non-turbolinks request displays raw JSON on chrome

The case (Chrome only)
I open my webapp
Navigate to another page (turbolinks)
Navigate to
another page (no-turbolinks, e.g. form submittion)
Hit 'Back'
Instead of showing the previous route's HTML, i see a raw JSON. Note that this route, along with others, are configured to respond to both HTML and JSON.
I added the following Javascript to my app and that solved it:
Turbolinks.pagesCached(0)
$.ajaxSetup({cache: false})

Rails scraping - submitting a form

I am filling in a form on a page and submitting it.
This should trigger the download of a file.
However, when I try to save the output of the download, I get the source code of the page rather than the file.
My code is:
mechanize = Mechanize.new
mechanize.pluggable_parser.default = Mechanize::Download
page = mechanize.get('http://page.com/')
form = page.forms.first
form.radiobuttons_with(name: 'presence')[0].check
form.source = "btce"
form.label = "BTC/USD"
mechanize.get_file(form.submit).save!('page.csv')
How can I save a file which is downloaded when I submit a form?
Does the file automatically begin downloading once you submit the form?
Submitting a form may return a new page, also new scripts/stylesheets can be loaded. Which possibly explains why your file contains the source code since that's what you're downloading. (Mechanize doesn't throw an error if you download a web page)
For example, I use Mechanize to fill out Google's search form and submit it and save the results to google_search.csv. The new file contains a mixture of the page's source code along with javascript, mySQL, and its stylesheets.
You can dig through the page's source code using Firebug and pinpoint what exactly happens when you submit the form, which can likely be a link that's invoked but you were unaware of.

How to Display stored image in html in database into view with razor engine

I have a section that saves html created with an html editor into a database in the site control panel.
in my html if I insert image with this address "image/Picture1.jpg" using the html editor if there is a image stored at mysite.com/image/picture1.jpg.
Now in a view(razor) I display the stored html content from the database with System.Web.HttpUtility.HtmlDecode or #Html.Raw(item.Content). if this content is shown the in home page like mysite.com it works correctly.
but, if it show it in other area or controller or action the image doesn't show. Because in those areas (like mysite.com/desktop) the image address changes to mysite.com/desktop/image/picture1.jpg.
How do I display this html content without this problem?
The images will always be relative to the page that displays them as you are using a relative URL.
Unless they have an absolute URL mysite.com/image/picture1.jpg or a root-relative URL /image/picture1.jpg in the HTML it will not work.
A: You need to enter the URL in the HTML editor as either absolute
mysite.com/image/picture1.jpg
or root-relative:
/image/picture1.jpg
In both cases the browser will search from root of the website, and not just relative to the current page.

How do I return MVC File ActionResult of PDF over jQuery modal dialog

Note: I am not wanting to display the PDF inline with the modal. Rather, I am looking to have the browser acknowledge the file and allow the user to save or open it.
I have a jQueryUI modal dialog in MVC 4. The dialog IS modal. The content of the dialog is from a Partial Views which works fine. I have only one button on the dialog itself and have successfully gotten all the JavaScript to deal with client side data entry checking.
What is giving me a headache is that I have one button embedded in the Partial View that is to display a PDF file. I can successfully call a JavaScript function that calls the controller that gets the file from another server. I can even get the file converted to a byte array and the last line is
return File(contents, "application/pdf", "PropsedChanges.pdf");
However it will not open as I suspect that the modal dialog is preventing it.
I have done something similar outside of the model dialog and it gives me the save/open option at the bottom of the screen for IE or in the correct manner in other browsers.
Is there a way to display the PDF in a registered PDF viewer on the client's PC/Device outside of the browser needing to ask if they want to save or open it? Which, as I suspect, is not happening due to the modal dialog.
Help is greatly appreciated.
public ActionResult GetPdf(Model modelo)
{
return File(Pdf bytes[], "application/pdf");
}
Try using a new window to open your PDF. Like target="_new" or "blank".
If you are using Asp.net 5, install MvcPdfActionResult via nuget
PM> Install-Package MvcPdfActionResult
Simply use return type as PdfActionResult in the controller will output PDF document instead of HTML. This converts HTML to PDF using the iTextXmlWorker Library.
...
return PdfActionResult(model);
}
Generates pdf documents from your razor views within an asp.net 5 MVC project. https://www.nuget.org/packages/MvcPdfActionResult/

Resources