Wednesday, March 28, 2012

How to open a URL in the default browser

Tuesday, August 19, 2008 | 3 comments

If you ever wondered if there is an easy way to open a URL from your Java program in the user-default browser, with Java SE 6 there is. Unless your platform doesn't support this. The good news is that you can test if this is the case or not.

In Java SE 6 a new class has been added to the java.awt package: Desktop. This class has a public class method isDesktopSupported() which returns true if the class is supported on the current platform, and false otherwise.

If the class is supported, you can retrieve an instance using the class method getDesktop().

You can use the browse() method to display a URI in the default browser. If this browser is not able to handle the specified URI, the application registered for handling the URIs of the specified type is invoked. For example, the URI news:comp.lang.perl.misc might invoke a Usenet client.

However, before you call the browse() method make sure to check if this action is supported on the current platform by calling the isSupported()method with java.awt.Desktop.Action.BROWSE as the value of the first and only parameter.

Note that even though this method returns true, it's still possible that the platform doesn't support the URI - for example if there is no application registered for the given scheme. In this case the browse() method will throw an IOException.

Example Java program using the browse method

Below follows a small example program that can be invoked from the command line. It attempts to open each argument as a URI in the user-default browser, or if the browser can't handle the URI, an attempt is made to pass the URI to the application registered for the URI's scheme.

import java.net.URI; import java.awt.Desktop;  public class OpenURI {      public static void main(String [] args) {          if( !java.awt.Desktop.isDesktopSupported() ) {              System.err.println( "Desktop is not supported (fatal)" );             System.exit( 1 );         }          if ( args.length == 0 ) {              System.out.println( "Usage: OpenURI [URI [URI ... ]]" );             System.exit( 0 );         }          java.awt.Desktop desktop = java.awt.Desktop.getDesktop();          if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {              System.err.println( "Desktop doesn't support the browse action (fatal)" );             System.exit( 1 );         }          for ( String arg : args ) {              try {                  java.net.URI uri = new java.net.URI( arg );                 desktop.browse( uri );             }             catch ( Exception e ) {                  System.err.println( e.getMessage() );             }         }     } }

But there are more actions

Besides the browse() method there are 5 more methods, providing support for the 4 following Desktop actions:

EDIT
The edit() method launches the associated editor application and opens a file for editing.
MAIL
There are two mail() methods. The first one doesn't take any parameters and launches the mail composing window of the user-default mail client. The second method takes a single parameter: a "mailto" URI. It also launces the mail composing window of the user-default mail client, but additionally fills in the message fields specified by the "mailto" URI (for example, to, subject, etc.).
OPEN
The open() method launches the associated application to open the file. If the specified file is a directory, the file manager of the current platform is launched to open it.
PRINT
Prints a file with the native desktop printing facility, using the associated application's print command.

Java 1.6 Desktop class related

Using the Desktop API in Java SE 6

By John O'Conner, February 2006

With the default graphical user interface (GUI) look and feel, printing, and performance, the Java platform has come a long way in its effort to minimize the difference between the performance and integration of native applications and Java applications. Version 6 of the Java Platform, Standard Edition (Java SE), continues to narrow the gap with new system tray functionality, better print support for JTable, and now the Desktop API (java.awt.Desktop API). This article describes the new Desktop API, which allows Java applications to interact with the default applications associated with specific file types on the host platform. In order to describe the API more effectively, the article also features a simple application called DesktopDemo.

Desktop Overview

This new functionality is provided by the java.awt.Desktop class. The API is adopted from the JDesktop Integration Components (JDIC) project. The goal of that project is to make "Java technology-based applications first-class citizens" of the desktop, enabling seamless integration. Specifically, the new Desktop API allows your Java applications to do the following:

  • Launch the host system's default browser with a specific Uniform Resource Identifier (URI)
  • Launch the host system's default email client
  • Launch applications to open, edit, or print files associated with those applications

The Desktop API uses your host operating system's file associations to launch applications associated with specific file types. For example, if OpenDocument text (.odt) file extensions are associated with the OpenOffice Writer application, your Java application could launch OpenOffice Writer to open, edit, or even print files with that association. Depending on your host system, different applications may be associated with each different action.

Running the DesktopDemo Application

DesktopDemo is a simple Java application that uses the new Desktop API. The application has one main window that exposes the entire API, allowing you to do three things:

  1. Launch the default browser with a specific URI.
  2. Launch the default email client with a mail recipient.
  3. Launch an associated application to open, edit, or print a file.

Figure 1 shows the user interface (UI).

Figure 1: DesktopDemo UI
Figure 1: DesktopDemo UI

You can run this application by downloading the application source and JAR files, changing your console's active directory to the application project's dist directory, and executing the following command using a JDK 6:

    java -jar DesktopDemo.jar 

Determining Desktop API Support

