So I have seen this intermittent error with my selenium tests that drives me up the wall. I'll be running a test and all of a sudden a little "Quick Find" box shows up in the lower left corner in Firefox (not the same as CTRL-F). This appears to be some sort of "old feature" of firefox that is used to quickly find links or something in the page (people have complained about it since Firefox 1.0). If you google the term "firefox quick find links only" you'll see the issue. Basically if you are in a non-input field (like the page) and type either "/" or "'" it will invoke this. The problem is, in GXT with selenium in order for some values to be input, events need to be raised by my selenium tests to blur/focus etc. Even though I am not typing in an apostrophe or slash, some sequence will trigger this control. Usually it was during the typing in a text field after clearing it and the first character (or in the case of my tree filter the 8th character?) would be dropped. It turns out, a solution that appears to work is the use of a Firefox plugin to turn off this widget/control (not sure why there is not a setting to do it by default - since I am sure most people do not even know the functionality is there).
There is a solution for this, but in order to use it you'll want to setup Firefox and Selenium to use a custom profile (since you have to install this plugin). To do so, start firefox with the -profileManager argument (ie. firefox -profilemanager). Be sure not to have any instances running when you do this (or else it will be ignored). When the profile manager shows up:
uncheck the "don't ask at startup" - we'll restore this later
choose to create a new profile
give your profile a name like "selenium" and click the choose folder. Before going further write down this path as you will need it along with the profile name. On Windows 7, mine would be c:\users\myusername\AppData\Roaming\Mozilla\FireFox\Profiles.
Launch Firefox using this profile.
Go to your favorite website (like my blog). Without clicking in a textfield, hit the button "/". If you see a Quick Find show up, the next should help disable this.
The process to disable the Quick find is documented here. In particular you'll need to download the plugin and install it to Firefox (on Windows is .xpi is not mapped to firefox choose to pick a file and choose firefox). Once installed, follow the instructions.
After "disabling" it, try step 5 again and this time the Quick Find should not show up.
Now you have a Firefox that will run the selenium tests without Quick Find, but selenium is not using it. The next step is to modify your selenium startup script (if you are running it by typing java -jar selenium-server.jar write a script!. In the script, add the flag -firefoxProfileTemplate path_to_profile_above\profile_name to the end of the command. This will use your custom profile for executing the tests.
Finally, close down firefox and launch it again. This time checkoff the "Don't ask at startup" and choose your regular profile and you are off back using firefox with your profile.
First off, to all those who have patiently asked for my solution of GXT combo boxes and selenium, I do apologize for the long time in coming. While reading my articles is certainly not like being left with a cliff hanger in a movie sequel, I know the pain in waiting anxiously for a solution.
Combo Boxes
After trying many different ways to get combo boxes to work, I have worked out a pattern which I will share which has seemed to provide the greatest stability in our tests. We currently have forty-odd selenium tests run upon check-in to trunk for the stamp webeditor project. Approximately half of them utilize one of the dozen or so combo boxes in my application and the only failures we have seen is when there is actually something wrong with our underlying code.
Here is a break-down of the steps:
If a label is provided (ie. a combobox with a label), attempt to wait for the combobox to be enabled. When the combobox is first shown, the backing store may be initializing or other activities may be happening, thus causing the combobox to be disabled. The routine will simply wait a duration for a given number of cycles for the combobox to be enabled.
The combobox will be clicked.
If the combobox results are visible, and one of those results is the item we are looking for, a mouseDown event will be emitted on the resulting item. If not present, a system out message will be printed (I found this useful in debugging the issue. In practice I may only see the message once if the system is bogged down and running slow)
I found a need to wait another duration after the mouseDown event, proceeding with firing off a blur event. While these last may not always be needed, as I mentioned above, I have not had any failures show up due to combobox selection and having these in the code certainly have helped!
I should mention the waitDuration and waitCycles are simply integer static values (125 and 20 respectfully however I can configure these via configuration). Finally the pause() method is simply a Thread.sleep() call wrapped in a try/catch block. One of my readers Carl, suggested using the Selenium.Wait( ) functionality, which I may explore in the future.
So lets look at some code:
/** * Will select the text in a ComboBox by the specified locator. If the ComboBox is provided * a label, the method will try and determine if the ComboBox is disabled, and if it is wait * for it to become enabled (or timeout after 5000 seconds whichever is first). * * @param selenium The selenium context * @param text The text to pick from the selections * @param locator The locator of the selection input box * @param label The label for the ComboBox (optional) */publicstaticvoidselectByText(Seleniumselenium,Stringtext,Stringlocator,Stringlabel){if(label!=null){StringdisabledLocator="//fieldset//label[.='"+label+":']/following-sibling::div//div[contains(@class,'x-item-disabled')]";inttimeout=0;while(selenium.isElementPresent(disabledLocator)){pause(waitDuration);timeout++;if(timeout>waitCycles){thrownewSeleniumException("Selection element was not enabled after timeout");}}}booleanfound=false;StringdownDownLocator="//div[contains(@class,'x-combo-list')]";StringitemLocator=downDownLocator+"//div[contains(@class,'x-combo-list-item') and .='"+text+"']";selenium.click(locator);for(inti=0;i<waitCycles;i++){if(selenium.isElementPresent(itemLocator)&&selenium.isVisible(itemLocator)){selenium.mouseDown(itemLocator);found=true;break;}elseif(selenium.isElementPresent(downDownLocator)){System.out.println("selectByText() - at least div for the combo is present...");}else{System.out.println("selectByText() - no div for the combo present.");}pause(waitDuration);}if(!found){thrownewSeleniumException("locator:"+itemLocator+" not found.");}pause(waitDuration);selenium.fireEvent(locator,"blur");}
Hopefully this can help alleviate some of the pain out there around the GXT combo boxes and selenium.
Recently I have had the pleasure of working together with one of my coworkers on my Stamp Web Editor project (on our personal time of course). Like all skilled professionals she wanted a chance to try and use some new technologies and libraries (like GXT, JPA and Restful Web Services) and I realized I simply could not continue to develop my hobby application without involving more developers. One problem arose quite quickly. I went from the "one man shop" to having to express my ideas and intentions to another developer often through email and napkin drawings. I also felt there was no permanence to the designs or formal drawings to really refer back to. At my employer I know several of the Product Definition folks use a tool called Balsamiq for doing napkin like designs, which I always felt lacked a sense of fidelity. I wanted more. A quick google search turned up a bunch of different tools.
One that I investigated was a firefox plugin called "Pencil". This is a freeware application, but I found it lacking when trying to show any sort of flow (it is really designed I think to provide a static prototype). Still, if you need a simple tool to show some buttons and forms, this might be a light weight way to achieve this.
The next tool I looked at was called ForeUI from EASynth. While the tool is a commerical product, the EASynth offers a full featured version as a demo which the user can use for 15 days. Some functionality (such as Save and Export) will be unavailable after this time period expires.
Installation/Setup
The install was clean and easy and the application launched on my Windows 7 laptop without any issues. A program group was added in my application bar under "EaSynth" which I would think many users might find confusing (since they installed ForeUI didn't they?) but once you get familiar with it, it should be easy enough to find for most users. It would appear that it is setup by default to look for a newer version of the software which will prompt the user when available:
Capabilities and Impressions...
The first thing that impressed me about ForeUI was its clean user interface. My "paper" page was right in front of me, and the widget I could choose from were easy to find on the left. A toolbar/menu was present for the "actions".
In ForeUI, a plot concept is used to represent your "prototype". You can add multiple pages to your plot and provide actions to transition between pages.
Right away I was able to start adding widgets to my page and exploring deeper. One thing that I did find a little confusing at first was that you had to drag the components onto your page. It was not like Microsoft Powerpoint where you pick your element and click on the page to add it. This is similiar to most GUI-builder tools (like Matisse in Netbeans) and it didn't take me long to pick up the correct action. I was impressed with the components available to the user and they included both application components (group frames, calendars, menu bars) as well as components you might find in a website (images, mock text). The components available allow prototypers to develop a prototype for:
Web sites
Rich Web Applications / Desktop Applications
Layouts (either was Web pages, blog or non-computer related layouts)
As well as visual components, a set of Annotations are available to allow you to annotate your designs with Balloons, Post-Its and Lines. This is especially useful in calling out elements of behavior within your pages. There also appears to be a portal where users can Share their custom components called "Resource Sharing". Some of the examples currently available include a Map component, Ad spots and arrow libraries. While providing a good selection of components, one that I found missing was some sort of accordion panel (the irony is that the components themselves are housed in one). Another confusing aspect was the location of a few of the components. For example the traditional label and images show up under the Basic panel. While these are basic constructs of all prototypes (Web, application, layouts), while working with the widget components I often found myself having to think twice on where I go to get the text label.
Once a component is dropped on the page the user has to ability to customize it further. Overall, I was quite pleased with the options which included:
Changing the visibility
Setting the state of a component (disabled, selected etc.)
Specifying the font type, weight and color
Defining the text of the component
Z-Ordering of the component
In order to change the properties of an item, you can either right-mouse click on it and choose from the menu options or select it and then the elements toolbox appears (by default on the right side of the screen): One aspect I found very confusing was "where" a property option would be. Some options were only available from the toolbox (Group, Z-Order etc.) whereas other were available both from the context-menu and toolbox. Using the context menu is the most efficient, but I started finding myself ignoring it after a while because the options I was looking for were not present. The font for the components will be dialog by default. This produced horrible looking "simulated prototypes" and I had to manually change the font on every component after I had added it. I discovered an option afterward in the Settings menu under the Plot tab where you can specify the default font which appeared to take care of this. One aspect of property editing which could be improved is the double-click edit text capability (you select an item in your page and double click it to edit the text). More the half the time, even when clicking quickly, any movement of the mouse would move the component (thus throwing off my alignment). You can edit text from the toolbox (the pencil icon top-left) and I quickly preferred this approach to avoid the movements of my items. Perhaps if it was not as sensitive (or the move was delayed) this would be a cleaner experience.
The user can move the component around the page either with a mouse-drag or by using the arrow keys (once selected). As you drag near other components, spacing guidelines will appear letting you know that you are aligned along the center, top, middle etc. This allows you to quick setup a user-interface and still have it aligned properly. The guidelines only appear after the item is on the page so you do have to get used to the double drop (ie. pick a widget drag it to your page and drop it. Then select and drag it around your page to get the guidelines). There are some quick options to align horizontally/vertically etc. if more than one item is selected. When you move and align an item with guidelines, there is no concept of spring boundaries (like in Matisse) such that if you add a text field to a window and set the textfield to be most of the width of the window, resizing the window will not resize the text field. There is also snap capabilities which is useful, however I found the default snap value (5 pixels) a little tight.
Grouping of items is supported however in order to do so, you need to carefully select the items and select the "Grouping" icon from the element toolkit (I am not sure why this is not available from the right-mouse context menu). If you stack several components on top of each other it can be difficult to select the right ones. You can get at buried items using the CTRL-left or CTRL-right keys.
You can add events on an item using the action capability. This is very powerful in communicating intent. The type of events you can add depends on the component used but include concepts like:
changing the visibility (hiding/showing)
changing selection (comboboxes, checkbox, tables)
changing pages (navigating to a new screen)
I used it for both showing my annotations (on mousing over a component) as well as invoking events on click.
The table component is a very polished read-only component for ForeUI. The data for the table is excepted as a comma delimited list (with the headers being the first row of data). I found the easiest way to create fake data was to use Excel and export the file as csv (and then copy/paste the CSV content from notepad into ForeUI). It would have been nicer if I could have input the data easier within the ForeUI tool, but I am happy with the end result. One thing that was lacking about the table was providing editable cells (as well as defining a component to use for the editor). I worked around this by dropping an editable component in the desired row above the table (Z-order wise). You seem to only be able to register a single "click event" you will not be able to take the user through a edit session easily. Providing the ability to supply actions / table cell does not appear to be supported and this would really allow for some complex client interactions. For this reason I switched to showing the application in a more static manner and instead used annotations to call out capabilities as the user mouses over components.
I was able to create a relatively accurate representation of my desired client in quick order. Since I was only designing a pop-up tool for my application, I decided to represent my application as a static image and then added a custom toolbar action as a launch point for the new client tool. In order to represent the lightbox affect, I had to drag a filled rectangle over the image (and under the popup tool) with an opacity setting. As I added new screens to the plot, I learned that if my page represented a popup tool, that I should focus first on these components and then add an main application image (with the partially transparent rectangle for masking) afterwards and send this to be back with the Z-order action. An example of a page I designed is here:
Several preview options are available include a Slide Show (showing each of your screens statically) and a Simulation tool which will run your pages in your browser (allowing you to click/iteract with the client). The following is a video I produced for one of the new features I want to implement that shows the simulation:
You can export the project to a variety of different formats including PDF, HTML or as images. The PDF and image formats of course do not provide interaction with the action events, however the DHTML option does output the actions you defined so you can interact with the client (likely using Javascript) using the simulation tool.
Technical Observations
The ForeUI application is written in Java, which allows some nice customization ability such as applying different Look and Feels:
The application when running consumes approximately 160 MB of memory (this was for a three page 50 element prototype with a few interactive actions). Overall this is not too bad and is less than the average requirements for an IDE like Eclipse with Java tooling.
Overall performance and responsiveness was good, which to me shows me that the developers at EaSynth know how to develop proper Java Swing applications by not performing large computational operations on the Swing Event Thread.
I did not run into any crashes, fatal errors or discernable bugs in the hours I have used the tool to date.
Conclusion
With a comprehensive toolkit, the ability to add actions and simulations, as well as online connectivity tools for help, tutorials and additional components I would rate the EaSynth ForeUI 2.X prototyping tool on a scale of ten as a value of My biggest complaint would have to be the inconsistencies in interacting with the component properties and and look forward to exploring its capabilities deeper as I begin to prototype other areas of my application.
Disclaimer
EaSynth provided me with a complementary license to review their product. I think this is a great way for them to recieve more publication of their tool, however as a professional I would be amiss if I allowed this to interfere with my assessment of the product.
I recently updated my application to use a menu hooked up to a button in which I display a GXT CheckboxListView of stamp issues. The general idea is that when defining my stamp if there are flaws (I tend to avoid collecting these) I can check-off the flaws in a drop-down like list. I added some selenium tests to capture the correct functionality, and came a across a few interesting points I thought I'd share.
GXT does not appear to let you set a constant on the checkbox, such that can you tie it back to an enumerated list easily. This meant I had to navigate to the text of interest (localized display value of the enum) and then proceed back in the DOM to get the input field such as the following:
Setting the value of the checkbox turned out to be more than simply using click(). In order for the click to be registered with the underlying GXT models I also needed to emit a DOMActivate event on the checkbox:
I had to reimage my linux server due to a catastrophic disk failure. In doing so, I had to reinstall tomcat(s) (I use two... one for running my stamp app and the stamp test app (selenium testing) and one for running hudson builds). When my ant script for my stamp application deployed to the "production" tomcat, the start target would fail. I looked in the tomcat logs and saw this:
Exception Description: Predeployment of PersistenceUnit [stamp-test] failed.
Internal Exception: java.lang.RuntimeException: Exception [EclipseLink-7018] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.ValidationException
Exception Description: File error.
Internal Exception: java.io.FileNotFoundException: /etc/rc.d/init.d/tempToDelete.xml (Permission denied)
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:121)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:133)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:67)
This threw my for a loop, until the path where the file was being read/written to tipped me off. I have startup scripts that use the java service daemon (jsvc) which are located in /etc/rc.d/init.d. Sure enough, this was the problem. Essentially eclipselink was trying to create a temporary file while attempting to clone an object when TABLE_PER_CLASS inheritance is being used. The fix turned out to be quite simple. I simply had to perform a change directory prior to calling the jsvc to the $CATALINA_HOME(or wherever your tomcat lives) prior to invoking the jsvc.
I had to upgrade my GWT version to 2.0.0 with GXT 2.1.0. For the most part this was pretty straight forward. One change that impacted me was the usage of ImageBundle being deprecated. To convert it to the GWT version of doing things I had to do the following:
extend com.google.gwt.resources.client.ClientBundle instead of ImageBundle
replace @Resource with @Source (from ClientBundle)
the return types will need to change to com.google.gwt.resources.client.ImageResource for each of the image methods.
Instead of using the interface directly (after being runtime binded with GWT.create()), you will need to convert the ImageResource to an AbstractImagePrototype. This can be done by calling the create(ImageResource) method.
The thing that is unfortunate about this, is all my setIcon() calls simply referred to a singleton instance of the images. Now they all need to convert to via the create() call. Hopefully I can work out a nicer solution for the future.
The article that helped guide me in this came from the google wiki: ImageResource Version Info
GXT: 2.1.0
GWT: 2.1.0
The following is a list of the issues I ran into when I converted from GXT 2.0.1 to GXT 2.1.0. This is not the complete exhaustive list, however these may provide others with some of the workarounds.
My dialogs will cascade events to the form panels and their contents on the dialog. A change was made to Layout which requires all components which are receiving the event to have a layoutData defined. Since dialogs would normally not hold a layoutData (in my case they were using FitLayout which results in a null layoutData), I had to change the cascading to start at the dialog's FormPanel.
All text input components have the wrapper set to the id used to create the component (this should be a <div/> tag). The physical input field now has a "-input" added to the end of the id. This impacted my Selenium tests.
The StoreFilterField required the setProperty("name") to be called in order for the filtering to actually be invoked. I also changed my overloaded applyFilters() method to be similiar to the super method in the way it adds/removes the filter on the store.
In my country ListView, when the Events.Select was raised I was retrieving the selected countries from the selection model. This either changed or I was doing it incorrectly, as now the selection model was returning the items before the selection is registered. Instead, I switched to use the getIndex() of the ListViewEvent to find the country that was selected.
For my image panel, I was using a GWT HTML component. This now required the parent to implement HasWidgets interface, which the ContentPanel in GXT doesn't (since all GXT components extend Widget from GWT). Fortunately there is a GXT component Html which does pretty much the same as the GWT one, and converting to use this worked.
Nodes in a TreePanel had their rendering changed from a <li> tag to a <div> tag. This impacted Selenium tests.
Popup menus changed from using <li> tags to using <div> tags. This impacted Selenium tests.
Overall, the changes took me approximately 5 hours to incorporate and resolve the differences in my selenium tests. Some of it was due to changes in the rendering of the GXT components (which is to be expected and is not difficult to reconcile) and some of it was related to event sequencing and component model changes. It was these later changes which impacted my time the greatest.
If you install and attempt to run Civilization 4 on Windows 7 you will likely receive an error similiar to the following:
I was able to resolve this by downloading and installing the latest released runtime version of DirectX. I suppose if you install and play many games you likely have a newer version of the DirectX runtime, but this game was my favorite and was the first (and currently only) DirectX game I am running under Windows 7.
I mentioned to a colleague a week ago that I wanted to provide better syntax highlighting of source code in my blog entries. He suggested I look at Pygments which is a "generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code.". I have to admit, I kind of like it and it is relatively easy to use (just make sure you use spaces in your code instead of tabs!
For those of you who follow the GXT toolkit know, they are currently in the process or preparing for the release of the 2.0 version. I converted to the 2.0 M1 version a few weeks ago and other than a few issues, have been able to continue using my application (and building on it). However when I upgraded to the 2.0 M2 version, I had several key areas that no longer worked. Of course, while I had unit tests to test my services, I didn't have anything for my GWT-based client. At this point I rolled back any updates I had made to be compliant with 2.0 M1, and started to write some Selenium tests to cover some of the key functionality. This should help my conversion to 2.0 M2 later. Through the use of Selenium I have come across a few tips and techniques I thought I'd share:
1. Be liberal with pauses (just be smart about it!)
Ideally you should be able to type, click and type, but the nature of GXT being a web application means that there are many transitions that occur, elements need to be built/loaded etc. Do not assume that after clicking an action to show a dialog that the dialog is immediately there. To handle this I do two things: First, ensure that the element is present, and second that the element is visible. Since the element may take a while to materialize you should wrap this in a loop for a predetermined time and break when both conditions are met (I generally use 1.5-10.0 seconds as the maximum timeout waiting 100-250ms between checks). You need to use your judgement based on the complexity of the elements you wait for (for example updating a status bar may be immediate, but creating a complex form (for the first time) might require creation of models etc.) You need to check for the element being present first, because the call to selenium.isVisible( ) will throw an exception if the locator is not yet in the DOM. Here is a simple example from one of my Selenium solutions:
2. Keystrokes and GXT
For text input, Selenium provides two methods: type() and typeKeys(). The later supposedly emits keystroke events as the keys are typed in sequentially (whereas type() acts more like a paste of a set value). As I posted previously in Selenium with GXT..., the problem with these methods and GXT is they do not seem to play very well together. I have not done too much data entry testing yet in Selenium, but I have cases under test and only one of the three worked using type() without changes. The two that didn't work consisted of a StoreFilterField to filter my tree view, and the other were simple form fields in a window.
For the StoreFilterField, it was essential that as each keystroke was made appropriate events were fired to cause the filtering to be invoked. In my case, it wasn't important to have the events be emitted with each keystroke, just when I was done. What I discovered was that I had to manually emit the events after typing with a slight delay after the keys had been typed. From running these tests over and over, it would appear that a delay of approximately 250ms is sufficient between the typing and the event emitting. Keep in mind, if you use typeKeys( ) this is supposedly already emitting these events. What is important is to emit them again. This is what seemed to trigger the filter to fire. Within Firefox, you need to emit three key events: keydown, keypress, keyup in that order. As well, as I will discuss next, form field were only populated in GXT with a blur event, so I also fire the blur, focus events. While this might seem kind of over-complex, it does work, and my tests have been running smooth (and passing) since. I wrote a method which I put into one of my abstract solutions called textWithEvents. Lets look at the code:
Now one thing you'll note is that I am using type() and I am actually re-typing each character. I could have typed the whole thing, but then this would not have fired the events as I was typing (which some code may require). But why not typeKeys? I can not explain this yet, but typeKeys() leads to invalid strings not matching the input text. I had a test failing over and over for a while and it was because of the use of typeKeys() in a StoreFilterField. What was happening was while trying to type in the text "My Test_233333--2", the result was "MTest_233333". Somehow typeKeys() was dropping characters or invoking other characters (such as a backspace) instead. I was at a complete loss. When I came across this in disgust (having lost almost an hour trying to figure out the problem - I thought it was related to locators originally) I decided to switch to type() even though it is a little slower. If you are filling out simple forms you will not really notice more than a few extra milliseconds. For typing large amounts of text in a text area, I would recommend a hybrid of the above method, likely simply using type() for the entire text and then double emit the key events with a pause between (unless you need to test UI interaction with each keystroke).
Finally, the reason for the blur and focus events was to ensure the form fields were populated. In GXT, form fields like TextFields do not store their value in the input HTML components, but internally (I assume as a variable in Javascript). You can see this watching the changes to the DOM using Firebug with Firefox. For this reason, to ensure the values are updated firing the blur event, will update the GXT component value. The focus event was fired just to maintain focus in the component.
I intend to continue this topic to cover some other areas I have discovered (such as smart locators and ComboBoxes) in an upcoming article. I felt this article was getting a little long. Stay tuned!