HtmlUnit – A quick introduction

HtmlUnit is an open source java library for creating HTTP calls which imitate the browser functionality. HtmlUnit is mostly used for integration testing upon Unit test frameworks such as JUnit or TestNG. This is done by requesting web pages and asserting the results. Simple Example WebClient As you can see in the example, the WebClient is the starting point. It is the browser simulator. WebClient.getPage() is just like typing an address in the browser. It returns an HtmlPage object. HtmlPage HtmlPage represents a single web page along with all of it’s client’s data (HTML, JavaScript, CSS …). The HtmlPage lets you access to many of a web page content: Page source You can receive the page source as text or as XML. HTML Elements HtmlPage lets you ability to access any of the page HTML elements and all of their attributes and sub elements. This includes tables, images, input fields, divs or any other Html element you may imagine. Use the function getHtmlElementById() to get any of the page elements. Anchors Anchor is the representation of the Html tag <a href=”…” >link</a>. Use the functions getAnchorByName(), getAnchorByHref() and getAnchorByText() to easily access any of the anchors in the page. Dom Continue reading HtmlUnit – A quick introduction

Android – Opening a new screen

  Opening a new screen is fairly easy in android. This post will show you almost all you need to know about switching back and forth between screens in your Android application. Add all activities to manifest Each screen is usually an Activity. Each activity should be mentioned in the manifest file. The simple use Bear in mind that every time you will call the function startActivity(intent) a new instance of MyActivity2 will be created. Passing a parameter In most times you need to pass a parameter to the new screen. You do that by using the function putExtra(). This function Receiving a parameter And of course you will need to receive that parameter on the other side. Going back If you need to go back to the previous screen and terminate the current screen, than all you have to do is to use the function finish() from anywhere in the new Activity. Open for result When you need to open a new screen and get result back from it, than use the function startActivityForResult() instead of startActivity() Returning a result Getting the result from the new activity

Which client will dominate?

I first got into the magical world of the internet in the happy 90’s. Back then you could find 3 basic types of network application clients: Internet lightweight web sites (HTML, JS), installed applications with network connection like ICQ or Applets. The years went by, the internet connection got faster and richer applications came out of the desktop and into the browser. The web applications clients became fatter. Even if the desktop applications still exist, they have clearly become a lot less common. That was about the time I started developing in java. The obvious solution for many of these fat clients were the java web frameworks like Struts, JSF and all the others. But as the years went by a new approach became more and more popular – the Ajax web applications, with GMail in the lead. Fat clients never looked better and the usability was excellent. It is almost as if we are using desktop applications (!?!). JavaScript was never so cool. Libraries like JQuery are born every day as well as some new solutions like GWT to make our life with JavaScript easier. But the story doesn’t end here. With the birth of the smart cellphones an Continue reading Which client will dominate?

Batch Image Resizer

I wrote this application so I could resize a batch of photos all at once. The use is very simple. You insert the input image folder and the out put folder. You enter the resizing percentage you wish and press the button. I have implemented this using my own EasyImage for the picture resizing. I have used Apache Pivot for the GUI. And that is it, very easy. View on Github  Download BatchImageResizer  Download Source code from Github