Before launching the browser, email client, or any application, DesktopDemo must determine whether your platform supports the API. First, however, DesktopDemo disables all the graphical text fields and buttons. It enables these graphical components after determining that the platform supports them.

After instantiating the UI, the application's constructor quickly disables the few components of this application as shown in the following code:

    public DesktopDemo() {         // Initiate all GUI components.         initComponents();         // Disable buttons that launch browser and email client.          // Disable buttons that open, edit, and print files.         disableActions();         ...     }      /**      * Disable all graphical components until we know      * whether their functionality is supported.      */     private void disableActions() {         txtBrowserURI.setEnabled(false);         btnLaunchBrowser.setEnabled(false);                  txtMailTo.setEnabled(false);         btnLaunchEmail.setEnabled(false);                  rbEdit.setEnabled(false);         rbOpen.setEnabled(false);         rbPrint.setEnabled(false);          txtFile.setEnabled(false);         btnLaunchApplication.setEnabled(false);             }          ...      public javax.swing.JTextField txtBrowserURI;     public javax.swing.JButton btnLaunchBrowser;     public javax.swing.JTextField txtMailTo;     public javax.swing.JButton btnLaunchEmail;     public javax.swing.JRadioButton rbEdit;     public javax.swing.JRadioButton rbOpen;     public javax.swing.JRadioButton rbPrint;     public javax.swing.JTextField txtFile;     public javax.swing.JButton btnLaunchApplication; 

Use the Desktop.isDesktopSupported() method to determine whether the Desktop API is available. On the Solaris Operating System and the Linux platform, this API is dependent on Gnome libraries. If those libraries are unavailable, this method will returnfalse. After determining that the API is supported, that is, the isDesktopSupported() returns true, the application can retrieve a Desktop instance using the static method getDesktop().

    Desktop desktop = null;     // Before more Desktop API is used, first check      // whether the API is supported by this particular      // virtual machine (VM) on this particular host.     if (Desktop.isDesktopSupported()) {         desktop = Desktop.getDesktop();         ... 

If your application doesn't check for API support using isDesktopSupported() before calling getDesktop(), it must be prepared to catch an UnsupportedOperationException, which is thrown when your application requests a Desktop instance on a platform that does not support these features. Additionally, if your application runs in an environment without a keyboard, mouse, or monitor (a "headless" environment), the getDesktop() method will throw a java.awt.HeadlessException.

Once retrieved, the Desktop instance allows your application to browse, mail, open, edit, or even print a file or URI, but only if the retrieved Desktop instance supports these activities. Each of these activities is called an action, and each is represented as aDesktop.Action enumeration instance:

  • BROWSE. Represents a browse action performed by the host's default browser
  • MAIL. Represents a mail action performed by the host's default email client
  • OPEN. Represents an open action performed by an application associated with opening a specific file type
  • EDIT. Represents an edit action performed by an application associated with editing a specific file type
  • PRINT. Represents a print action performed by an application associated with printing a specific file type

Before invoking any of these actions, an application should determine whether the Desktop instance supports them. This is different from determining whether a Desktop instance is available. The Desktop.isDesktopSupported() method tells you whether an instance can be created. Once a Desktop object is acquired, you can query the object to find out which specific actions are supported. If the Desktop object does not support specific actions, or if the Desktop API itself is unsupported, DesktopDemo simply keeps the affected graphical components disabled. As Figure 2 indicates, the components cannot be used to invoke Desktop features in the disabled state.

Figure 2: Graphical components are disabled when the desktop is unsupported.
Figure 2: Graphical components are disabled when the desktop is unsupported.

Using a new Desktop instance, the following code checks each Desktop.Action for support and enables the appropriate graphical components:

    public DesktopDemo() {         ...          // Before more Desktop API is used, first check          // whether the API is supported by this particular          // VM on this particular host.         if (Desktop.isDesktopSupported()) {             desktop = Desktop.getDesktop();             // Now enable buttons for actions that are supported.             enableSupportedActions();         }                 ...     }      /**      * Enable actions that are supported on this host.      * The actions are the following: open browser,       * open email client, and open, edit, and print      * files using their associated application.      */     private void enableSupportedActions() {         if (desktop.isSupported(Desktop.Action.BROWSE)) {             txtBrowserURI.setEnabled(true);             btnLaunchBrowser.setEnabled(true);         }                  if (desktop.isSupported(Desktop.Action.MAIL)) {             txtMailTo.setEnabled(true);             btnLaunchEmail.setEnabled(true);         }          if (desktop.isSupported(Desktop.Action.OPEN)) {             rbOpen.setEnabled(true);         }         if (desktop.isSupported(Desktop.Action.EDIT)) {             rbEdit.setEnabled(true);         }         if (desktop.isSupported(Desktop.Action.PRINT)) {             rbPrint.setEnabled(true);         }                  if (rbEdit.isEnabled() || rbOpen.isEnabled() || rbPrint.isEnabled()) {             txtFile.setEnabled(true);             btnLaunchApplication.setEnabled(true);         }     } 

Once the application determines the supported actions, it enables the appropriate graphical components. If all components are enabled, the UI should look like Figure 3.

Figure 3: Components are enabled when the Desktop API is supported.
Figure 3: Components are enabled when the Desktop API is supported.

Opening the Browser

Calling the following instance method will open your host's default browser:

    public void browse(URI uri) throws IOException 

Because DesktopDemo's UI components are enabled only if the associated Desktop.Action is supported, this simple demo application doesn't need to check support again before actually calling the browse() method. However, checking action support before each invocation may be more robust in real-world applications:

    if (desktop.isSupported(Desktop.Action.BROWSE)) {         // launch browser         ...     } 

DesktopDemo adds a java.awt.event.ActionListener to each button. When enabled, the Launch Browser button invokes the following method through its ActionListener:

    private void onLaunchBrowser(java.awt.event.ActionEvent evt) {         URI uri = null;         try {             uri = new URI(txtBrowserURI.getText());             desktop.browse(uri);         }         catch(IOException ioe) {             ioe.printStackTrace();         }         catch(URISyntaxException use) {             use.printStackTrace();          }         ...     } 

The browse() method can throw a variety of exceptions, including a NullPointerException if the URI is null, anUnsupportedOperationException if the BROWSE action is unsupported, an IOException if the default browser or application can't be found or launched, and a SecurityException if a security manager denies the invocation.

If all goes well, however, the listener retrieves the text from the associated text field in Figure 4, creates a URI, and invokes thebrowse() method. The code above launches the default browser on your system and instructs the browser to load the URI, as Figure 5 shows.

Figure 4: Launch the default browser with a specific URI.
Figure 4: Launch the default browser with a specific URI.

Figure 5: The default browser launches using the Desktop API.
Figure 5: The default browser launches using the Desktop API.

Sending Email

Applications can launch the host's default email client, if that action is supported, by calling this Desktop instance method:

    public void mail(URI uri) throws IOException 

DesktopDemo has an ActionListener for the Launch Mail button. In this case, the listener invokes the following method:

    private void onLaunchMail(java.awt.event.ActionEvent evt) {         String mailTo = txtMailTo.getText();         URI uriMailTo = null;         try {             if (mailTo.length() > 0) {                 uriMailTo = new URI("mailto", mailTo, null);                 desktop.mail(uriMailTo);             } else {                 desktop.mail();             }         }         catch(IOException ioe) {             ioe.printStackTrace();         }         catch(URISyntaxException use) {             use.printStackTrace();         }         ...     } 

The onLaunchMail() method retrieves the email recipient from the associated text field, creates the URI with a mailto scheme argument if a recipient exists, and then invokes the mail() method. The mail() method is overloaded, so you can call it with or without a URI that represents its mailto recipient (see Figure 6).

Figure 6: Launch the default email client with an email recipient.
Figure 6: Launch the default email client with an email recipient.

You can use more than just a single email recipient when creating this URI. The mailto scheme supports CC, BCC, SUBJECT, andBODY fields as well. For example, the following text could be used to create a mailto URI:

    mailto:duke@sun.com?SUBJECT=Happy New Year!&BODY=Happy New Year, Duke! 

Figure 7 shows the result.

Figure 7: The Desktop API launches the default email client with multiple <code>mailto</code> parameters.
Figure 7: The Desktop API launches the default email client with multiple mailtoparameters.

You can, of course, invoke mail() without an argument. In this case, your email client will launch a new email window without specifying a recipient, subject, or body message.

Opening, Editing, and Printing a File

Java applications can open, edit, and print files from their associated application using a Desktop object's open(), edit(), andprint() methods, respectively (see Figure 8). Again, DesktopDemo allows these actions only if the Desktop instance supports them, so in this application scenario, it is not necessary to check for support again.

Figure 8: Launch the associated application for a specific file type.
Figure 8: Launch the associated application for a specific file type.

Each of DesktopDemo's radio buttons has its own ActionListener as well. In this case, each sets an instance variable so that it represents the most recently selected button's associated Desktop.Action:

    Desktop.Action action;      private void onPrintAction(java.awt.event.ActionEvent evt) {         action = Desktop.Action.PRINT;     }                                    private void onEditAction(java.awt.event.ActionEvent evt) {         action = Desktop.Action.EDIT;     }                                   private void onOpenAction(java.awt.event.ActionEvent evt) {         action = Desktop.Action.OPEN;     } 

When you press the Launch Default Application button, it invokes its own listener, which calls the following method:

    private void onLaunchDefaultApplication(java.awt.event.ActionEvent evt) {         String fileName = txtFile.getText();         File file = new File(fileName);          try {             switch(action) {                 case OPEN:                     desktop.open(file);                     break;                 case EDIT:                     desktop.edit(file);                     break;                 case PRINT:                     desktop.print(file);                     break;             }         }         catch (IOException ioe) {             ioe.printStackTrace();         }         ...     } 

This method determines which Desktop.Action is selected and invokes the appropriate Desktop instance method, either open(),edit(), or print(). Each method requires a File argument, which will be used to perform the requested action.

Interestingly, different applications may be registered for these different actions even on the same file type. For example, the Firefox browser may be launched for the OPEN action, Emacs for the EDIT action, and yet a different application for the PRINT action. Your host desktop's associations are used to determine what application should be invoked. The ability to manipulate desktop file associations is not possible with the existing Desktop API in JDK 6, and those associations can be created or changed only with platform-dependent tools at this time.

Summary

Desktop integration is an important theme. One way that Java SE 6 technology supports this theme is through thejava.awt.Desktop API. This API allows Java applications to launch the host's default browser and email client. Additionally, Java applications can launch applications associated with specific file types to open, edit, and print files. Although Java applications cannot manipulate, create, or change file associations, the Desktop API does allow Java applications to launch the default associated applications. This article provides a sample application that demonstrates the API, which you can download from this site.

Note: Any API additions or other enhancements to the Java SE platform specification are subject to review and approval by theJSR 270 Expert Group.

For More Information

The following information may help you learn more about Java SE 6's integration features as well as related topics:


Monday, March 26, 2012

TopicDescription

Debugging HTML and CSS with the Developer Tools

Windows Internet Explorer 8 provides enhanced Developer Tools to help you research and resolve HTML, Cascading Style Sheets (CSS), and JavaScript related problems. This article is focused on the HTML and CSS tools of the Developer Tools. For information about debugging HTML and CSS code using F12 developer tools in Windows Internet Explorer 9 see Using F12 Developer Tools to Debug HTML and CSS.

Debugging Script with the Developer Tools

The Developer Tools feature of Internet Explorer 8 offers a built-in, lightweight Microsoft JScript debugger that enables developers to set breakpoints and to step through client-side JScript code without leaving the browser. This document outlines the high-level features of the JScript debugger.

Developer Tools Keyboard Shortcuts Reference

F12 tools help you to quickly research and resolve HTML, CSS, and JavaScript related problems. This article provides a list of shortcut keys for F12 tools that will help you accomplish these tasks even faster. The keys are listed below by feature set. A comprehensive list of all shortcut keys is also provided for easy lookup and reference.

Developer Tools Tutorials

The Developer Tools tutorials will show you how to use the Developer Tools to inspect and resolve webpage issues. To establish a context for these scenarios, a starting webpage is provided. Each tutorial is focused on resolving a specific issue in order to make this webpage better, and is designed to provide a simple and safe environment for experimenting with the many features of the Developer Tools. For more on F12 tools in Internet Explorer 9 see How to use F12 Developer Tools to Debug your Webpages.

Developer Tools User Interface Reference

This article is designed to give you a quick reference to the commands and menus available in the Developer Tools interface commands. The goal is to help you quickly identify main areas of the interface and to quickly find your way around, ultimately improving your productivity. Each element of the interface is identified and a short description of what it does is provided. For more on F12 tools in Internet Explorer 9 see How to use F12 Developer Tools to Debug your Webpages.

Discovering Internet Explorer Developer Tools

Every installation of Internet Explorer 8 comes with the Developer Tools. This tool enables Web site developers to quickly debug JScript, investigate a behavior specific to Windows Internet Explorer, or iterate rapidly to prototype a new design or try solutions to a problem on-the-fly. This article introduces you to key features of the Developer Tools in Internet Explorer 8. For F12 tools in Internet Explorer 9 see How to use F12 Developer Tools to Debug your Webpages.

Profiling Script with the Developer Tools

The Internet Explorer 8 Developer Tools provide a built-in script profiler that enables you to profile the JavaScript code running in Internet Explorer. This document outlines the high-level features of the script Profiler. For information about the F12 tools Profiler tab in Internet Explorer 9 see Using the Profiler Tool to Analyze the Performance of your Code.

Using Internet Explorer Developer Tools Network Capture

The Network tab in the Internet Explorer 9 Developer Tools can help you diagnose network-related issues by showing all the traffic that is related to a page and exposing details about individual connections. You can see the relative timing that each item on a webpage takes to load and render, so you can quickly see and solve problems. For more on F12 tools in Internet Explorer 9 see How to use F12 Developer Tools to Debug your Webpages.

Developer Tools Keyboard Shortcuts Reference

13 out of 20 rated this helpful Rate this topic

[This documentation is preliminary and is subject to change.]

The F12 developer tools help you to quickly research and resolve HTML, Cascading Style Sheets (CSS), and JavaScript related problems. This article provides a list of shortcut keys for F12 tools that will help you accomplish these tasks even faster. The keys are listed below by feature set. A comprehensive list of all shortcut keys is also provided for easy lookup and reference.

Developer Tools Menu Bar Shortcut Keys

The following shortcut keys can be accessed at any time while the F12 tools are open. Differences between Windows Internet Explorer 8 and Windows Internet Explorer 9 are noted. For more on using F12 tools in Internet Explorer 9 see How to use F12 Developer Tools to Debug your Webpages

ActionShortcut Keys
Open/Close Developer ToolsF12
Resize to 800x600Ctrl+Shift+1
Resize to 1024x768Ctrl+Shift+2
Resize to 1280x768Ctrl+Shift+3
Resize to 1280x1024Ctrl+Shift+4
Switch to Quirks modeAlt+Q
Switch to Windows Internet Explorer 7 Standards modeAlt+7
Switch to Internet Explorer 8 Standards modeAlt+8
Switch to Internet Explorer 9 Standards mode (Internet Explorer 9 only)Alt+9
Switch to (page default) modeAlt+D
Clear Browser CacheCtrl+R
Clear Browser Cache for This DomainCtrl+D
Select Element by ClickCtrl+B
View Class and ID InformationCtrl+I
View DOM (Element+Styles) Ctrl+T
View DOM (Page) (Internet Explorer 8 only)Ctrl+G
Show/Hide Color Picker (Toggle)Ctrl+K
Show/Hide Ruler (Toggle)Ctrl+L
Minimize/Maximize (Toggle) (Internet Explorer 8 only)Ctrl+M
Outline Any ElementCtrl+O
Clear Outlines (Internet Explorer 8 only)Ctrl+Shift+O
Pin/Unpin (Toggle)Ctrl+P
Help (Internet Explorer 9 only)F1

Jump-To Tab Shortcut Keys

The following shortcut keys can be accessed at any time while the F12 tools are open. For more on using tabs in F12 tools in Introduction to F12 Developer Tools

ActionInternet Explorer 8 Shortcut KeysInternet Explorer 9 Shortcut Keys
Select HTML TabCtrl+1Ctrl+1
Select CSS TabCtrl+2Ctrl+2
Select Console Tab (Internet Explorer 9 only)n/aCtrl+3
Select Script TabCtrl+3Ctrl+4
Select Profiler TabCtrl+4Ctrl+5
Select Network Tab (Internet Explorer 9 only)n/aCtrl+6

HTML Tab Toolbar Shortcut Keys

The following shortcut keys can be accessed under the HTML tab. For more on debugging HTML in F12 tools, see Using F12 Developer Tools to Debug HTML and CSS

ActionShortcut Keys
Make value editableF2
RefreshF5
Select Element by ClickCtrl+B
Edit ModeAlt+E
Clear Browser CacheCtrl+R
SaveCtrl+S
View element source with styleCtrl+T
Add AttributeCtrl+Plus Sign
Expand all beneath this three node. This only works with the number's keypad symbol keys.Alt+*
Collapse all beneath this three node. This only works with the number's keypad symbol keys.Alt+-

CSS Tab Toolbar Shortcut Keys

The following shortcut keys can be accessed under the CSS tab. Differences between Internet Explorer 8 and Internet Explorer 9 are noted. For more on debugging CSS in F12 tools, see Using F12 Developer Tools to Debug HTML and CSS.

ActionShortcut Keys
Make value editableF2
Select Element by ClickCtrl+B
File chooser (Internet Explorer 8 only)Ctrl+F
Clear Browser CacheCtrl+R
SaveCtrl+S
Add CSS property while focus is on a propertyCtrl+Plus Sign
Expand all beneath this three node. This only works with the number's keypad symbol keys.Alt+*
Collapse all beneath this three node. This only works with the number's keypad symbol keys.Alt+-
Increment selected value (Internet Explorer 9 only)Up arrow
Decrement selected value (Internet Explorer 9 only)Down arrow

Console Tab Shortcut Keys For Debugger Mode

The following shortcut keys work under the Console tab. This tab is only available in Internet Explorer 9. For more on using the F12 tools Console tab, see How to use F12 Developer Tools to Debug your Webpages.

ActionShortcut Keys
Clear browser cacheCtrl+R
Clear browser cache for this domainCtrl+D
Run script (Single line mode)Return
Run script (Multi-line mode)Ctrl+Return
Toggle between single and multi-line modeCtrl+Alt+M

Script Tab Shortcut Keys For Debugger Mode

The following shortcut keys work under the Script tab. To work, script debugging does not have to start for these shortcut keys. However, some debugging features are disabled when debugging is not started, and pressing these shortcut keys will yield no results. For more on using the F12 tools Script tab, see Using the F12 Developer Tools to Debug JavaScript Errors.

ActionShortcut Keys
Start debugging or continueF5
Stop debuggingShift+F5
Step overF10
Step intoF11
Step outShift+F11
Break allCtrl+Shift+B
Break on Error - toggle on/offCtrl+Shift+E
Toggle Breakpoints - set/unsetF9
Set breakpoint ConditionAlt+F9
Enable/Disable breakpointsCtrl+F9
Delete all breakpointsCtrl+Shift+F9
Go to Breakpoint windowCtrl+Alt+B
Go to Locals windowCtrl+Alt+L (or V)
Go to Watch windowCtrl+Alt+W
Go to Call Stack windowCtrl+Alt+C
Go to Console windowCtrl+Alt+I
Console - Run script (in single-line mode)Return
Console - Run script (in multi-line mode)Ctrl+Return
Console - toggle between single-line and multi-line modeCtrl+Alt+M
Go to Script chooser dropdownCtrl+Alt+N
Next function on StackCtrl+Period
Previous function on StackCtrl+Comma
Go to specific line number (Internet Explorer 9 only)Ctrl+G

Profiler Tab Toolbar Shortcut Keys

The following shortcut keys work under the Profiler tab. For more on using the F12 tools Profiler tab, see Using the Profiler Tool to Analyze the Performance of your Code.

ActionShortcut Keys
Start ProfilingF5
Stop ProfilingShift+F5

Network Tab Toolbar Shortcut Keys

The following shortcut keys work under the Network tab. For more on using the F12 tools Network tab, see Using Internet Explorer Developer Tools Network Capture.

ActionShortcut Keys
Start CapturingF5
Stop CapturingShift+F5

Search Shortcut Keys

The following shortcut keys can be accessed to do Search. For more on using the F12 tools Search, see Introduction to F12 Developer Tools.

ActionShortcut Keys
Move focus to Search BoxCtrl+E
Next matchF3
Previous matchShift+F3

Related topics

How to use F12 Developer Tools to Debug your Webpages
Using the F12 Developer Tools to Debug JavaScript Errors
Using F12 Developer Tools to Debug HTML and CSS
Using the Profiler Tool to Analyze the Performance of your Code
Introduction to F12 Developer Tools
Using Internet Explorer Developer Tools Network Capture

Build date: 2/7/2012

Saturday, March 24, 2012

Free Online Course Offerings Grow in Abundance and Popularity

February 12, 2010

More and more universities across the country and throughout the world are contributing their full courses and materials, including video lectures, to their school websites as well as sites such as iTunes U and YouTube EDU. And the cost of these courses that are normally worth thousands of dollars in tuition? Zero. These institutions of higher learning say they're sharing their courses online with no charge to fulfill their mission of making education more accessible to the broader public, not just to students and educators but to independent learners worldwide. While users do not get academic credit for the free online courses, they now have access to an array of educational materials that were not previously available to the public.

University of California–Berkeley was one of the first universities to enter into the free online educational resources sphere in 2001 with itswebcast.berkeley.edu site. The program automatically records video of faculty lectures in courses across all areas of study. Since its inception, webcast.berkeley has recorded and published around 520 video lectures, says Benjamin Hubbard, the site manager. Berkeley was the second university to publish content on iTunes U in 2006 and the first to publish on YouTube EDU in 2007. Since its inception, Hubbard says webcast.berkeley has received more 100 million views, in addition to 9.3 million views on iTunes U and 13.5 million on YouTube EDU.

Hubbard says webcast.berkeley viewed the partnerships with iTunes U and YouTube EDU as an extension of the university's ability to distribute content on platforms that students and the public were already using. "Our aim was to broaden the window of access to education," he says. "Our mission as a public university is to make this educational content available to folks from all walks of life."

These online educational courses can also reach an even more international audience with the help of automatic captions, combining Google's automatic speech recognition with YouTube's captioning system. The YouTube captioning can be translated into over 40 languages, Hubbard says.

Also in 2001, Massachusetts Institute of Technology began its OpenCourseWare program. This provides nearly 2,000 courses, some with a combination of video lectures, lecture notes, syllabi, and problem sets. Between 2005 and 2008, the program began partnering with other institutions of higher learning in the United States and overseas. In July 2008, the OpenCourseWare Consortium was formed, with more than 200 higher education institutions, domestic and international, sharing their content on the site, says Steven Carson, the chairman of the OpenCourseWare Consortium's board of directors and the external relations director of MIT's OpenCourseWare.

Not only does the OpenCourseWare Consortium work to increase the number of free educational projects and courses around the world, Carson says, but it also brings educators together to create a broader, open-resources community and to establish principles of best practices. He says the courses are used by students, educators, and self-learners worldwide. While these online educational resources will not serve as substitutes for a university or online distance-learning degree, Carson says these free resources will continue to support the growing independent-learning community.

Stanford has also contributed free online courses to the Web, many coming from Stanford’s Continuing Studies program. The university was the first institution to contribute its courses to iTunes U in 2006. It later contributed to YouTube EDU in 2007. Currently, the program offers more than 73 courses on iTunes U and 53 on YouTube EDU. Also, Yale created Open Yale Courses in 2006 under the leadership of Diana Kleiner, the principal investigator of Open Yale Courses. She says there are currently 25 courses on the site, as well as on iTunes U and YouTube EDU, and another 11 will be published this fall. All of the courses include a full set of high-quality videos of class lectures as well as other course materials, including syllabi, suggested readings, and problem sets.

So what impacts do these free online courses have on the classroom experiences in universities? Hubbard says that at Berkeley, he has heard professors who post their video lectures online say that students in the classroom are engaging in a different way. Instead of being buried in their texts and taking notes, the professors say they can actually see students' faces listening and absorbing the lecture. The professors say this is because the students know they can go back and watch the video lectures later if they want to review material. Kleiner says she may assign her own online video lectures as homework and then incorporate the lectures into class discussions. She also says that thanks to the liberal licensing of the online courses, she has seen educators around the world repurposing the content to teach in their own classrooms.

These free online educational resources are also helping to break down the financial and geographical barriers that can limit access to education. "At some level, these courses are helping to democratize knowledge," says Dan Colman, the associate dean and director of the Stanford Continuing Studies program. "Suddenly, knowledge that was fairly specialized is available to anyone with Internet access. It doesn't matter how much money you have or where you live; it's accessible now."

The Down-Low on Online Downloading Sites:

iTunes U- This multimedia file-sharing site contains more than 250,000 educational video and audio files from more than 600 universities, including Yale, MIT, Cambridge, and Oxford. The launch of iTunes 9 has made iTunes U accessible in 77 countries with Apple Stores. Additionally, iTunes U content can be searched and wirelessly downloaded onto an iPhone or an iPod touch.

YouTube EDU- This education-specific YouTube channel created in October 2007 provides more than 60,000 videos from over 300 colleges and universities in the United States, Canada, Europe, Australia, and India, according to Obadiah Greenberg, the strategic partner manager at YouTube. He says the mission of the site is "to facilitate the distribution of open educational resources to a worldwide audience."

Academic Earth- Founded by Yale graduate Richard Ludlow in January 2009, the site has around 3,500 videos from 110 courses provided by 10 universities located around the world. Ludlow says the site has had more than 6 million visitors. He says the site hosts only select, complete video courses that have high production quality.

Open Culture- Dan Colman of the Stanford Continuing Studies program founded the site in 2006 to provide free audio books, online courses, movies, language lessons, and E-books. The site has more than 250 courses from institutions of higher education around the globe.

Corrected on 02/17/10: An earlier version of this article incorrectly stated the number of videos offered on Academic Earth. The correct number is 3,500 videos. Additionally, the earlier version may have given an incorrect impression about the source of Stanford’s free online courses; many programs at Stanford contribute to the university’s free courses on the Web.

Wednesday, March 21, 2012

Running Selenium with TestNG

This week I had to rewrite a bunch of functional tests, mostly Selenium stuff. When I think about Java Unit tests the first thing that comes to my mind is the JUnit framework. All tests that I have written until past week were with JUnit, and was using it to run Selenium.

But I got one more requirement, since I was rewriting all tests I would like to change environments (development and pre-production) without dealing in the code where was running the tests. The problem was a simple one, just write configurations with URLs, expected values and so on, for each of my environments. A trivial example is using different URLs in selenium for the same tests. Well, how do this with JUnit?

First approach, using JUnit 3

In JUnit 3 (old one) you have Test Suites. Programatically you have a chance to read a properties file and give the information to your test classes. Well, this could work if I had not the principle: “Do not write test code if isn’t a test.” When I caught myself creating a “little” framework to test my application I realized “I’m in the wrong way”. Not that you should never code a “little” framework to simplify even more the tests, but i hadn’t the time to do it.

Second approach, using JUnit 4

Well, JUnit 4 is more flexible, newer and uses annotations; and I didn’t explored it well. After some digging i found JUnit’s Parameterized Tests, but again I had (bear with me in this one) “to code, code to test code”. And one more thing, JUnit 4 have Test Suites but, AFAIK, you only have a annotation version to define the classes for a suite.

JUnit wasn’t solving the problem

After some thought i had two choices, forget about environments, or spend some time coding new stuff that wasn’t tests or my application. Justice has to be made, JUnit is a excellent test framework but I think my objectives weren’t too “Unitwise”.

TestNG, next generation?

I heard about TestNG about a year ago and didn’t gave it enough attention, I was happy with JUnit. But, everyday is a new day and I had a problem, so I started to read about TestNG. I was skeptic at first, thinking “maybe this can do it, but I don’t have time to learn it all”. I was wrong, happily wrong.

http://marcovaltas.com/?p=49

Selenium-ANT-TestNG (SAT) Framework

Posted by aditya_dada on May 20, 2008 at 12:39 PM CDT


Architecture

This framework is created using ANT, TestNG and Selenium.
Through this framework, a user is able to create an automated test case which can be run later by executing a single command. The uses of different frameworks are as follows:
Selenium: This framework is needed for recording a testcase, exporting it into Java, and executing it on a browser
TestNG: This framework is used to organize different tests, and to report results.
ANT: provides the glue to hold everything together, and execute basic commands.

Pre-requisites:


Basic knowledge of Selenium IDE, Selenium RC, TestNG and ANT.

Setup:


1. Install Selenium IDE on your Firefox browser.
2. Make sure you have ANT installed.
3. Grab the testws.zip file from here. Unzip it into a directory of your choice.

About the sample
There are 2 bundled samples:
1. AdminLoginTest.java: This test logs into the glassfish admin console using the username/password: admin/administrator. It then clicks on the 'Enterprise Applications' link, and tests to see if there are no applications deployed. Else, test will fail.
2. SimpleTest.java: This test accesses http://localhost:8080/ page, and tests whether the term "Glassfish Project" appears or not.

The config directory contains testng.xml file, and is a place holder for configuration files.
The lib directory contains required jar files, and is a place holder for other library jars/zips.
The test directory contains test java files and is a place holder for other test files.
Once the tests are run, build and test-output directories will be created.
The build directory contains compiled classes, and is a volatile directory that is deleted by the target clean inbuild.xml file.
The test-output directory contains result files, and is generated by TestNG.
Notes:
To run the bundled sample, follow the steps for "Execute your test through ANT" (see below).
Currently, I face some issues running this on IE. I have successfully been able to run tests using Firefox.

How To:


Write a test case
The basic structure that one has to follow to create a test case is:
1. Record a testcase using Selenium IDE (Firefox browser only), Export the test case into Java
2. Edit the test case – java file, and add TestNG annotations
3. Execute the test case using ANT

1. Record test using selenium IDE and export it into Java:
i. Open the website you’d like to test in Firefox browser
ii. Start the selenium IDE from your Firefox browser
iii. Ensure that the Base URL in Firefox is the same as the website you want to test
iv. Start clicking on the website. Selenium will record your actions.
v. When finished, do: File -> Export Test As... -> Java – Selenium RC and save the java file.
seleniumIDE-export.JPG
After exporting, your java test case should look like this:
selenium-java-test.JPG

2. Add TestNG to your test case:
i. Open the java test file you just created in an editor
ii. Add the following:
(a) to the import statements:
import org.testng.annotations.*;
(b) To variable declarations:

private DefaultSelenium selenium;
private static String TIMEOUT_PERIOD ="10000";

(c) To The class:

@BeforeSuite(alwaysRun = true)
public void setUp(String browser) {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080");
selenium.start();
selenium.open("http://localhost:8080");
}

@AfterSuite(alwaysRun = true)
private void stopTest() {
selenium.stop();
}

(d) After each statement in the test that will take time for a page to load:

selenium.waitForCondition("selenium.browserbot.isNewPageLoaded()", TIMEOUT_PERIOD);

(e) On top of the test method:

@Test(groups = { "" })
e.g. @Test(groups = { "roller" })

(f) Edit page to be opened. Make sure arg to ‘open’ method of selenium points to the right context root e.g. Ifhttp://localhost:8080/ is the correct URL to test, then since we already have tried to open localhost:8080 in setUp, we only need to open the context root page.
e.g.
selenium.open("");

iii. Save the test file
(a). (Optional) Update testng.xml file. TestNG uses this file to read which groups to execute and also to pass parameters to the test. This file is only required if build.xml file uses testng.xml file to run the test.
Note: in sample test included, testng.xml is used, and will need to be updated.

iv. Ensure that the test file you created is mentioned in the build.xml compile target.

3. Execute your test through ANT
i. Start domain required by your webpage. e.g. asadmin start-domain
ii. Start database if needed (Not needed for bundled sample test)
iii. Start selenium server e.g. cd testws/lib, java -jar selenium-server.jar
iv. Execute the command: “ant run” from ‘testws’. You should see a new firefox browser window open up, and run through your test.
v. Check reports generated by TestNG under ‘testws/test-output’ directory. Open the index.html to see different output from the test.

SAT-html-output.JPG
Console output:

SAT-cmd-output.JPG