Archive for July, 2007
How to test a web application
By Justin Silverton
When creating and releasing a web application, testing is a very important step in the overall process. It can determine the success of an application and is many times a very time consuming process. There is an open source application called selenium that can help automate these steps and help reduce the risk of missing anything important while testing.
How it works
Selenium uses JavaScript and Iframes to embed a test automation engine in your browser. This technique should work with any JavaScript-enabled browser. Because different browsers handle JavaScript somewhat differently, we usually have to tweak the engine to support a wide range of browsers on Windows, Mac OS X and Linux. The beauty of this design is that it can also be used to test any web page or script (independent of the the back-end technology used to generate it).
Features
- Easy record and playback
- Intelligent field selection will use IDs, names, or XPath as needed
- Autocomplete for all common Selenium commands
- Walk through tests
- Debug and set breakpoints
- Save tests as HTML, Ruby scripts, or any other format
- Support for Selenium user-extensions.js file
- Option to automatically assert the title of every page
How to test your application
Testing comes in three flavors. The first is a simple GUI interface (either a firefox extension or through a back-end application for Internet Explorer) that allows the direct recording of any action in the browser. Below is a screenshot of this interface.

Test scripts can be created by the following steps:
- Install the Firefox extension
- Go to the website/page that you would like to start testing
- Click the
and go through all of the steps for the test - When you are finished, click the button from step 3 again to finish the test
You will notice some commands listed on the main screen. These are the commands that were recorded from above. These can also be added manually.
Another method for testing is using the selenium core. Selenium Core uses a unique mechanism which allows it to run on so many platforms. Written in pure JavaScript/DHTML, you copy Selenium Core tests directly into your your application webserver, allowing the tests to run in any supported browser on the client-side. It allows you to do the following:
- Browser compatibility testing. Test your application to see if it works correctly on different browsers and operating systems. The same script can run on any Selenium platform.
- System functional testing. Create regression tests to verify application functionality and user acceptance.
The third method for testing is through the Selenium Remote Control. Selenium Remote Control provides a Selenium Server, which can automatically start/stop/control any supported browser.
The Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest). You can send commands directly to the Server using simple HTTP GET/POST requests; that means that you can use any programming language that can make HTTP requests to automate Selenium tests on the browser. Wrapper objects are also included for Java, .NET, Perl, Python, and Ruby.
Download
Selenium can be downloaded for free Here
1 commentA PHP compatible MD5 function in c#
By Justin Silverton
The following is a function written in c# that will return a PHP compatible MD5 hash of a file, given the name. The equivalent function in PHP is md5_file().
public string MD5Hash( string sFilePath )
{
try
{
MD5CryptoServiceProvider md5Provider
= new MD5CryptoServiceProvider();
FileStream fs
= new FileStream(sFilePath, FileMode.Open, FileAccess.Read);
Byte[] hashCode
= md5Provider.ComputeHash(fs);
string ret = "";
foreach (byte a in hashCode)
{
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}
fs.Close();
return ret;
}
catch( Exception ex )
{
throw ex;
}
}
5 ways to extend Firefox tabs
By Justin Silverton
The following are 5 Firefox extensions that will extend tab functionality.
1) IE tabs

This is a great tool for web developers that allows you to view web pages in Internet Explorer within a firefox tab.
Download Here
2) Informational tab

This extension provides thumbnail-style preview for each tab, does progress meter, and indicates unread status.
Download Here
3) Tab Mix Plus

Tab Mix Plus enhances Firefox’s tab browsing capabilities. It includes such features as duplicating tabs, controlling tab focus, tab clicking options, undo closed tabs and windows, plus much more. It also includes a full-featured session manager with crash recovery that can save and restore combinations of opened tabs and windows.
Download Here
4) TabSidebar
Features:
- Provides navigation options for each tab including history, stop and reload.
- Allows you to move tabs around with drag and drop.
- You can drop links, local files and bookmarks anywhere you like in the tab list.
- Displays the security status of tabs.
- Automatically refreshes the tab preview whenever the page changes.
- Lets you hide the main tab bar when the sidebar is open.
- Bidirectional support making the sidebar work correctly in right-to-left languages.
- Works well with other tab-related extensions allowing you to use their context menu additions from the sidebar.
Download Here
5) Tab Effect

This adds a tab switching cube effect to Firefox.
Download Here
1 commentHow to create a zip archive using PHP
by Justin Silverton
The following is a library that allows you to generate zip file archives using php.
<?php
include("ziplib.php");
$zipfile = new Ziplib;
$zipfile->zl_add_file("This is a test file","path/to/file","g9");
//You can stream the ZIP file or write it in a file on your server
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"testfile.zip\"");
echo $zipfile->zl_pack("zip file comments");
?>
This script will dynamically create a zip archive using the files specified with zl_add_file and output it to the browser (the final zip file will be named: testfile.zip).
Options
zl_add_file allows you to specify the compression level of the file file that will be added to the archive.
- n (none)
- b (bzip)
- g (gzip)
Download
The php zip library can be downloaded Here
11 commentsHow to create Microsoft Office Documents with PHP
By Justin Silverton
There are two main ways to build Excel, Word, and PowerPoint documents using PHP. The first is by using the COM library (only if you are using a Windows server) and the other is by using a more standardized approach such as HTML or CSV.
Dynamically creating a word document:
<?php
$word = new COM("word.application");
$word->Visible = 0;
$word->Documents->Add();
$word->Selection->PageSetup->LeftMargin = '2"';
$word->Selection->PageSetup->RightMargin = '2"';
//Setup the font
$word->Selection->Font->Name = 'Verdana';
$word->Selection->Font->Size = 8;
//Write some text
$word->Selection->TypeText("This is a test document");
//Save the document as DOC file
$word->Documents[1]->SaveAs("c:\\docs\\test1.doc");
//quit and release COM resources
$word->quit();
$word->Release();
$word = null;
?>
Dynamically creating an excel document
<?php
$excel = new COM("excel.application");
$excel->Visible = 0;
//Create a new workbook
$wkb = $excel->Workbooks->Add();
$sheet = $wkb->Worksheets(1);
//This code adds the text 'myvalue' on row 2, column 4
$sheet->activate;
$cell = $sheet->Cells(2,4);
$cell->Activate;
$cell->value = 'myvalue';
$wkb->SaveAs("C:\docs\test.xls");
//close and free resources
$wkb->Close(false);
$excel->Workbooks->Close();
$excel->Quit();
?>
Dynamically creating a powerpoint presentation
<?php
$powerpnt = new COM("powerpoint.application");
//Creating a new presentation
$pres=$powerpnt->Presentations->Add();
//Adds the first slide. "12" means blank slide
$pres->Slides->Add(1,12);
//Adds another slide. "10" means a slide with a clipart and text
$pres->Slides->Add(2,10);
//Adds a textbox
$pres->Slides[1]->Shapes->AddTextbox(1,20,50,300,40);
//Save the document as PPT file
$powerpnt->Presentations[1]->SaveAs("C:\Docs\test1.ppt");
//free resources and quit powerpoint
$powerpnt->quit();
?>
How to find Word, Excel, and Powerpoint functions
The following will show you all of the functions that are possible when accessing Microsoft Office components through php:

- Open Microsoft Word, Excel, or Powerpoint
- Press Alt+F11 to start the Visual Basic Editor
- Press F2
- Find “ThisDocument” on the left. In the right frame you’ll see the available variables and functions that can be used with the COM object.





