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 Development – Preferences

  If you have ever developed an application for mobile, most chances are you have found yourself wanting to create a settings page. The user uses the settings page to set configuration parameters and these parameters are saved even after the program is closed. In this post I will explain how to create a settings page very easily. All code examples are available to download at the bottom. Android designers have developed a framework to make the developers life a lot easier. Preference Framework is a framework composed of a hierarchy of preference objects which are translated to UI objects. This mechanism is built on top of the shared preferences mechanism which stores the values. Shared Preferences Mechanism Before we can explain how to build a settings page with the preferences framework we need to get to know the shared preferences mechanism. Shared Preferences is a simple key-value storage mechanism of primitive types and Strings. These values are stored even if the program is terminated. Use it to store simple variables you wish to save between sessions of the program. Preferences Framework As mentioned, the preference framework is a framework which is built on top of the shared preferences mechanism. Continue reading Android Development – Preferences