blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Richard Griffin's Blog

  • Silverlight Tweening Adventures with Baby Smash!

    BabySmashScreenBefore starting out  on my tweening adventures I have to admit too being complete tweening newbie. On previous WPF and Silverlight projects animations were rolled from scratch to provide the desired responses to changes in the applications state. With regards to Designer and Developer workflow this  stage of the process is usually where the 2 worlds collide. The developer adding animations in code behind hand cranking; Storyboards and animations; and dealing with event handlers. The designer is using Blend to create Timeline animations declared in Xaml. The other point to note is that Developers can't do animations, we may be able to code the equations and provide the necessary hooks for when event that happen when an animation finishes, but essentially the designer will have the last say in the matter with regards to the aesthetics of the animation created. My own experience is that we start with good intentions by putting all the animations in Xaml but this can become a little tricky when you have to deal with different states and trigger different animations. So this is when I fall back to putting all my animations together in a Resource Dictionary; and handling the state changes in code which fire the animations that the designer has created. The other problem that i have come across is when you have dynamic data data bound to an Items Control and you need to animate the different items based on their position in the Control, this simply can't all be done in Xaml and is a combination of Storyboards declared in Xaml and code behind to trigger the animations. In general animations can cause problems and I was also frustrated that these animations having to be hand rolled from scratch, this was evident when Felix asked if I would write some Silverlight animation code for him recently and while I was doing this all the memories of working with WPF and animations came flooding to mind at which point I thought that there must be a better way. I vaguely remembered reading an article on Silverlight Cream from Koen over at first floor solutions and further back a post from Adam Kinney. If like me you are new to Tweening this is a great place to start and is where my journey really begins. After reading the blog posts and looking over the other Tweening libraries from Cristian all of which are based on Robert Penner equations I was feeling confident that I could use this code and start to tackle my first problem. Animating Baby Smash! shapes.

    After helping Scott with some other parts of Baby Smash! we started talking about how to animate the different shapes that Felix had created. We discussed the above and based on the outcome I decided to use tweening rather than hand cranking the animations from scratch, but I wanted to do something that would Tweening code Xamlnot only work in Silverlight but also in WPF, this is where Koens' Library solved my problem. I download his simple Silverlight application which shows off some of the basic features available in the Tweening Library and put in some additional tweaks to the UI allowing for more control over the different Transfroms which we can use in Xaml. We have a bunch of different transforms available in Silverlight, which include; RenderTransform; ScaleTransform; RotateTransform; and SkewTransform. Not only did I want to be able to play with tweens for each Transform type I also wanted to allow users to change the values for their selected transform, for example the Scale Transform supports Scaling on the X and Y axis so there are sliders which can be used to change the values from and to which the tween will use to animate the Scale tween selected.

    Scott is building Baby Smash! mainly using code behind, and I can understand the attraction of heading for the code behind as this is what we feel comfortable cranking. From personal experience when building WPF applications burying goo in the code behind is not always that best thing especially when you are building interactions for the user. These interactions will have an impact on the designer and if they are not in the Xaml then they can't help that easily, but also they are more willing to change Xaml than code behind. Keon solution fits well, it allows me to add the animations in Xaml and event handlers in the code behind, allowing the designer to tweak the animations to produce the desired effect.

    So now we have away to play around with the different tweens and how they effect the various Transforms, we can also hit the Xaml button and get the Xaml required to recreate the Storyboard. The next job is to get everything working in WPF. I created a new WPF assembly and stuck Keons' library in. Next up add a reference from Baby Smash! project to the tweener project. Find the User Control shape that I want to change and add this code into the Resources collection of the Grid we also need to add the RenderTransformOrigin and set the value. Finally I needed to add the Render, Rotate, Scale and Skew transform to the Transform group collection of the grid.  Hit F5 and i get to see my shape and the tween animation that I created in the Silverlight app. 

    FigureGeneratorThere are a couple of problems with my approach; first is that we are duplicating the tweening code in all the User Controls; and second problem is randomness, if I want to keep the equation applied to the shape but randomly change the from and to values this is currently not possible. I style may help here as Styles support animations, however I am referencing UI Elements that are in the Grid and this could cause some issues with regards to Scoping. My other choice is to add the animations into another Xaml file and use a Resource Dictionary. Keons' Library is best used inside a Control Template, however the Baby Smash! shapes are User Controls which contain a layout grid that hosts other UI Elements unfortunately these controls do not inherit from Control and thus I am unable to use the Control Template. As I could not make a decision I thought that I would attempt both the Style route and the Resource dictionary. I created an empty style for the layout root grid and moved the tweening Xaml into here, and that is about as far as it went, I got an exception at runtime complaining that it could not find the target. This is the scoping issue that mentioned earlier as the UI Element that we want to target is  out of scope. So next up is the Resource Dictionary. I created the Resource Dictionary in Blend and moved the tweening Storyboard into the Resource Dictionary, final part in Xaml is to just add in a reference from within the User Controls Resources collection to the new Resource Dictionary. Using this mechanism means that I have to trigger the tween for each shape from code behind, but its only a couple of lines. In Baby Smash! the figure generator is where most of the action takes place so in there I added some code to kick off the animation for shape. I have now replaced the duplicate code with a single Storyboard that we have in the Resource Dictionary, cool, but what about Random changing of the tweening easing functions and input values ? To implement this part I iterate over all the Children which in this case are DoubleAnimationUsingKeyFrames and call on of the Utility methods in Baby Smash! to get two random numbers generated.  To change the other values we can simply add the other static method calls to change the inputs on the tween. So I guess the next question really is "What would it have taken to do it all in code behind ?? "Tweeing code only You can see that if we go with all the animation tweening in code behind then it looks like this, yeah that's all it takes to get the animation working. By creating the Storyboards in code behind we loose the Verbose qualities of Xaml but we also loose the designer. My current thoughts are that if you have a number of UI Elements that you want to animate and these animations are pre baked by the Designer, go for the Xaml route. However, if you are looking for a solution to either dynamic items in an Items Control or you are looking to do something which is similar to Baby Smash! go with the code behind.

    While I was building this code Dev Dave and Scorbs put together the FlickrViewr using the Animating Wrap Panel and Robbie updated his site and also posted a great post on animating panels. So the next job is to take Dev Daves' AWP and change his interpolations with Penners' Equations. I have got pretty far with this but I have a performance tweak that I would like to make before posting the source. What I am hoping to build is a versatile AWP where you can easily say in Xaml what tweening easing equation you want to use along with the inputs. You can download all the source from my SkyDrive or you can load up the URL and have a play with the app here.

  • Silverlight Nuggets

    If like me you are following the Silverlight trail, you are more than likely to be reading Silverlight Cream and the Silverlight Show and their daily posts which provide a great way to stay on top of the daily Silverlight news. Not only Silverlightnuggetsdo I subscribe to this sites via RSS but also their twitter feeds which I take advantage of as my RSS reader tends to get a little swamped with unread posts. I have yet to reach this stage with Twitter I am sure the time will come but for the moment the new entries appear in twhirl and its a joy to go and instantly have a read of the news. Recently, I have been posting about styles and control templates in Silverlight 2 Beta 2 tabcontroland posting up the code for other people to take a look and comment on. Over the weekend Rajeev from Silverlight Nuggets contacted me asking if I would be interested in posting my source up onto the site, which I gladly agreed too.

    Silverlight Nuggets is a great site built using Silverlight which hosts working demos of Silverlight controls and styles that you can find on the Internet. There is a complete listing of the controls that you can dig into with a brief overview of what each UI control does. Once you have found the control that you would like grok there are a range of different community  built styles that have been built. You can select the individual styles and view live what they look like and more importantly interact with the controls. All this is great but Silverlight nuggets also pull apart the Visual tree for the styles and control templates use d in the viewing the visual tree of the controlsample so that you can get an in-depth view of the UI controls used to create the visual metaphor. Awesome..

    If you are building styles and control templates in Silverlight 2 Beta 2, Silverlight Nuggets is a great place to share you code.

  • Skinning Controls in Silverlight 2 Beta 2 - Introducing the TabControl, TabPanel and TabItem

    With the new release of Silverlight 2 Beta 2 came a new drop of controls that allow the designer and developer to build tabbed content that we have become used to, the TabControl, TabPanel and TabItem don't reside in the standard Silverlight Controls assembly but live in the System.Windows.Controls.Extended assembly. After reading Tim Heuer's post about the TabControl and not having used the controls before I thought that it was about time I got to know these new controls.

    To create a simple TabControl you can drag the TabControl from the toolbar in Blend and drop it on to your canvas and resize the control to your requirements, next select the TabItem control, making sure your TabControl is selected double click the TabItem on the toolbar and you can add in as many Tabs as you require, nice and easy. This is the simplest tabbed control you can build. But what happens if you want to change the style and template of the control to come in line with your applications skin ?? In a previous post I covered skinning a ListBox Control and its visual elements, in this post I will attempt to cover the tabbed controls that are available in Beta 2.

    When we want a higher level of control of the TabControl and its items we need to create our own custom Style and Control TemplatTabControlTemplatee for the TabControl and TabItem's. In Blend select your TabControl and from the Object menu option select edit style and select the   create empty sub menu option, I called mine MyTabControlStyle, we then get to see our new style which is rather plain as it is empty, so lets move on and edit the UI elements of the TabControl template. Select the style in the object tab and right click and edit the control parts template, and select the Edit a copy option, I called mine MyTabControlTemplate calling the style and the associated control template is the standard naming convention that I use so that it it easy to keep track of what templates belong to what styles and vice versa. Now if you check out your TabControl you will find that what once looked like a TabControl now looks nothing like a TabControl, the reason behind this is because we have just changed the style of the control and its template both of which are empty. What need to do is workout what the UI elements we want to use so that we can create the required design.  The first UI simple tab control template and styleElement that we need to add is a grid to hold all the other UI Elements. Once we add the grid into the control we then also get the different common states that are supported by the control template. In this case the Common States are Normal and Disabled. Next UI control too add into the control template is the TabPanel control. The TabPanel control provides a container where the TabItem's will live, therefore the TabPanel plays host to our TabItem's. Next up is our Border UI element for the control. Next and most importantly is the ContentControl for the content that will be displayed by each TabItem added into the TabControl.

    When you add the ContentControl to the control template it will automatically create the template bindings for you. You can change these settings in Blend templatebinding when you have the ContentControl selected you will see that there are yellow squares next to the group that is bound. When you select the square you will get a popup where and at the bottom is a template binding option with a bunch of submenu options that you can choose based on what you want to bind up to. The TabPanel part of the control template can be used to change the size of the TabItems that are hosted inside so that you can easily change the height and placement of the TabPanel and this layout will effect the TabItems hosted inside.

    The next step is to move on to the TabItem, follow the same steps again by creating a style and then the template. Once you have you empty control template ready its time to add the UI elements that we want to the template. First off add a Grid to host all the other visual elements we are going to add. Next add in a border for the outer part of the TabItem. Inside the outer border add a second border which we animate when the user mouse's over the TabItem. To this border we need to a grid that will host a rectangle for tTabItemControl templatehe selected background when the TabItem is selected we also need to add a Content Control that will host the Header content of the TabItem. Now we have the basic structure in place for the TabItem we can start to customise the tab and create the design required. 

    There is a gotcha here which caused me some pain for a while. The TabItem design that I wanted to build was a tab which has rounded corners and positioned slightly above the content rendered in the TabControl Content area very similar to the TabItem controls in Blend. After a number of attempts at building the TabItem control template I could not get the design that I wanted as the background of the control would not rendered correctly after it had been selected. So even though the UI element rendered correctly when the page loaded once you had selected the TabItem and selected another TabItem in the TabPanel the Look and Feel changed as the background had changed to the background of the TabItem's root element. This was very unexpected behaviour as  you can see the TabBorder lives within a Grid and something somewhere was changing the background colour of the grid to be the background colour of the TabItem. What the problem turns out to be is the naming of the controls in the Control Template. I had named each of the Visual Elements the same as the default TabItem Control Template, based on the help that I found in the docs. It turns out that there is some code in Silverlight that deals with the TabItem which uses margins to move the TabItem and in here the code looks for the default names of the UI elements to perform these interactions. Therefore by changing the names of the UI elements this solved all my problems.

    When building the TabItem you will want to set the UI elements width and height to  Auto, however this is not great when your are trying to get the look and feel that you want for your TabItem, personally I make the control larger until I have a layout that is close to the design, tTabControlskinhen reset everything back to auto before building the solution. Once you have all the elements in place and the layout you want then next it's time to add in the interaction animations for the different states of the control. The TabItem has  a number of different states that we can wire up to. The first state I am going to wire up to is the MouseOver. In Blend select the MouseOver State from the state tab and select the TabItemInnerBorder UI element, and change this to the colour of your choice. Then repeat the same steps for the other visual states that you want to change. I went for a different coloured background for each different state, to give hints to the user the image on the right screen shot of the final design where the first tab is in a selected state, second tab has a MouseOver state and the third tab is in a normal state.

    You can download the styles and templates from my skydrive folder.

  • Skinning Controls in Silverlight 2 Beta 2

    With the new release of Beta 2 and Blend skinning of Silverlight controls has improved dramatically. Rather than hand cranking these due to no support at all in the previous version of Blend, you can now change templates and styles from within Blend rather than cranking the Xaml yourself. Not that I don't like cranking Xaml by hand but better tool support means that you are more productive and it also becomes more accessible to designers who are not interested in cranking pages of Xaml.

    Recently I have been upgrading some of the work we have been doing in Beta 1 to Beta 2 and this time round I am concentrating on skinning and templating of controls. I will post soon about my experiences in doing this but in the meantime Corrina Barber is updating her skins for Beta 2 which is where I am sourcing my information.  Tim Heuer has a great post on skinning controls in Beta 2, in the Tim's post he illustrates how we can edit templates of a Scroll Bar and then start to change the composite parts that make up the Scroll Bar. In this post I want to take Tim's example a little further and illustrate a couple of areas that are worth noting when skinning controls.resourcestab

    So once you have decided to change the template of the Scroll Bar you may want to go back and make some further tweaks, the way in which you can do this is by selecting the Resources tab and selecting your style for the Scroll Bar, in this instance I have called mine TestScrollBarStyle (not very elaborate I know). Also listed in the Resources tab you will see all you other styles and templates that you have created specific to your application. By putting your resources into the App.xaml file this helps leverage the separation of concerns between the designer and the developer, allowing the developer to work on other controls and code behind, and freeing the designer to create skins for the controls that have a global effect on the UI elements used in the application. Once you have found the style or template that you want to edit we need to select this and start to work on tweaking the design. We edit these by double clicking on the Editing scrollbar res  icon at the far right hand side which will then display the Scroll Bar, which looks just like the standard Scroll Bar. TestScrollBarYou may now have noticed that as we are editing the style of Scroll Bar there are no other controls listed in the objects tab. So how do you edit the style ?? What we need to do here is ensure that the Style is selected and then right click on the selected style, then select the Edit Control Parts option and under this Edit scroll bar templateoption select the Edit Template option. You will now see all the composite UI Control templates that are used to create a Scroll Bar. Also notice that we have moved from the editing a Style to editing a Template.

    We now have the option of editing the templates to change the look and feel of the Scroll Bar. Lets follow Tim's example and change the skin of the Thumb template. Select the Horizontal Thumb template from the objects tab and edit the controls template. Blend now shows you all the UI Elements that make up the Thumb template, including animations and colours used on the UI elements required to deliver the behaviours of a Scroll Bar. So while we are here we can change the UI elements that we want for the Scroll Bar and change the animations and colours being used. We should now have a new visual design of the Scroll Bar, cool that was not too difficult for us to achieve.

    What is happening in the Xaml ?? Well what we can see is that we have changed the Horizontal Thumb template that lives within our style for the Scroll Bar and when we view the ListBox that is using this particular style we can see our new visual design being used, however we are only seeing our new design on the template that we updated, more than likely this will be the Horizontal template. This is because we have only update the template for the Horizontal Thumb and we have not yet changed the Vertical Thumb. So we could, either copy and paste the contents of the Horizontal template into the Vertical template or we may want to have a completely different design for the Vertical Thumb. Personally I don't like either of those options, as a developer I like to read beautiful code and one of the tenants of beautiful code is based around DRY (Don't Repeat Yourself) and having 2 different skinned Scroll Bars I think would be confusing. So how do we resolve this issue ?? In our application we are likely to have many controls that derive from Items Control and we want a consistent look and feel to the Scroll Bar and in this particular case the Horizontal and Vertical Thumb.

    The solution to the problem is to create a Style that we can apply to many different Thumb Templates. So how do we do this ??Create thumb style

    In the previous steps we changed the template associated with the Thumb, what we actually want to do is change the style and to do this there is an option which is not all that intuitive to find. Select the Horizontal Thumb template and then move up onto the main menu  options where you will see an option called Object, select this option and towards the bottom you will see called Edit Style, select this option and then select the Edit Style option from the sub menu listing. You will then be prompted to create a new Thumb Style. editing the thumb style We now see our new style, to edit the style we need to change the template and we do this by selecting the style in the objects tab, right click and edit the template associated with the style. We now see the UI elements associated with the template that we can change to be the visual design we want.

    Once you have modified the layout controls, colours and animations that you want we need to associate this new style with the Horizontal and Vertical Thumb control templates that we edited earlier in the Scroll Bar style. In the resources tab select your Scroll Bar style and edit the template so that we move down to the composite control templates that are used to create the Scroll Bar. Select the Horizontal Thumb template and right click,  rather than selecting the edit template select the apply resource option, in the sub menu options will be the new Thumb style that we created previous select the resource and this will apply your new Thumb style to the Horizontal Thumb. Repeat the same steps to associate the Vertical Thumb Control template with your new style.

    The final part is to ensure that you are no longer using the Horizontal Thumb control template but using your new style, so you may not see your new Thumb Style, we need to modify some Xaml to do this. The highlighted line below is what we need to change.

    modify the xaml

    As we can see from the Xaml the Thumb has been wired up to the Style that we created, but it is also wired up to the template that we created earlier on. We need to remove the reference to the Template and let the style do its job. Once this is done we will then see our new Thumb.new thumb

     

    final listboxWe can do the same to all the other Templates that constitute the Scroll Bar style and reuse them across the application, allowing the design to build a consistent theme for the application in complete separation to the developer. If there is enough demand from readers then I would be happy to do a screen cast if this makes it easier.

     

     

  • Upgrading from Silverlight Beta 1 to Beta 2

    Felix and I have been presenting around Europe at the Remix Essentials events giving away a white labelled Silverlight mashup. Being on the Silverlight TAP I have been trying to keep the project up to date with the latest drops but fell behind. So while in Mexico on the Friday evening I thought that I would try and do a simple upgrade to Beta 2.

    So for those of you out there that have not seen the presentation I have put the complete deck up on my public SkyDrive area so you can take a look at the deck. However, I will give you a little more background about the application. Felix and myself wanted to build a simple Silverlight mashup so that we could gain a better understanding of Beta 1 and how we could bend it. My other goals were to try out a simple testable pattern based on an MVP approach; and make the entire app a white labelled application so that people who have not done Silverlight before can easily change the endpoints and change the skin of the application so that they could get up to speed quickly with Silverlight. The idea was that this would be attractive to developers and designers so that it would act as a stepping stone to try out the technology and the workflow required to build an application.

    So lets open the Beta 1 solution and see what happens. Visual Studio works out that my copy is using the older Beta 1 version and politely asks me if I wish to upgrade the solution to Beta 2. The solution loads up with all the correct bindings in place so I hit F5 and watch the output window for errors.

    upgrade  The only compilation issue was about the multi scale image control. Checking the documentation you will find a section on breaking changes for Deep Zoom and the multi scale image control. 

    MSI Change

    and

    DZ Collections format change

    After making these changes build the app. Green light cool.

    Next its time to change the Deep Zoom Compositions which I created for Denmark and Austria, forgot my camera in Dublin and Mexico :-(

    So open up  the old files and simply make sure that the composition option and output as files options as selected, then hit the export. Once this was done copy over the goo and drop them into the ClientBin. To get a definitive list of new stuff check out the Expression team blog. Once that's done the final part is to update the code.

    Beta 1

    case Model.RemixEvents.Denmark:
    {
        this.DeepZoom.Source = new Uri(this.remixDenmarkSource);
        break;
    }

    Beta 2

    case Model.RemixEvents.Denmark:
    {
         this.DeepZoom.Source =
       new DeepZoomImageTileSource(new System.Uri(this.remixDenmarkSource));             
       break;
    }

    So far so good, no real pain to be had.

    The mashup contains a simple User Control to wrap up all the functionality of a deep zoom view and the corresponding View Model that contains all the logic for the view, such as filtering of images and working out which image in the collection has been selected. Curious of the new Deep Zoom Composer and wanting to interact with the new UI and its features, I decided to create a dummy project and see what happens. I find that with new technology it best to start real simple and then layer on the complexity so I created a new simple project with 2 images and left all the defaults in place. View the collection using the in browser option and the collection appeared ready for action. Cool...

    Then select the open in Blend option ready to create the filtering GUI to test out the filter as this code needs to change to come inline with the new metadata.xml file that the DZC auto gens for us.

    Unfortunately, I was getting an error as the project file which opens is incorrect.

    blenderror

    If you use the default values you will get something like DeepZoomOutput.sln that DZC has asked it to open. However, it should be DeepZoomProject.sln. Not a biggie but a little frustrating when you want the process to be a seamless one. Ok I thought open everything up in VS08 just in case there is a problem with the new version and VS will usually give you better debug information at Runtime. So I open the project with no errors and hit F5. I get a Xaml error in the browser.

     XamlErrorinbrowserfromVS

    My next stop is to right click on the html file and select the view in browser option, the Browser starts up and loads up my Silverlight goo with no errors. On closer inspection the clue is in the URL which is given to the browser hitting F5 it was :-

    C:\Projects\ConchangoLabs\DeepZoomFilter\FitlerExample\Collection\ascollection\DeepZoomProject\Bin\Debug\TestPage.html

    However if you right click and say view in browser it references the webdev server instance :-

     http://localhost:56724/DeepZoomProjectWeb/ClientBin/DeepZoomProjectTestPage.html

    The way around this is to make the web site your startup app and make the .html page your start page and say yes to debugging support for Silverlight and all is well again.

    The video plays and the Deep Zoom Collections are loaded into the User Control and my interactions still work. However I am still not getting any data. Strange after checking all my bindings and everything is looking good. So debugging the page around the where I bind up my data and find that Silverlight is barfin' with an UnauthorizedAccessException, due to cross-threaded access. The threading model in Beta 2 has changed, and the Invalid cross-threading exception is due to the code trying to update the UI while still on the background thread. So we need to marshal back on to the UI thread and update the control with the new data from the response stream. After a bit more digging I found a couple of recent posts by Scorbs on WebClient and HttpWebRequest changes in Beta 2 here. So my next job is to change the way in which I update the UI from within the ModelView for that View. The original code looked like this.

    original code HttpRequestCallback

    In WPF we have something called the Dispatcher, which allows us to do a BeginInvoke and add the UI work we want to do into the queue for the UI thread to process depending on the priority that we sent, if you are not familiar then Dr WPF has a good article or check out msdn. However, the Silverlight Beta threading model is not the same and the call to the Dispatcher's Begin Invoke takes only a delegate, so you can't set the priority of the work put into the queue. But doing the BeginInvoke is only part of the story and you don't actually need to do it in this particular case, what is important is to use the SynchronizationContext and call its Post method which takes a delegate and an Object. Cool however, there is a little gotcha we need to look out for. Although you can call the Current property on the SynchronizationContext it is not guaranteed to return you the context of the UI thread, so SynchronizationContext.Current.Post(delegate, object) is not going to do the job. To get around this you need to grab the Context in the constructor of the main page. For example my start page looks like this.

    SyncContextconstructor

    Page.xaml.cs and in the constructor I am getting hold of the context and passing this into the constructor of my ViewModel, the ViewModel then will retain this reference so that all my other calls to add items to the UI queue will use this reference. It ends up looking like this.

    newcallback

    The last bit of work to be done is to add the call to the BeginIvoke on the Dispatcher to update the UI now that we have a hold on the UI thread. Notice that as we are on the background thread it feels right to process all the data sent here rather than doing this work on the UI and blocking something that could be reducing the experience which the user is having. 

    UIDelegate

    That was quite a lot to get through so you may want to go and grok this code a little before you crank your own, however before you do read on.

    Everything is building so I fire my app and sit back to wait and see my data in the control.... However nothing gets displayed. Strange... Well not really as there have been schema changes in Beta 2 the styles associated with my control nolonger work. So its time to jump into the Xaml and remove the associated styles from the ListBox. Build and run.... Whoa I see data in the ListBox.

    After changing each of the ViewModel's to use the same pattern as above it's time to start changing the controls styles which I will attempt in the next post about upgrading from Silverlight Beta 1 to 2.

    If you have come across any other gotcha's then I would like to hear about them.

  • Getting ready for Mix07

    Less than 24 hours to go and I will be on my way to Vegas for Mix07. Last year Mix06 was a great success and after watching the channel 9 video "Mixin' it up with Beth and Ray" this year is going to be bigger and better. Unlike other Microsoft conferences where audiences grok a number of new offerings from Microsoft where speakers are only from Microsoft Corp, Mix on the other hand is completely different!

    ... Awesome I can get excited with other folks about RoR, YUI and Apollo rather than being a black sheep…

    So not only will there be Microsoft dudes but techies from Amazon, Apple and some php dudes who will going head to head with some asp.net dudes in a tech face off.

    If you are going then drop me an email and it would be great to catch up you can also find me on facebook. If you're not going then stay cool, as you can be in the virtual audience, so you can catch up with all sessions and speakers online. Whilst at TechEd 2007 Barcelona last year I attempted to blog at the end of each day however this proved to be rather difficult I will attempt this again however don't hold your breathJ.

    >Rich.

  • Converting Dashboard Widgets to Sidebar Gadgets

    Jamie and I were chatting yesterday morning about Vista Sidebar Gadgets when he sent me a link to the Sidebar Gadget Development MSDN Forum where chemgirl had posted a new thread "Can someone make a gadget for us chemistry students". I read the post and had a look around the Apple Dashboard Widgets page and found the "The Periodic Table" widget written by Chris Fennell.

    Now I have been pondering for a while about writing a tool that will convert Dashboard Widgets into Sidebar Gadgets and I have been looking for an example to play with that will highlight some of the processes that a tool will have to perform in order to convert from one to another and what happens if you want to invert the process and go from a Gadget to a Widget?? A couple of months ago I attempted to convert some Gadgets that I had written to Widgets but all the Gadgets used IE7's RSS platform and this just made it all more difficult.

    I was having a couple of problems with Threading in WPF so I thought that I would allow myself a lunch break and see if I could convert the Widget to a Gadget during lunch.

     

     

    Rather quickly I was up and running and had managed to convert the Widget to a Gadget. The steps that I followed were:-

    1. Create the .xml file to and update the.
    2. Identify and then Modify the main .js and add some specific Gadget calls to ensure that the size dimensions are correct.
    3. Add the images and modify references.
    4. Modify the css where necessary.
    5. Repackage the gadget.

    There is some Fit and Finish to be added to the Gadget, however I ran out of time. There is also the issue of design guidelines that are enforced by Microsoft which are not strictly adhered to. So I have a simple process that I can attempt to code up and run against other Widgets in an attempt at converting Widgets to Gadgets. I will keep you posted as to my progress in this area.

    Chemgirl I hope that this helps you out. I have attached the gadget for download.

  • WATiN Recorder v 0.1 Released

    It has taken a little longer than I first anticipated releasing the WATiN Recorder, so please except my humble apologies for this. When I first scratched this itch I had no idea that so many people out there would be interested in using the recorder. So, I wanted to ensure that the recorder got the best possible start in life. Allowing my vision of a freely downloadable web UI testing tool built which utilizes the WATiN framework can mature, powered by a passionate .Net community. I would also like to say thanks to Scott Hansleman for helping in push the Recorder into its new home; Jereon for giving birth to WATiN 1.0 and making all this stuff possible; and also Patrick Lightbody for sponsoring OpenQA.

    So, I have been rather busy as of late working on a number of different Conchango projects to include; the building windows Vista Sidebar Gadgets for MSN UK(soon to be released); working on the Daily Mail eReader; and presenting the eReader at the launch of Windows Vista at TVP where Mark invited someone from the team to come up on stage and talk about our experiences of building a WPF application in the real world.

    When I first built the recorder one late night many moons ago I simply did not realize just how many people would be interested in the recorder. I had always had a vision of a small community but for the large number of emails that I have received on a daily basis I am hoping that you guys can help out with powering this community to ensure the development of the recorder continues.

    The WATiN Recorder can be found at openqa.org where the other open source testing tools can be found. You will need to register with openqa before you start contributing to the WATiN Recorder community. Personally I use Tortoise as my SVN client of choice there are others around, however Tortoise is very cool and extremely easy to use, IMHO streets ahead of the TFS client.

    Up on the openqa server you will find a couple of projects.

    1. The original WATiN Recorder++ which has several bug fixes and some extra bits and bobs.
    2. Builds on the original recorder but rather than spawning a IE browser it uses an embedded IE browser control.
    3. The final project that I have uploaded is a brain dump for getting WATiN to work with Firefox, called FireWATiN. I wanted to investigate if this was possible so there is a test client which uses sockets and jssh.
    I have still to put fit and finish to the wiki but I guessed that you wanted to register and then download the code so that you can start to contribute. I look forward to seeing your contributions and together I am sure that we can creating a great testing tool for all the .Net community to benefit from.

    Enjoy.

    >Rich.

  • WPF Commands a scenic tour part I

    WPF Commands provides a new method for decoupling UI events, the handling of these events and also how you can register multiple UI elements for these defined events.

    When I first came across commands they immediately stood out from the crowd as one of the new baked in features that developers need to use and be aware of, what I found was not a concise and easy to understand guide or examples on how to use them but a frustratingly over complex message. So in this post I am going to attempt to clear the water and bring your attention to the different ways that you can utilise the power of Commands with less pain. I am not going to discuss what they are, but you can read Jelle Druyts blog who has a great post and of course you can dig out your copy of the Gang of Four et al or Head First Design Patterns to remind yourself of the Command Pattern.

    For many years I have used such patterns as MVC and more recently MVP for building applications to provide the levels of separation to help with unit testing and make applications more manageable to build. Personally I have always split the View into what I call a Skin and a Process layer. The Skin contains all code to do with the elements to be presented on the form or page and the Process holds all the UI processing for actions that can be performed by the user.

    Why ? Well I wanted to be able to unit test the UI and this technique provided the right levels of isolation enabling unit tests to be written against the Processing sub layer. At the time I was working for a company that wanted to do white labeling of their product so the UI Skin needed to be flexible, this was achieved using the described methods. However, due to limitations of C# it was not possible to build the cleanest eventing mechanism, and testing the event handling was always tricky to the point of un-testable at times.

    WPF Commands means that you don't need to put this amount of effort in to get the benefits. Commands can be separated and therefore isolated, so that Commands are testable, Commands are localisable (baked in Commands do this for free), baked in Commands provide default key gestures (standard keyboard shortcuts).

    When it comes to implementation then there are really two options, does your implementation require UI interaction, or do you need a non UI Command. If your implementation needs a visual representation then RoutedUICommands are your friend, if you need a non visual commands then you can implement a more structured design by creating custom classes that implement ICommand.

    So we can start the tour off by having a look into the implementation of those RoutedUICommands that are baked into WPF. WPF provides a library of common commands, which include; ApplicationCommands; ComponentCommands; NaviagationCommands; MediaCommands and EditingCommands. These baked in commands make life a lot easier for designers and developers, with a couple of lines of XAML you can associate UI Elements with the baked in command that you want. For example:-

        <UserControl.CommandBindings>
            <CommandBinding Command="MediaCommands.Play" CanExecute="OnQueryExecute" Executed="Execute"/>
            <CommandBinding Command="MediaCommands.Pause" CanExecute="OnQueryExecute" Executed="Execute"/>
            <CommandBinding Command="MediaCommands.Stop" CanExecute="OnQueryExecute" Executed="Execute"/>
        </UserControl.CommandBindings>

    ....

        <StackPanel Grid.Row="2" Orientation="Horizontal">
            <Button Command="MediaCommands.Play" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
            <Button Command="MediaCommands.Pause" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
            <Button Command="MediaCommands.Stop" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
            <Slider Name="Volume" Minimum="0" Maximum="100" Value="{Binding ElementName=Player, Path=Volume}" Width="100" />
        </StackPanel>

    So the baked in commands provide some cool functionality but this is rather specific, what happens when we want to create your own RoutedUICommands. So we come to the most important part of the tour; design your commands before you implement them. The first part is to identify the commands that you are going to need, next categorise these into functional areas of the application that you are building. Chat with your UE person and I am sure that they will be more than willing to help you out.

    I will clear this up with a simple example of an application that has a list view control with add and remove functionality, items selected in the list view are added to another control or removed from the list view control. The user can interactive with this functionality either from a file menu or they can invoke the same two actions from add and remove buttons, or I can use the context menu by right clicking and select the same options. These options can be viewed as library commands in a WPF world allowing the developer to isolate the functionality and provide a consistent look and feel throughout the application. Now that we have identified a simple mechanism for helping group commands, we need to briefly look over how we would have usually implemented these in an application that was not using WPF. Using either a MVC or MVP pattern these events would live in the processing sub layer of the view and this is still the case for WPF, where the difference lies is in the way we implement the event handlers around the application. Due to limitations in C# we would have had to provide a handler that wires up to the event and provide a delegate method that would call the code in the processing sub layer. There are other ways that we could achieve the same result but this would require using multicast delegates and these can be difficult to debug. However, WPF provides the developer/designer with the flexibility to hook up to these commands directly in the XAML or execute them directly in the code behind and this is where you can harness the real power of commands.

    Now let's start cutting some code. Goto your UI project and create a folder called commands, this will be the repository for all your UI commands that we will create whilst building the application. In this folder create yourself a static class called LibraryCommands ensuring that you have a static constructor. For those Library commands that were identified earlier we are now going to create these as private members of our class and provide some public properties to allow outsiders to access the commands. You should have something that looks like this :-

        namespace Conchango.WPF.BrowserApp.UI.Commands
        {
            public static class LibraryCommands
            {
                private static Dispatcher _dispatcher;
                private static RoutedUICommand addCommand = new RoutedUICommand("Add", "add", typeof(LibraryCommands));
                private static RoutedUICommand removeCommand = new RoutedUICommand("Remove", "remove", typeof(LibraryCommands));

           

                public static RoutedUICommands Add
                {
                    return addCommand;
                }


                public static RoutedUICommands Remove
                {
                    return removeCommand;
                }

     

                static LibraryCommands()
                {
                    _dispatcher = Dispatcher.CurrentDispatcher;
                }
            }
        }    

    So far we have created a static class in our UI project, defining a set of library commands for a simple application. We need to take a closer look at the RoutedUICommand constructor; the first parameter is a string description of the command and will be used in the UI and provides the visual representation of the command; the second parameter is the name of the command itself which is used by the framework for serialisation; and the third parameter is ownertype, essentially the owing class for this defined command. There is a certain amount of refactoring that can happen here in regards to the text parameter that we are passing in. I will come back to this later on in the post.

    The other important implementation detail that you need to come to terms with is that the majority of your classes in WPF will be instantiated on the UI thread and therefore have the UI Dispatcher associated with the UI thread. When you do Dispatcher.CurrentDispatcher call you will retrieve an instance of the Dispatcher object for the context of the current thread your code is being run in, which may not be the UI thread. Therefore, a simple and effective work around is to always keep a local copy of the Dispatcher and wire this up in your constructor.

    So the commands that we have defined are looking good however, they are pretty useless at the moment as they are not registered with the Command Manager, who is a rather important when it comes to dealing with commands, it is also rather particular about what parameters that you pass in. So for the moment we are going to register the commands with the application, by adding the line of code to the constructor :-

                 Application.Current.MainWindow.CommandBindings.Add(
                 new CommandBinding(_addCommand, ExecuteAddCommand, CanExecuteAddCommand));

                 Application.Current.MainWindow.CommandBindings.Add(
                 new CommandBinding(_removeCommand, ExecuteRemoveCommand, CanExecuteRemoveCommand));

    The RegisterClassCommandBinding call wires all our hard work together and registers this with the input element in this case I have used a ListView but this could by any element that supports the IInputElement interface. There is a second option that you can use depending on the design that you need, the second option is to register the commands at an application wide level.

    CommandManager.RegisterClassCommandBinding(typeof(ListView), new CommandBinding(_addCommand, ExecuteNavgiateForwardCommand,  CanExecuteNavigateForwardCommand));

    CommandManager.RegisterClassCommandBinding(typeof(ListView), new CommandBinding(_backwardCommand, ExecuteNavgiateBackwardCommand, CanExecuteNavigateBackwardCommand));

     

    Next we need to provide the Execute and CanExcute methods.

         public static void CanExecuteAddCommand(object sender, CanExecuteRoutedEventArgs e)
         {
            // Handler to provide mechanism for determining when the add command can be executed.
            e.Handled = true;
            ......
         }

        public static void CanExecuteRemoveCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            // Handler to provide mechanism for determining when the remove command can be executed.
            e.Handled = true;
            ......
        }

     

        public static void ExecuteAddCommand(object sender, ExecutedRoutedEventArgs e)
        {
            // Handler to actually execute the code to perform the add command
            //add your code here to handle
        }

     
        public static void ExecuteRemoveCommand(object sender, ExecutedRoutedEventArgs e)
        {
            // Handler to actually execute the code to perform the remove command
            //add your code here to handle
        }

    Unfortunately we are coming to the end of the tour and building up to the grand finale. So, just looking back for a moment at the great view; what have we implemented, we have added all the plumbing for the Commands; created the navigational commands that have been identified that are required in the application; and we have also gone a step further and isolated these to a single class ready to be unit tested. The final stage is to add these commands into the XMAL so that they can be used.

    In the XMAL file that will be using the command I have declared the namespace that I want to include:-

    xmlns:conchangoCommand="clr-namespace: Conchango.WPF.BrowserApp.UI.Commands "

    Next add the list view control and define the context menu that we want to use:-

        <ListView Name="AList" Style='{StaticResource MyListStyle}'
             ItemsSource="{Binding Source={StaticResource TestData}}"
            VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            MouseDoubleClick="ListDblClick" >
            <ListView.ContextMenu>
                <ContextMenu>
                <MenuItem
                    Command=" conchangoCommand: LibraryCommands.Add"
                    CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"/>


                <MenuItem
                    Command=" conchangoCommand: LibraryCommands.Remove"
                    CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"/>
                </ContextMenu>

            </ListView.ContextMenu>

    You may have noticed that there is a MouseDoubleClick event handled that I have added to the List View. The user experience that we want to implement allows the user to double click on an item in the List View and the result of the action is that this item is added to another control in the window. The implementation is rather straight forward, WPF provide the flexibility to allow designer or developer to implement commands not only to be used in the XAML but also in the code behind.

            private void ListDblClick(object sender, MouseEventArgs e)
            {
                ListView list = sender as ListView;
                if (list != null)
                {
                    LibraryViewCommands.Add.Execute(list.SelectedItems, list);
                }
            }

    And finally we can also wire up the commands to buttons :-

             <Button Content="Add" Command="{x:Static conchangoCommand: LibraryCommands.Add}" />
             <Button Content="Remove" Command="{x:Static conchangoCommand: LibraryCommands.Remove}" />

    So this brings us to the end of the scenic tour, looking back on the journey I hope that this has helped cleared up the usage of RoutedUICommands and provides the information that you require to implement them in your own applications. Earlier on in the article I mentioned that the implementation of the string description associated with the creation of the command, this can be refactored so that it retrieves this from the Resources of you application.

    In part II I will investigate how to utilise ICommand in your WPF applications.

  • Vista Sidebar Gadget resources

    With the launch of Windows Vista last week, I thought that it would be helpful to put together a list of resources that I have been using to develop Vista Sidebar Gadgets for MSN UK. Stuart has also posted a couple of great articles on Sidebar Gadgets which talk about installing and configuring Gadgets and a second which talks about how to sign your gadgets.

    File paths that you need to know about

    Repository for gadgets on your local pc, replace your user name with mine C:\Users\RGriffin\AppData\Local\Microsoft\Windows Sidebar\Gadgets. Here you will find all the currently installed gadgets.

    If you are using the new RSS platform Object Model then you will also be interested in the Settings.ini file that can be found here at C:\Users\RGriffin\AppData\Local\Microsoft\Windows Sidebar\.

    You will also be interested in the directory C:\Users\RGriffin\AppData\Local\Microsoft\Feeds which contains a FeedsStore.feedsdb-ms, which contains a listing of all your RSS registered feeds, here you will also find and feeds or directories that you have created using the feeds manager.

    Debugging and building your gadgets

    I have been using Visual Studio and Expression Web to build my gadgets. If you are experiencing errors when loading your gadgets you will be able to dive into the code and so long as you have the script explorer window open you will be able see the executed script. If you have been doing Atlas then you will be in a very familiar world. If you want to step through your code and examine certain values of variables, load up your gadget and switch over to Visual Studio. Attach your Visual Studio session to the Sidebar process that is running your gadget, you will then be able to step through the code. One thing to notice here is that when you do this you will see Cassini kick in and away you go.

    One important thing to note here, while debugging your gadget, is to remember that the server will cache your files and changes that you make may not be visible when you next run your gadget. One way around this is to close down Cassini, next go to the sidebar directory and delete the gadget, this will ensure that your code is no longer cached and then reinstall your gadget.

    Links to resources

    Sidebar Gadget APIs

    Sidebar Gadget Dev Manual

    Sidebar Blog

    Examples of the object model

    Windows Sidebar Reference or http://windowssdk.msdn.microsoft.com/en-us/library/ms722795.aspx

    Vista Sidebar Gadgets Persistence Settings

    Microsoft Gadgets

    LiveSide Developer Blog

    Sidebar Gadget Development forum

    OdeToCode Sidebar Gadgets

    Scripting in Widows Vista Part 1

    Sidebar Gadget Development Overview

    I will attempt to maintain this list of resources. For the most up to date listing you can check out http://del.icio.us/grippa.

  • WATiN/R Testing Design Pattern

    Do you want your tests fixtures to look like this ?

     

            [TestMethod]
            public void EnterInvalidUsernameAndPassword()
            {
                //Navigate to home page
               
    IE instance = HomePageManager.NavigatetoHomePage();           

                //Check that there are no items in the basket
               
    if (!BasketManager.ValidateBasketIsEmpty(instance))
                {
                    //if not clear it
                   
    BasketManager.ClearBasketItems(instance);
               

                //Sign out of the session
               
    SignInManager.SignOut(instance);          

                //Attempt a signin with invalid user name
               
    SignInManager.SignIn(instance, "test&tester.com", "fake", true);           

                //make sure that the oops message is visible and the text is correct
               
    Assert.IsTrue(instance.ContainsText("Oops! You made a mistake!"));

                Assert.IsTrue(instance.ContainsText("Please enter a valid email address."));
            }

     

    In this post I will provide a outline for an approach you can use to refactor your tests and create a more maintainable and flexible design to use in your WATiR/N tests.

     

    The WATiR WebRecorder++ and the WATiN WebRecorder++ are great tools that help create test scripts quickly. In the short term they provide the ability to create lightweight test scripts by both the developer and the tester.  The recorders output code so that the user becomes familiar with seeing the language and becomes used to certain constructs in that language. Once the test script has been recorded, verification code is written in the form of asserts to ensure that the required level of functionality is being delivered. Based on these factors, the creation of test fixtures using WATiR/N is a two-stage process consisting of recording and verifying activities.


    With a complex or enterprise web site, the test fixture starts to get rather large, rather quickly, bringing with it management and maintainability issues. When creating tests using this particular approach there are some problems; a large amount of copying and pasting happens as test fixtures start to overlap; resulting in duplicate code for testing components that are reused across the site on different pages; and the navigational code for requesting pages in the site is consistently the same. One way around this is to provide a template that contains the default actions that your test fixture requires, record the test and crank out the verification code, copy this and add the code to the template and stash this away. A simple and effective way to improve productivity as the main parts of the test are predefined and heavily tested so if you test script barfs due to coding errors they are isolated to the new code that has been added to the template, allowing you to isolate the issue and quickly fix the problem.


    The template helps but does not really solve the problems mentioned above. As a programmer we understand that low coupling and high levels of cohesion helps to make the code base easier to manage and maintain. Therefore, why not apply these principles to the test suite.  Therefore, I created a design that would increase cohesion and remove and need to copy and paste code, Don’t Repeat Yourself (DRY). To implement such a design, there needs to be a separation of concerns, by breaking away data, processing logic and test fixture. At this point it is important note that changes to HTML element id’s can cause your test fixture to break, and there is a question of responsibility over the tests. One of the reason that prompted the refactoring of the tests was based on observations that the developers were not owning the tests. So the tester spent more time maintaining existing tests rather than creating new tests scripts. For the moment it is best that we assume all parties are responsible.


    Earlier I identified the three areas to be refactored, data, processing logic and the tests scripts that we want to rinse. Here I am going to classify the id’s and names of HTML elements  as the data part of the puzzle. Each page on the site needs to be mirrored to create a test data object, the data objects are simple property bags containing the id and names of the HTML elements located on the page. By creating this design, it tackles the issues around cohesion mentioned earlier. Having all the names and id’s of elements on the page in one place means that, when there is change on the page updating the variables happens in one place. The result, of the refactoring means that for each page on the web site there is a corresponding property bag class that contains the id’s of HTML elements and a property to access that HTML element.


    The simple base structure, contains an abstract class  Abstract Page that implements an interface IPage. The interface provides the ability to access either a secure or an unsecure web page.  All other data classes that are created are derived from the AbstractPage class and therefore all data classes that are created retain the ability to have a secure and unsecure url’s. To adding a new interface or extending the existing IPage interface you will be able to add the extra functionality you require. The design is about containment and isolation, to allow for the auto generation of implemented pages and page components. The secure and unsecure Url properties are populated from a configuration file so that you can point the test scripts at a particular server with ease. A future enhancement that I would like to introduce is the ability for data classes to be auto generated using a CodeSmith template.


    So now that we have meet the data aspect of the design, we can move on to the reusable logical processing actions of the  design. The functionality that is exposed or expected to be exposed is presented via a manager of the component or page. Therefore, in the current design there is a manager that you speak with to perform an action. The manager uses the data objects to access the HTML elements on the page to perform the task at hand requested. The processing logic is contained within the manager objects, it is here where you define common tasks on a page or component. Once there is duplication or common functionality requirements then this is the place where the code should live.


     

    There is a one to one mapping between the managers and the page or control. Therefore there is a 1 to 1 mapping between the manager and the data class, you will notice that each implementation of the manager class are sealed so that they can’t be extended, they are closed. The next noticeable facet is that each of the managers are thread safe singletons. The managers are created from common code or duplicate code found in the outputted code of the recorder. Such action tasks as, “Login a user with the correct username and password” or a simple action, “navigate to homepage” make up the logical processing. These actions are common and are very reusable, achieving the goal of cohesion and enforcing the separation of concerns that we want from the pattern. They can also be made into your own toolset of controls that after a time provide a comprehensive framework. For instance most web sites that provide a mechanism to order products or service require a login and will have a shopping basket to order and pay for goods. By adding reusable basket testing components to your framework will help you become more productive.


            [TestMethod]
            public void EnterInvalidUsernameAndPassword()
            {
                //Navigate to home page
                IE instance = HomePageManager.NavigatetoHomePage();           

                //Check that there are no items in the basket
               
    if (!BasketManager.ValidateBasketIsEmpty(instance))
                {
                    //if not clear it
                   
    BasketManager.ClearBasketItems(instance);
               

                //Sign out of the session
               
    SignInManager.SignOut(instance);           

                //Attempt a signin with invalid user name
               
    SignInManager.SignIn(instance, "test&tester.com", "fake", true);           

                //make sure that the oops message is visible and the text is correct
               
    Assert.IsTrue(instance.ContainsText("Oops! You made a mistake!"));
                Assert.IsTrue(instance.ContainsText("Please enter a valid email address."));
            }


    The final piece of the puzzle are the test fixtures When using the recorder mechanism it can be easy to hit a curve where the QA person is spending more time doing maintenance tasks rather than creating test fixtures for the site. These test scripts that are produced can be confusing and prone to error caused by copy and pasting code from other areas of the test suite. To provide a solution to this the QA can now write there tests in a more English notation that can be easily read and understood, by a BA or developer. How is this achieved? This is done through the using interactions with the managers of the page and or the managers of component areas of the site to create a test script for a particular area of the system. Allowing the QA / tester  / developer to concentrate more on the creation of the test rather than the maintaining of the test. By designing layers of abstraction test fixtures can build high level readable tests.

     

    The article has covered a mechanism for creating an abstract test design pattern based on using recorders that are commonly available to the development and testing teams. The ability of implementing an abstract design delivers a large amount of reusable code base that can be used on different projects that you work on, and could even be used as benchmarks for new projects starting up that have a similar level of functionality.

  • WATiN web recorder++ prototype

    I am a big fan of Ruby, Rails and WATiR, but I could not help get excited by WATiN. A lightweight port of WATiR that retains much of the original commands. One of the first challenges was to take a WATiR test and convert this to WATiN, however this was not a challenge, it was a breeze.  With the recent publication of the WATiN mappings I thought that it would be really cool to build a simple web recorder to output C# code that can be easily transferable to either an NUnit or a VS2005 unit test.

    The WATiN web recorder is based on the web recorder ++ originally written by Scott Handsleman and Rutger Smit. After hooking up to the sourceforge repository for web recorder++, I got my hands on the code base and started to play. The first bugs to fix were around the marshalling to the UI thread which were causing cross threading exceptions. Once, these were fixed up I moved onto changing the Ruby code to C#, and adding some support for div’s and span’s.
     

     
    The WATiN web recorder is still in its infancy and there are a number of areas where I would like to add richer functionality to the User Experience. The use of a web recorder is a two part phase. The first is the recording of the tests that allow the navigation to a particular area, the second stage is the <