SWT Browser - Detect Ajax Calls - java

I'm using SWT.Browser (java) and am wondering if there's a way to get a listener that hears when ajax requests are made, received, etc.
Is there a way to intercept them and manipulate them before they come in, etc?

No, there is no publicly available API for that.
However, you can write APP plugin for SWT, though it is applicable to IE only. Or for Firefox or Webkit or IE you can write a local proxy like fiddler.

Related

Java - Go to new url in new window/tab

I want to be able to use Java to tell it to go to X url when X browser is open/running (my lingo is terrible). (Firefox/Chrome/IE is already up, and I want it to go from the default page to let's say Twitter.)
Most of the solutions are using java.awt.Desktop to launch native browser with a url in it, but that isn't useful if I want to change the url later on. (Already on Twitter-Home Page, but want to go to Twitter-Contact Us afterwards.)
The other solutions I've seen involve using Selenium WebDriver, but I also need to eventually learn how to basically force the Java to read a long list of URLs off an excel and simply verify that url isn't dead, and then do this on the Native Android browser, for example. So the Selenium might not be the right choice. Granted, you can also tell me this is an awesome choice for this too if it truly is. I haven't really been exploring Selenium.
Sorry for asking such a basic question. Company wants QA Automation without training/hiring an Automation QA. My end goal (aside not getting canned), is to see if I can get a bunch of urls to load on specific browsers. I can sort of (praying) be able to do stuff with it afterwards.
A simple trick would be to create an add-on( if you know javascript ) which will be quite similar in chrome and firefox (for IE I have no idea in my days it needed BHO) and send websocket commands from java to your addon. But this needs a java websocket server running where your addon will connect when the browser opens. Rest of communication can be carried upon the protocol lines of your requirements.
There are multiple parts to your question.
Read urls from excel.
Use Apache POI to do the same. Selenium code can use the same.
Check that the urls are not dead.
Use any java http client, (apache) to do that without even opening a browser. If the link is dead, it will be dead for all the browser.
Open the links in a multiple browsers.
Selenium is perfect for this. I am assuming that after the page is loaded you have way of validating that the page is correct. Selenium is very powerful here.
Target native android browser too.
I do not know of much difference between this and the previous question unless you are also testing site display based on browser size. The browser is more or less the same as chrome with webkit rendering engine.

Launch IE browser in JAVA and using POST method

We have a Java awt desktop application on Windows machine. We have provided a button with hyperlink to third party web based application .
Click on button should do following :
Launch new instance of Internet Explorer on the machine.
Open the URL of third party application in IE
Submit few parameters and their values using http "POST" method in IE.
It will open the application in Browser and user will work in new Window with no further interaction with Java application.
We are able to achieve this using java.awt.Desktop.browser in "GET" method . But due to security restrictions we are not supposed to pass these parameters using GET method as they are visible in URL.
I have received some suggestions to do this by using intermediate vbscript but can it be achieved within Java .
Unfortunatelly I cannot help you with invoking IE with POST and to be honnest not sure if it is even possible via vbscript. But if you have some vbscript capable of doing such thing, you can allways invoke it from java see commons-exec library. By platform invoke you can also invoke any platform special stuff - see JNA in https://github.com/java-native-access/jna
But maybe another approach - why not use encryption and hmac verification of your parameters ? When you carefully use them, you can use GET also.

What is the difference between automating using http requests vs selenium webdriver?

I am a bot developer in selenium webdriver Java and I'm using a browser HtmlunitDriver headless but it's complicated when I have to deal with javascript, so, which is better when I have to automate page? Sending HTTP get and post requests or continue using webdriver?
I'm confused because, for example, how can I click a button and wait for a page to load (example: when I open a page like Ad.fly) and I have to wait 5 seconds until the button is ready sending http request, this is what I am confused by, thanks a lot for your answers!!
Use HTTP requests if you just want to make calls (i.e. to REST services). Use selenium (or other web automation tools) if you need to simulate browser behaviour (i.e. run javascript in the page).
HTTP is generally preferable if you have the option - services are more stable than page structure (particularly if there's a published interface) and are more oftened designed to be machine-readable. Web pages are designed for humans using web browsers, so they can change frequently, and adds a lot of overhead which doesn't make sense in a machine interface.
So, I'd suggest - look through the sequence of user actions you're trying to automate. If you can express those as a simple sequence of HTTP requests, I'd do it that way. If you need to run client-side javascript, or use other browser functionality, use selenium.

Triggering a web page print from server side

This question might be very basic.
Till now I thought a command to print a webpage can only be initiated at the client side.
(window.print when using javascript)
But I came across http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/ which states about printing using Java. I think this seems to be related to some desktop client and the same may not be possible in a web client. Can anyone confirm and explain this?
You can't execute server side code on the client, so the only way to do it in browser is through javascript or using plugins/flash/java applets.
You could print using java, but for that java needs to run on the client.
A website can ask the browser to open its print dialog (Google Maps does this on the "print directions" page, for example), but it can't actually force the browser to print anything. (If it could, you can be sure that advertisers would use it to print ads on your printer.)
A Java application running locally with sufficient permissions can print, just like any other desktop application. That has nothing to do with web pages.
Don't confuse Java and JavaScript. When trying to use Java within a browser, you'd have to look into using applets. A Java applet could definitely be used to do the kind of work you'd normally have a rich client do from within a browser.
Java applets could also receive events sent out from a server via sockets or some other mechanism, although I'm not certain if security constraints would allow it. Also seems a bit of a roundabout way to do things.
Remember that web browsing is a client-side-driven affair. There's some push models in certain infrastructures (I believe it's possible using JavaServer Faces). But those are probably just a sort of polling mechanism initiated by the client that is abstracted away to look like a server-side push.

Java and Silverlight together forever

I want to display a silverlight web page inside my java desktop application.
Does anyone know of a plugin or browser control that I can use to do this?
Embed an appropriate browser window into the Java app and it can load the SL - there will not be any interaction / communication between the two without some hacky code. Multiple browsers support SL but you are better off using the an IE based one at present, the chrome support is not official as I remember.
How about an iFrame? In the nutshell... Alternatively you can make a request to .Net app from within your java server code using something like HttpClient and then serve markup that way - would be relatively easy thing to do (relatively since if there authentication involved things can get complicated fast. And if you want (willing) to get "sophisticated" and you are using portlet technology there is WSRP
For the desktop app I would go with HttpClient suggestion: get the content, parse it then do with it what you please unless that Silverlite app is also running as webservice then you have some additional options by utilizing components that can consume services
Eclipse's SWT provides out of the box web browser component based on IE and/or Mozilla engine. For swing application you can use one of ActiveX bridges, such as J-Integra or JDIC or EZ JCOM.
Use JDIC WebBrowser component

Categories

Resources