Is it required that I use forge.request.ajax in stead of $.post? - trigger.io

First , I am not trying to do a cross site request.
I have created a small JS app and I can test in in a browser and it works fine i.
I see that my request from the app makes it to my server and I can confirm that my server responds with the data I expect. The problem is that the compiled app triggers the .fail in my javascript.
Is is REQUIRED that I use forge.request.ajax. instead of $.post? I see many posts saying I should but no one says I cannot use $.post .It makes debugging and development much easier being able to test all my JS in a browser before making the package.

Unfortunately I haven't found a way around it. You can use a promise, create a wrapper function/service, detect the platform that you are running on and call the corresponding function.

Related

How to handle the request in the electron app (capture request, serve custom response)

I want to handle any API requests from the web app wrapped in the electron app. My intention was to keep the same API calls that web app delivered over the net will stay the same as when delivered as standalone electron app. In the latter I would capture API requests and serve responses created locally. Is it possible? I'm looking into WebRequest callbacks available through session.defaultSession.webRequest e.g. session.defaultSession.webRequest.onResponseStarted
Edit 02/01/2020
I've found also to use the ProtocolAPI but then I would have to modify my API calls which I want to intercept to use custom protocol when within electron wrapper which is not what I want (intercept request and serve custom response on electron).
Your web app will work 100%(*) the same in Electron as it does without. The (*) is the caveat that throwing the production flag on your web app may come with other side effects, and that may confuse things.
Just because Electron comes with its own native way to handle certain things, doesn't mean Electron will prevent you from doing things the way you've been doing thus far.
For example I'm doing all my client-server action via JQuery's .ajax() method and Sails.js's MVC action handlers. Electron hasn't interfered at all.
However, if you want Electron to interfere, you can do that. See the WebRequest part of the Electron API. In particular the first method on the page, onBeforeRequest, seems relevant to the requirement mentioned in your comment.

Mock API Requests Xcode 7 Swift Automated UI Testing

Is there a way to mock requests when writing automated UI tests in Swift 2.0. As far as I am aware the UI tests should be independent of other functionality. Is there a way to mock the response from server requests in order to test the behaviour of the UI dependant on the response. For example, if the server is down, the UI tests should still run. Quick example, for login, mock if password failed then UI should show alert, however, if the login is successful the next page should be shown.
In its current implementation, this is not directly possible with UI Testing. The only interface the framework has directly to the code is through it's launch arguments/environment.
You can have the app look for a specific key or value in this context and switch up some functionality. For example, if the MOCK_REQUESTS key is set, inject a MockableHTTPClient instead of the real HTTPClient in your networking layer. I wrote about setting the parameters and NSHipster has an article on how to read them.
While not ideal, it is technically possible to accomplish what you are looking for with some legwork.
Here's a tutorial on stubbing network data for UI Testing I put together. It walks you through all of the steps you need to get this up and running.
If you are worried about the idea of mocks making it into a production environment for any reason, you can consider using a 3rd party solution like Charles Proxy.
Using the map local tool you can route calls from a specific endpoint to a local file on your machine. You can past plain text in your local file containing the response you want it to return. Per your example:
Your login hits endpoint yoursite.com/login
in Charles you using the map local tool you can route the calls hitting that endpoint to a file saved on your computer i.e mappedlocal.txt
mappedlocal.txt contains the following text
HTTP/1.1 404 Failed
When Charles is running and you hit this endpoint your response will come back with a 404 error.
You can also use another option in Charles called "map remote" and build an entire mock server which can handle calls and responses as you wish. This may not be exactly what you are looking for, but its an option that may help others, and its one I use myself.

VS2013 RTM making once per second Signal R requests when I check with fiddler

When I check with Fiddler I see my new install of VS2013 is giving Continuous Signal R requests. I don't use anything to do with this in my application. How can I stop these requests which I assume are part of VS2013 trying to sync up something?
It's probably due to the BrowserLink feature mentioned here. BrowserLink uses SignalR to communicate between VS and your browsers.
Maybe log out of VisualStudio? It might also help if you tell us where VS is communicating to...
There seem to be two additional calls made by the browser-link:
a one off call made on a page render, on the same port as the site exchanging information about the mapping between Razor views and the elements. This call has __browserlink at the start of the URL.
a periodic call as part of the SignalR synchronisation. This has SignalR about 30 characters into the URL.
The former, a single call, I can live with. The other fills up my capture history.
To avoid this, in fiddler I've used the 'Hide the following Hosts' option in the Filter Tab and put something like localhost:62533 in the text box. Note that port number seems to change with each restart of VS2013.
As long as the 'Use Filters' is checked, I still see the traffic I want to (plus a one-off call for __browserlink).

Capture outgoing HTTP request from Controller / Service

So I have the following scenario (it's a Grails 2.1 app):
I have a Controller that can be accessed via //localhost:8080/myController
This controller in turn executes a call to another URL opening a connection using new URL("https://my.other.url").openConnection()
I want to capture the request so I can log the information
I have a Filter present in my web.xml already which does the job well for controllers mapped in my app. But as soon as a request is fired to an external URL, I don't get anything.
I understand that my filter will only be invoked to URLs inside my app, and that depends on my filter mapping which is fine.
I'm struggling to see how a solution inside the app is actually viable. I'm thinking of using a mixed approach with the DevOps team to capture such outgoing calls from the container and then log them into a separate file.
I guess my questions are:
Is there a way to do it inside the app itself?
Is the approach I'm planning a sensible one?
Cheers!
Any reason why you don't want to use http-builder? There a Grails plugin for it, and it makes remote XML calls much easier than handling the plumbing yourself. At the bottom of the linked page they describe how you can enable request logging via log4j configuration.

With firebug stop loading so can see requests

I am trying to analyze a POST request using firebug. Using the net panel I can see the request, however when the POST has success the page then reloads and I only have a couple of seconds to actually look at the request and see what is going on. Is there a way I can pause it much like when analyzing scripts using this tool?
There is a "Persist" button on some of the tabs in Firebug. Just make sure to click it before doing your post.
[edit] Second row, third button from the left, on the Console and Net tabs.
Even better, if you're on Windows you can use Fiddler - an amazing and free HTTP debugger developed by some important guy on the Microsoft IE team.
With it you can conditionally intercept GET or POST requests, inspect and change parameters, break on responses, change responses (headers or body), reissue old requests and generally screw with your application during development.
Simply one of the most useful web development tools. Ever.
May require a little tweaking for localhost - see here
One solution would be to remove the refresh of the page from your code.
Then run your code to see the results.
You can use web developer tools plugin for Mozilla firefox, and disable meta redirects

Resources