<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-1384551653506604356</atom:id><lastBuildDate>Sun, 22 Nov 2009 20:09:38 +0000</lastBuildDate><title>GUI Automated Testing</title><description>and other interesting topics</description><link>http://gui-at.blogspot.com/</link><managingEditor>noreply@blogger.com (Lukáš Čenovský)</managingEditor><generator>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-1197273637537051751</guid><pubDate>Sun, 22 Nov 2009 19:28:00 +0000</pubDate><atom:updated>2009-11-22T21:00:00.610+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><category domain='http://www.blogger.com/atom/ns#'>clrtype</category><category domain='http://www.blogger.com/atom/ns#'>wcf</category><title>WCF Service in pure IronPython with config file</title><description>I was wrong when I wrote in the &lt;a href="http://gui-at.blogspot.com/2009/11/wcf-service-in-pure-ironpython.html"&gt;last post&lt;/a&gt; that the IronPython service cannot be saved into an assembly. It can. Which opens a way to use &lt;i&gt;.config&lt;/i&gt; file to configure the service.&lt;br /&gt;&lt;br /&gt;This is a simple config file for the service:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.exe.config"&gt;ConfigService.exe.config&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.serviceModel&gt;&lt;br /&gt;    &lt;services&gt;&lt;br /&gt;      &lt;service name="ConfigService.myService"&gt;&lt;br /&gt;        &lt;host&gt;&lt;br /&gt;          &lt;baseaddresses&gt;&lt;br /&gt;            &lt;add baseAddress="http://localhost:9000/myWcfService"/&gt;&lt;br /&gt;          &lt;/baseAddresses&gt;&lt;br /&gt;        &lt;/host&gt;&lt;br /&gt;        &lt;endpoint address=""&lt;br /&gt;            binding="basicHttpBinding"&lt;br /&gt;            contract="TestServiceInterface.ImyService"/&gt;&lt;br /&gt;      &lt;/service&gt;&lt;br /&gt;    &lt;/services&gt;&lt;br /&gt;  &lt;/system.serviceModel&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;a href="http://gui-at.cendaweb.cz/2009/11/TestServiceInterface.py"&gt;interface&lt;/a&gt; is the same as in the previous version. The only difference in the service to the previous version is in the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt; ServiceHost&lt;/span&gt; initialization - we omit the service configuration parameters because they are in the &lt;i&gt;.config&lt;/i&gt; file. I also changed the clr namespace:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.py"&gt;ConfigService.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;import clrtype&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;from System import Console, Uri&lt;br /&gt;from System.ServiceModel import (ServiceHost,&lt;br /&gt;        BasicHttpBinding, ServiceBehaviorAttribute,&lt;br /&gt;        InstanceContextMode)&lt;br /&gt;&lt;br /&gt;class myService(ImyService):&lt;br /&gt;    __metaclass__ = clrtype.ClrClass&lt;br /&gt;    _clrnamespace = "ConfigService"&lt;br /&gt;    _clrclassattribs = [ServiceBehaviorAttribute]&lt;br /&gt;&lt;br /&gt;    def GetData(self, value):&lt;br /&gt;        return "IronPython config service: You entered: %s" % value&lt;br /&gt;&lt;br /&gt;sh = ServiceHost(myService)&lt;br /&gt;sh.Open()&lt;br /&gt;Console.WriteLine("Press &lt;enter&gt; to terminate\n")&lt;br /&gt;Console.ReadLine()&lt;br /&gt;sh.Close()&lt;/pre&gt;&lt;br /&gt;If you want to run this script, you must save the &lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.exe.config"&gt;ConfigService.exe.config&lt;/a&gt; as &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ipy.exe.config&lt;/span&gt; to the folder with the IronPython interpreter &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt; ipy.exe&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;To save the service as an assembly, run the following command: &lt;pre class="brush:text"&gt;C:\IronPython-2.6\ipy.exe C:\IronPython-2.6\Tools\Scripts\pyc.py  /out:ConfigService /target:exe /main:ConfigService.py clrtype.py TestServiceInterface.py&lt;/pre&gt;The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigService.dll&lt;/span&gt; and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigService.exe&lt;/span&gt; are created. Add the &lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.exe.config"&gt;ConfigService.exe.config&lt;/a&gt; to the same folder and when you run &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigService.exe&lt;/span&gt;, the service starts. Note you also need all IronPython .dlls in the same folder.&lt;br /&gt;&lt;br /&gt;You can adjust the .config file to expose a MEX endpoint (&lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.mex.exe.config"&gt;ConfigService.mex.exe.config&lt;/a&gt;) but I don't see a big point in it because svcutil.exe generates C# or VB code. Anyway - here are the generated files: &lt;a href="http://gui-at.cendaweb.cz/2009/11/myService.cs"&gt;myService.cs&lt;/a&gt;, &lt;a href="http://gui-at.cendaweb.cz/2009/11/myService.config"&gt;myService.config&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can run the old &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;TestClient.py&lt;/span&gt; and it will successfully retrieve value from the service. But the old &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;TestClient.py&lt;/span&gt; does not use &lt;i&gt;.config&lt;/i&gt; file. If we want to use &lt;i&gt;.config&lt;/i&gt; file for the client, we have to rewrite the WCF client. First, here is the sample client &lt;i&gt;.config&lt;/i&gt; file:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigClient.exe.config"&gt;ConfigClient.exe.config&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:xml"&gt;&lt;?xml version="1.0"?&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;  &lt;system.serviceModel&gt;&lt;br /&gt;    &lt;client&gt;&lt;br /&gt;        &lt;endpoint address="http://localhost:9000/myWcfService"&lt;br /&gt;            binding="basicHttpBinding"&lt;br /&gt;            contract="TestServiceInterface.ImyService"/&gt;&lt;br /&gt;    &lt;/client&gt;&lt;br /&gt;  &lt;/system.serviceModel&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;br /&gt;You can see it is very similar to the &lt;a href="http://gui-at.cendaweb.cz/2009/11/myService.config"&gt;generated one&lt;/a&gt;. We do not specify details of the binding but we specify full name of the contract interface.&lt;br /&gt;&lt;br /&gt;If you check the &lt;a href="http://gui-at.cendaweb.cz/2009/11/myService.cs"&gt;generated client proxy class&lt;/a&gt; by svcutil.exe, you see it is based on &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt; System.ServiceModel.ClientBase&lt;/span&gt; and the interface &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ImyService&lt;/span&gt;. There are some empty constructors and all methods from &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ImyService&lt;/span&gt; interface return result of the same method name call on &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Channel&lt;/span&gt; property. That's why I have created &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;WcfClient&lt;/span&gt; helper function. The client source then looks like the following:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigService.py"&gt;ConfigService.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;import System.ServiceModel&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;&lt;br /&gt;def WcfClient(interface):&lt;br /&gt;&lt;br /&gt;    class WcfClientBase(System.ServiceModel.ClientBase[interface]):&lt;br /&gt;&lt;br /&gt;        def __getattr__(self, name):&lt;br /&gt;            # if name is method from interface, return the Channel method&lt;br /&gt;            if name in (k[0] for k in interface.emitted_methods.keys()):&lt;br /&gt;                return getattr(self.Channel, name)&lt;br /&gt;&lt;br /&gt;    return WcfClientBase()&lt;br /&gt;&lt;br /&gt;wcfcli = WcfClient(ImyService)&lt;br /&gt;print "WCF config client returned:\n%s" % wcfcli.GetData(11)&lt;/pre&gt;&lt;br /&gt;The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;WcfClient&lt;/span&gt; helper function returns an instance of class based on &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt; System.ServiceModel.ClientBase&lt;/span&gt;. The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;__getattr__&lt;/span&gt; checks if the requested attribute name is interface method and if so, it returns the Channel's method with the same name. Which is the same behavior as the generated client proxy class in couple of lines of code.&lt;br /&gt;&lt;br /&gt;To save the client as an assembly, run the following command:&lt;pre class="brush:text"&gt;C:\IronPython-2.6\ipy.exe C:\IronPython-2.6\Tools\Scripts\pyc.py   /out:ConfigClient /target:exe /main:ConfigClient.py clrtype.py TestServiceInterface.py&lt;/pre&gt;The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigClient.dll&lt;/span&gt; and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigClient.exe&lt;/span&gt; are created. Add the &lt;a href="http://gui-at.cendaweb.cz/2009/11/ConfigClient.exe.config"&gt;ConfigClient.exe.config&lt;/a&gt; to the same folder and when you run &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ConfigClient.exe&lt;/span&gt;, the client calls the service.&lt;br /&gt;&lt;br /&gt;Having this I think there is only a small step to use the IronPython WCF services in IIS. Unfortunately, I do not know how to do it...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-1197273637537051751?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/11/wcf-service-in-pure-ironpython-with.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-4628222184874447225</guid><pubDate>Tue, 17 Nov 2009 12:07:00 +0000</pubDate><atom:updated>2009-11-22T21:09:38.945+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><category domain='http://www.blogger.com/atom/ns#'>clrtype</category><category domain='http://www.blogger.com/atom/ns#'>wcf</category><title>WCF Service in pure IronPython</title><description>I wrote about implementing WCF service in IronPython &lt;a href="http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html"&gt;a couple of weeks ago&lt;/a&gt;. Meanwhile I pushed Shri a little bit with the &lt;a href="http://gui-at.cendaweb.cz/2009/11/clrtype.py"&gt;clrtype.py&lt;/a&gt; and he has implemented &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ClrInterface&lt;/span&gt; metaclass there so we can create the whole WCF service in IronPython now.&lt;br /&gt;&lt;br /&gt;The IronPython interface implementation is straightforward:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/TestServiceInterface.py"&gt;TestServiceInterface.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;import clrtype&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;from System.ServiceModel import (&lt;br /&gt;        ServiceContractAttribute,&lt;br /&gt;        OperationContractAttribute)&lt;br /&gt;OperationContract = clrtype.attribute(&lt;br /&gt;        OperationContractAttribute)&lt;br /&gt;&lt;br /&gt;class ImyService(object):&lt;br /&gt;    __metaclass__ = clrtype.ClrInterface&lt;br /&gt;    _clrnamespace = "TestServiceInterface"&lt;br /&gt;    _clrclassattribs = [ServiceContractAttribute]&lt;br /&gt;&lt;br /&gt;    @OperationContract()&lt;br /&gt;    @clrtype.accepts(int)&lt;br /&gt;    @clrtype.returns(str)&lt;br /&gt;    def GetData(self, value):&lt;br /&gt;        raise RuntimeError("this should not get called")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Also switching from C# interface to IronPython interface is easy:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/TestService.py"&gt;TestService.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;import clrtype&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;from System import Console, Uri&lt;br /&gt;from System.ServiceModel import (ServiceHost,&lt;br /&gt;        BasicHttpBinding, ServiceBehaviorAttribute,&lt;br /&gt;        InstanceContextMode)&lt;br /&gt;&lt;br /&gt;class myService(ImyService):&lt;br /&gt;    __metaclass__ = clrtype.ClrClass&lt;br /&gt;    _clrnamespace = "myWcfService"&lt;br /&gt;    _clrclassattribs = [ServiceBehaviorAttribute]&lt;br /&gt;&lt;br /&gt;    def GetData(self, value):&lt;br /&gt;        return "IronPython: You entered: %s" % value&lt;br /&gt;&lt;br /&gt;sh = ServiceHost(myService, Uri(&lt;br /&gt;        "http://localhost:9000/myWcfService"))&lt;br /&gt;sh.AddServiceEndpoint(clr.GetClrType(ImyService),&lt;br /&gt;        BasicHttpBinding(), "")&lt;br /&gt;sh.Open()&lt;br /&gt;Console.WriteLine("Press &lt;enter&gt; to terminate\n")&lt;br /&gt;Console.ReadLine()&lt;br /&gt;sh.Close()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notice that we call &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ServiceHost&lt;/span&gt; with &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;myService&lt;/span&gt; which is the type and not the instance of our service. Because of this, the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ServiceBehavior&lt;/span&gt; attribute does not need to have &lt;i&gt;InstanceContextMode.Single&lt;/i&gt; parameter.&lt;br /&gt;&lt;br /&gt;Finally, here is the test client:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/TestClient.py"&gt;TestClient.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;import System.ServiceModel&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;&lt;br /&gt;mycf = System.ServiceModel.ChannelFactory[ImyService](&lt;br /&gt;        System.ServiceModel.BasicHttpBinding(),&lt;br /&gt;        System.ServiceModel.EndpointAddress(&lt;br /&gt;            "http://localhost:9000/myWcfService"))&lt;br /&gt;wcfcli = mycf.CreateChannel()&lt;br /&gt;print "WCF service returned:\n%s" % wcfcli.GetData(11)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The disadvantage of having just a single service instance is gone, &lt;strike&gt;the harder configuration remains&lt;/strike&gt;. One new disadvantage can be &lt;strike&gt;it is not possible (yet) to compile the interface and save it to disk&lt;/strike&gt; nor use it from other .NET languages.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Edit 22. 11. 2009:&lt;/b&gt; See &lt;a href="http://gui-at.blogspot.com/2009/11/wcf-service-in-pure-ironpython-with.html"&gt;WCF Service in pure IronPython with config file&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-4628222184874447225?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/11/wcf-service-in-pure-ironpython.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-8502552386187992808</guid><pubDate>Mon, 16 Nov 2009 10:14:00 +0000</pubDate><atom:updated>2009-11-17T13:16:15.204+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>silverlight</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><category domain='http://www.blogger.com/atom/ns#'>clrtype</category><title>INotifyPropertyChanged and databinding in Silverlight</title><description>In the &lt;a href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html"&gt;previous article&lt;/a&gt;, I wrote about IronPython and databinding in WPF applications. The last note was it does not work in Silverlight. Thanks to Shri Borde (IronPython/IronRuby dev lead) who updated &lt;a href="http://gui-at.cendaweb.cz/2009/11/clrtype.py"&gt;clrtype&lt;/a&gt; module, the note is not true any more.&lt;br /&gt;&lt;br /&gt;Let's create a small Silverlight app in IronPython from scratch. I use IronPython 2.6 RC2. Follow &lt;a href="http://lists.ironpython.com/pipermail/users-ironpython.com/2009-October/011543.html"&gt;http://lists.ironpython.com/pipermail/users-ironpython.com/2009-October/011543.html&lt;/a&gt; to avoid bugs in IronPython 2.6 RC2.&lt;br /&gt;&lt;br /&gt;Create a new project:&lt;br /&gt;&lt;pre class="brush:text"&gt;C:\IronPython-2.6\Silverlight\script\sl.bat python BindTest&lt;/pre&gt;Change the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;app.xaml&lt;/span&gt; to&lt;br /&gt;&lt;pre class="brush:xml"&gt;&lt;usercontrol x:Class="System.Windows.Controls.UserControl"&lt;br /&gt;    xmlns="http://schemas.microsoft.com/client/2007"&lt;br /&gt;    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;&lt;br /&gt;    &lt;stackpanel x:Name="DataPanel"&lt;br /&gt;        Orientation="Horizontal"&gt;&lt;br /&gt;        &lt;textblock Text="Size"/&gt;&lt;br /&gt;        &lt;textblock Text="{Binding size}"/&gt;&lt;br /&gt;        &lt;textbox x:Name="tbSize"&lt;br /&gt;            Text="{Binding size, Mode=TwoWay}" /&gt;&lt;br /&gt;        &lt;button x:Name="Button"&lt;br /&gt;            Content="Set Initial Value"&gt;&lt;/Button&gt;&lt;br /&gt;    &lt;/StackPanel&gt;&lt;br /&gt;&lt;/UserControl&gt;&lt;/pre&gt;The difference comparing to &lt;a href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html"&gt;WPF version&lt;/a&gt; is we have to specify binding mode because the default mode for TextBox in Silverlight is &lt;i&gt;OneWay&lt;/i&gt;. And we cannot use &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt; UpdateSourceTrigger=PropertyChanged&lt;/span&gt; because Silverlight does not have such &lt;i&gt;UpdateSourceTrigger&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Silverlight binding is limited comparing to WPF. That's why we have to create &lt;i&gt;CLR properties&lt;/i&gt; to Silverlight be able to see them. DevHawk has a nice serie about clr types on his &lt;a href="http://devhawk.net/CategoryView,category,__clrtype__.aspx"&gt;blog&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Creating CLR property with &lt;a href="http://gui-at.cendaweb.cz/2009/11/clrtype.py"&gt;clrtype.py&lt;/a&gt; is easy. Shri described it on IronPython &lt;a href="http://lists.ironpython.com/pipermail/users-ironpython.com/2009-November/011659.html"&gt;mailing list&lt;/a&gt;. Because I use my enhanced &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;@notify_property&lt;/span&gt; decorator, I can write:&lt;br /&gt;&lt;pre class="brush:python"&gt;class ViewModel(NotifyPropertyChangedBase):&lt;br /&gt;    __metaclass__ = clrtype.ClrClass&lt;br /&gt;    _clrnamespace = "BindTest"&lt;br /&gt;    &lt;br /&gt;    def __init__(self):&lt;br /&gt;        super(ViewModel, self).__init__()&lt;br /&gt;        # must be string to two-way binding work&lt;br /&gt;        # correctly&lt;br /&gt;        self.size = '10'&lt;br /&gt;&lt;br /&gt;    @notify_property&lt;br /&gt;    @clrtype.returns(str)&lt;br /&gt;    def size(self):&lt;br /&gt;        return self._size&lt;br /&gt;&lt;br /&gt;    @size.setter&lt;br /&gt;    @clrtype.accepts(str)&lt;br /&gt;    def size(self, value):&lt;br /&gt;        self._size = value&lt;br /&gt;        print 'Size changed to %r' % self.size&lt;/pre&gt;The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;NotifyPropertyChangedBase&lt;/span&gt; class is the same as for &lt;a href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html"&gt;WPF version&lt;/a&gt;. The enhanced &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;@notify_property&lt;/span&gt; decorator calls automatically &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clrtype.accepts()&lt;/span&gt; for getter and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clrtype.returns()&lt;/span&gt; for setter so we do not need to call them manually for every property:&lt;br /&gt;&lt;pre class="brush:python"&gt;class notify_property(property):&lt;br /&gt;&lt;br /&gt;    def __init__(self, getter):&lt;br /&gt;        def newgetter(slf):&lt;br /&gt;            #return None when the property does not&lt;br /&gt;            # exist yet&lt;br /&gt;            try:&lt;br /&gt;                return getter(slf)&lt;br /&gt;            except AttributeError:&lt;br /&gt;                return None&lt;br /&gt;        getter = clrtype.accepts()(getter)&lt;br /&gt;        clrtype.propagate_attributes(getter, newgetter)&lt;br /&gt;        super(notify_property, self).__init__(newgetter)&lt;br /&gt;&lt;br /&gt;    def setter(self, setter):&lt;br /&gt;        def newsetter(slf, newvalue):&lt;br /&gt;            # do not change value if the new value is&lt;br /&gt;            # the same, trigger PropertyChanged event&lt;br /&gt;            # when value changes&lt;br /&gt;            oldvalue = self.fget(slf)&lt;br /&gt;            if oldvalue != newvalue:&lt;br /&gt;                setter(slf, newvalue)&lt;br /&gt;                slf.OnPropertyChanged(setter.__name__)&lt;br /&gt;        setter = clrtype.returns()(setter)&lt;br /&gt;        clrtype.propagate_attributes(setter, newsetter)&lt;br /&gt;        return property(&lt;br /&gt;            fget=self.fget,&lt;br /&gt;            fset=newsetter,&lt;br /&gt;            fdel=self.fdel,&lt;br /&gt;            doc=self.__doc__)&lt;/pre&gt;Then &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;App&lt;/span&gt; looks similarly to the &lt;a href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html"&gt;WPF counterpart&lt;/a&gt;:&lt;br /&gt;&lt;pre class="brush:python"&gt;class App:&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self._vm = ViewModel()&lt;br /&gt;        self.root = Application.Current.LoadRootVisual(&lt;br /&gt;                UserControl(), "app.xaml")&lt;br /&gt;        self.DataPanel.DataContext = self._vm&lt;br /&gt;        self.Button.Click += self.OnClick&lt;br /&gt;&lt;br /&gt;    def OnClick(self, sender, event):&lt;br /&gt;        # must be string to two-way binding work&lt;br /&gt;        # correctly&lt;br /&gt;        self._vm.size = '10'&lt;br /&gt;&lt;br /&gt;    def __getattr__(self, name):&lt;br /&gt;        # provides easy access to XAML elements&lt;br /&gt;        # (e.g. self.Button)&lt;br /&gt;        return self.root.FindName(name)&lt;br /&gt;&lt;br /&gt;a = App()&lt;/pre&gt;Run Chiron with the &lt;i&gt;BindTest&lt;/i&gt; app&lt;br /&gt;&lt;pre class="brush:text"&gt;C:\IronPython-2.6\Silverlight\script\sl.bat python BindTest&lt;/pre&gt;and check the application in the browser on &lt;a href="http://localhost:2060/index.html"&gt; http://localhost:2060/index.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Whatever you write into the text box appears in the label in front of the text box when the text box loses the focus. When you click the button, the value is reseted. You can also change the value from the console:&lt;br /&gt;&lt;pre class="brush:python"&gt;a._vm.size= '3'&lt;/pre&gt;&lt;br /&gt;Download &lt;a href="http://gui-at.cendaweb.cz/2009/11/app.xaml"&gt;app.xaml&lt;/a&gt; and &lt;a href="http://gui-at.cendaweb.cz/2009/11/app.py"&gt;app.py&lt;/a&gt;. You also need &lt;a href="http://gui-at.cendaweb.cz/2009/11/clrtype.py"&gt;clrtype.py&lt;/a&gt; and pyevent.py (from C:\IronPython-2.6\Tutorial\pyevent.py) in the &lt;i&gt;BindTest&lt;/i&gt; folder.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-8502552386187992808?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databinding.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-26309250501982853</guid><pubDate>Wed, 11 Nov 2009 11:22:00 +0000</pubDate><atom:updated>2009-11-22T20:29:37.924+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>wpf</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><category domain='http://www.blogger.com/atom/ns#'>clrtype</category><title>INotifyPropertyChanged and databinding in IronPython WPF</title><description>&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx"&gt;INotifyPropertyChanged&lt;/a&gt; is important interface for building WPF or Silverlight applications using &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;M-V-VM concept&lt;/a&gt; (&lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;MSDN article&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;In simple language, you have a &lt;b&gt;Model&lt;/b&gt; which provides access to your data (e.g in database, files, web, etc.). Then you have a &lt;b&gt;ViewModel&lt;/b&gt; that access data in the Model via Model's interface and provides data to a &lt;b&gt;View&lt;/b&gt; which is XAML file with UI layout. Linkage between ViewModel and View is done by binding that utilizes &lt;i&gt;PropertyChanged&lt;/i&gt; event to properly update all UI elements.&lt;br /&gt;&lt;br /&gt;I have found two examples how to implement &lt;i&gt;INotifyPropertyChanged&lt;/i&gt; interface in IronPython. &lt;a href="http://lists.ironpython.com/pipermail/users-ironpython.com/2009-August/010938.html"&gt;The first one&lt;/a&gt; uses __setattr__ hook. Personally, I don't like it - it is not clear and easily readable code. &lt;a href="http://palepoli.skr.jp/wp/2009/06/28/wpf-listview-databinding-for-ironpython/"&gt;The second one&lt;/a&gt; is better because it uses properties. But you have to write &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;self.OnPropertyChanged("my_property_name")&lt;/span&gt; for every property. Not ideal.&lt;br /&gt;&lt;br /&gt;That's why I sit down and write a &lt;b&gt;notify_property&lt;/b&gt;:&lt;br /&gt;&lt;pre class="brush:python"&gt;class notify_property(property):&lt;br /&gt;&lt;br /&gt;    def __init__(self, getter):&lt;br /&gt;        def newgetter(slf):&lt;br /&gt;            try:&lt;br /&gt;                return getter(slf)&lt;br /&gt;            except AttributeError:&lt;br /&gt;                return None&lt;br /&gt;        super(notify_property, self).__init__(newgetter)&lt;br /&gt;&lt;br /&gt;    def setter(self, setter):&lt;br /&gt;        def newsetter(slf, newvalue):&lt;br /&gt;            oldvalue = self.fget(slf)&lt;br /&gt;            if oldvalue != newvalue:&lt;br /&gt;                setter(slf, newvalue)&lt;br /&gt;                slf.OnPropertyChanged(setter.__name__)&lt;br /&gt;        return property(&lt;br /&gt;            fget=self.fget,&lt;br /&gt;            fset=newsetter,&lt;br /&gt;            fdel=self.fdel,&lt;br /&gt;            doc=self.__doc__)&lt;/pre&gt;With this subclass I aimed several goals:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;usage simple as &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;@property&lt;/span&gt; decorator (actualy no other usage is possible as I implemented &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;__init__&lt;/span&gt; with just one parameter that must be the getter)&lt;/li&gt;&lt;li&gt;when property is on yet defined, it should return &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;None&lt;/span&gt;&lt;/li&gt;&lt;li&gt;automaticaly handle &lt;i&gt;PropertyChanged&lt;/i&gt; event when and only when property has changed&lt;/li&gt;&lt;/ul&gt;We also need to implement &lt;i&gt;INotifyPropertyChanged&lt;/i&gt; interface in IronPython so we can call &lt;i&gt;OnPropertyChanged&lt;/i&gt; method. See &lt;i&gt;Overiding events&lt;/i&gt; in IronPython\Doc\dotnet-integration.rst to understand what means &lt;i&gt;add_&lt;/i&gt; and &lt;i&gt;remove_&lt;/i&gt; methods.&lt;br /&gt;&lt;pre class="brush:python"&gt;class NotifyPropertyChangedBase(INotifyPropertyChanged):&lt;br /&gt;    PropertyChanged = None&lt;br /&gt;&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.PropertyChanged, self._propertyChangedCaller = pyevent.make_event()&lt;br /&gt;&lt;br /&gt;    def add_PropertyChanged(self, value):&lt;br /&gt;        self.PropertyChanged += value&lt;br /&gt;&lt;br /&gt;    def remove_PropertyChanged(self, value):&lt;br /&gt;        self.PropertyChanged -= value&lt;br /&gt;&lt;br /&gt;    def OnPropertyChanged(self, propertyName):&lt;br /&gt;        if self.PropertyChanged is not None:&lt;br /&gt;            self._propertyChangedCaller(self, PropertyChangedEventArgs(propertyName))&lt;/pre&gt;Now we can implement a simple class with properties with change notification:&lt;br /&gt;&lt;pre class="brush:python"&gt;class DataObject(NotifyPropertyChangedBase):&lt;br /&gt;    &lt;br /&gt;    def __init__(self, size):&lt;br /&gt;        super(DataObject, self).__init__()&lt;br /&gt;        self.size = size&lt;br /&gt;&lt;br /&gt;    @notify_property&lt;br /&gt;    def size(self):&lt;br /&gt;        return self._size&lt;br /&gt;&lt;br /&gt;    @size.setter&lt;br /&gt;    def size(self, value):&lt;br /&gt;        self._size = value&lt;/pre&gt;You can see it is very easy - just like any other property in Python.&lt;br /&gt;&lt;br /&gt;Finaly, let's put all together. When you run the code below, it shows a window with label, textbox and button. The label is updated as you type into the textbox and a message is written into the console as well. By default, the textbox is updated when it looses focus, so I have to change &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;UpdateSourceTrigger&lt;/span&gt; to &lt;i&gt;PropertyChanged&lt;/i&gt;. When you click the button, the value is reset. Note if you use type &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;int&lt;/span&gt; instead of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;string&lt;/span&gt; the two-way bindign would not work.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/11/notpropwpf.py"&gt;notpropwpf.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;import System&lt;br /&gt;clr.AddReference('PresentationFramework')&lt;br /&gt;clr.AddReference('PresentationCore')&lt;br /&gt;&lt;br /&gt;from System.Windows.Markup import XamlReader&lt;br /&gt;from System.Windows import Application, Window&lt;br /&gt;from System.ComponentModel import INotifyPropertyChanged, PropertyChangedEventArgs&lt;br /&gt;import pyevent&lt;br /&gt;&lt;br /&gt;XAML_str = """&lt;window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;br /&gt;    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="250" Height="62"&gt;&lt;br /&gt;    &lt;stackpanel x:Name="DataPanel" Orientation="Horizontal"&gt;&lt;br /&gt;        &lt;label Content="Size"/&gt;&lt;br /&gt;        &lt;label Content="{Binding size}"/&gt;&lt;br /&gt;        &lt;textbox x:Name="tbSize" Text="{Binding size, UpdateSourceTrigger=PropertyChanged}" /&gt;&lt;br /&gt;        &lt;button x:Name="Button" Content="Set Initial Value"&gt;&lt;/Button&gt;&lt;br /&gt;    &lt;/StackPanel&gt;&lt;br /&gt;&lt;/Window&gt;"""&lt;br /&gt;&lt;br /&gt;class notify_property(property):&lt;br /&gt;&lt;br /&gt;    def __init__(self, getter):&lt;br /&gt;        def newgetter(slf):&lt;br /&gt;            #return None when the property does not exist yet&lt;br /&gt;            try:&lt;br /&gt;                return getter(slf)&lt;br /&gt;            except AttributeError:&lt;br /&gt;                return None&lt;br /&gt;        super(notify_property, self).__init__(newgetter)&lt;br /&gt;&lt;br /&gt;    def setter(self, setter):&lt;br /&gt;        def newsetter(slf, newvalue):&lt;br /&gt;            # do not change value if the new value is the same&lt;br /&gt;            # trigger PropertyChanged event when value changes&lt;br /&gt;            oldvalue = self.fget(slf)&lt;br /&gt;            if oldvalue != newvalue:&lt;br /&gt;                setter(slf, newvalue)&lt;br /&gt;                slf.OnPropertyChanged(setter.__name__)&lt;br /&gt;        return property(&lt;br /&gt;            fget=self.fget,&lt;br /&gt;            fset=newsetter,&lt;br /&gt;            fdel=self.fdel,&lt;br /&gt;            doc=self.__doc__)&lt;br /&gt;&lt;br /&gt;class NotifyPropertyChangedBase(INotifyPropertyChanged):&lt;br /&gt;    PropertyChanged = None&lt;br /&gt;&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self.PropertyChanged, self._propertyChangedCaller = pyevent.make_event()&lt;br /&gt;&lt;br /&gt;    def add_PropertyChanged(self, value):&lt;br /&gt;        self.PropertyChanged += value&lt;br /&gt;&lt;br /&gt;    def remove_PropertyChanged(self, value):&lt;br /&gt;        self.PropertyChanged -= value&lt;br /&gt;&lt;br /&gt;    def OnPropertyChanged(self, propertyName):&lt;br /&gt;        if self.PropertyChanged is not None:&lt;br /&gt;            self._propertyChangedCaller(self, PropertyChangedEventArgs(propertyName))&lt;br /&gt;&lt;br /&gt;class ViewModel(NotifyPropertyChangedBase):&lt;br /&gt;    &lt;br /&gt;    def __init__(self):&lt;br /&gt;        super(ViewModel, self).__init__()&lt;br /&gt;        # must be string to two-way binding work correctly&lt;br /&gt;        self.size = '10'&lt;br /&gt;&lt;br /&gt;    @notify_property&lt;br /&gt;    def size(self):&lt;br /&gt;        return self._size&lt;br /&gt;&lt;br /&gt;    @size.setter&lt;br /&gt;    def size(self, value):&lt;br /&gt;        self._size = value&lt;br /&gt;        print 'Size changed to %r' % self.size&lt;br /&gt;&lt;br /&gt;class TestWPF(object):&lt;br /&gt;&lt;br /&gt;    def __init__(self):&lt;br /&gt;        self._vm = ViewModel()&lt;br /&gt;        self.root = XamlReader.Parse(XAML_str)&lt;br /&gt;        self.DataPanel.DataContext = self._vm&lt;br /&gt;        self.Button.Click += self.OnClick&lt;br /&gt;        &lt;br /&gt;    def OnClick(self, sender, event):&lt;br /&gt;        # must be string to two-way binding work correctly&lt;br /&gt;        self._vm.size = '10'&lt;br /&gt;&lt;br /&gt;    def __getattr__(self, name):&lt;br /&gt;        # provides easy access to XAML elements (e.g. self.Button)&lt;br /&gt;        return self.root.FindName(name)&lt;br /&gt;&lt;br /&gt;tw = TestWPF()&lt;br /&gt;app = Application()&lt;br /&gt;app.Run(tw.root)&lt;/pre&gt;You need pyevent.py from IronPython\Tutorial\ folder to run to example.&lt;br /&gt;&lt;br /&gt;Unfortunately, this does not work in Silverlight, probably because the property is not .NET field.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-26309250501982853?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-3556934013257617305</guid><pubDate>Fri, 30 Oct 2009 17:08:00 +0000</pubDate><atom:updated>2009-11-17T13:17:46.870+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><category domain='http://www.blogger.com/atom/ns#'>clrtype</category><category domain='http://www.blogger.com/atom/ns#'>wcf</category><title>WCF Service in IronPython</title><description>&lt;b&gt;Edit 17. 11. 2009:&lt;/b&gt; See the article about &lt;a href="http://gui-at.blogspot.com/2009/11/wcf-service-in-pure-ironpython.html"&gt;WCF service in pure IronPython&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Until IronPython 2.6, it was not possible to create WCF service host in pure IronPython. The closest way was to create stub in C# and &lt;a href="http://www.voidspace.org.uk/ironpython/dynamically_compiling.shtml#subclassing-in-ironpython"&gt;subclass it in IronPython&lt;/a&gt; or create the whole service in C# and &lt;a href="http://www.darrellhawley.com/2009/03/writing-ironpython-wcf-host.html"&gt;run it from IronPython&lt;/a&gt;. It is now much simpler with IronPython 2.6 although you still have to write a little C# code.&lt;br /&gt;&lt;br /&gt;Simple WCF service implemented in C# looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/10/TestServiceInterface.cs"&gt;TestServiceInterface.cs&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:c#"&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace TestServiceInterface&lt;br /&gt;{&lt;br /&gt;    [ServiceContract]&lt;br /&gt;    public interface ImyService&lt;br /&gt;    {&lt;br /&gt;        [OperationContract]&lt;br /&gt;        string GetData(int value);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/10/TestService.cs"&gt;TestService.cs&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:c#"&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;using TestServiceInterface;&lt;br /&gt;&lt;br /&gt;namespace myWcfService&lt;br /&gt;{&lt;br /&gt;    public class myService : ImyService&lt;br /&gt;    {&lt;br /&gt;        public string GetData(int value)&lt;br /&gt;        {&lt;br /&gt;            return string.Format("You entered: {0}", value);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public class mySvc&lt;br /&gt;    {&lt;br /&gt;        public static void Main()&lt;br /&gt;        {&lt;br /&gt;            ServiceHost sh = new ServiceHost(&lt;br /&gt;     typeof(myService),&lt;br /&gt;     new Uri("http://localhost:9000/myWcfService"));&lt;br /&gt;   sh.AddServiceEndpoint(&lt;br /&gt;     typeof(ImyService),&lt;br /&gt;     new BasicHttpBinding(),&lt;br /&gt;        "");&lt;br /&gt;            sh.Open();&lt;br /&gt;            Console.WriteLine("Press &lt;enter&gt; to terminate\n");&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;            sh.Close();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You build it:&lt;br /&gt;&lt;pre class="brush:plain"&gt;csc /target:library TestServiceInterface.cs&lt;br /&gt;csc /r:TestServiceInterface.dll TestService.cs&lt;/pre&gt;&lt;br /&gt;The reason I put &lt;i&gt;TestServiceInterface&lt;/i&gt; into separate file is that you cannot create interfaces in IronPython. So this is the only part written in C# when implementig WCF service in IronPython.&lt;br /&gt;&lt;br /&gt;The implementation then looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/10/TestService.py"&gt;TestService.py&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;import clrtype&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;clr.AddReference('TestServiceInterface')&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;from System import Console, Uri&lt;br /&gt;from System.ServiceModel import (ServiceHost, BasicHttpBinding,&lt;br /&gt;        ServiceBehaviorAttribute, InstanceContextMode)&lt;br /&gt;ServiceBehavior = clrtype.attribute(ServiceBehaviorAttribute)&lt;br /&gt;&lt;br /&gt;class myService(ImyService):&lt;br /&gt;    __metaclass__ = clrtype.ClrMetaclass&lt;br /&gt;    _clrnamespace = "myWcfService"&lt;br /&gt;    _clrclassattribs = [&lt;br /&gt;            ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]&lt;br /&gt;&lt;br /&gt;    def GetData(self, value):&lt;br /&gt;        return "IronPython: You entered: %s" % value&lt;br /&gt;&lt;br /&gt;sh = ServiceHost(&lt;br /&gt;        myService(),&lt;br /&gt;        Uri("http://localhost:9000/myWcfService")&lt;br /&gt;    )&lt;br /&gt;sh.AddServiceEndpoint(&lt;br /&gt;        clr.GetClrType(ImyService),&lt;br /&gt;        BasicHttpBinding(),&lt;br /&gt;        "")&lt;br /&gt;sh.Open()&lt;br /&gt;Console.WriteLine("Press &lt;enter&gt; to terminate\n")&lt;br /&gt;Console.ReadLine()&lt;br /&gt;sh.Close()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;myService&lt;/span&gt; class must have &lt;i&gt;InstanceContextMode.Single&lt;/i&gt; ServiceBehavior attribute because we are passing service i&lt;i&gt;nstance&lt;/i&gt; to the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ServiceHost&lt;/span&gt; constructor. This is done via new &lt;a href="http://devhawk.net/CategoryView,category,__clrtype__.aspx"&gt;__clrtype__ metaclass&lt;/a&gt;. See the &lt;a href="http://lists.ironpython.com/pipermail/users-ironpython.com/2009-February/009718.html"&gt;error&lt;/a&gt; if we don't use the attribute. I was not able to pass &lt;i&gt;type&lt;/i&gt; into the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;ServiceHost&lt;/span&gt; constructor.&lt;br /&gt;&lt;br /&gt;To test the service, you can use C# or IronPython client implementation:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/10/TestClient.cs"&gt;TestClient.cs&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:c#"&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;using TestServiceInterface;&lt;br /&gt;&lt;br /&gt;namespace myWcfClient&lt;br /&gt;{&lt;br /&gt;    public class cli&lt;br /&gt;    {&lt;br /&gt;        public static void Main()&lt;br /&gt;        {&lt;br /&gt;   ChannelFactory&lt;imyservice&gt; mycf = new ChannelFactory&lt;imyservice&gt;(&lt;br /&gt;     new BasicHttpBinding(),&lt;br /&gt;        new EndpointAddress("http://localhost:9000/myWcfService"));&lt;br /&gt;   ImyService wcfcli = mycf.CreateChannel();&lt;br /&gt;   Console.WriteLine("Calling GetData(33) returns:\n{0}", wcfcli.GetData(33));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://gui-at.cendaweb.cz/2009/10/TestClient.py"&gt;TestClient.py&lt;/a&gt;&lt;pre class="brush:python"&gt;import clr&lt;br /&gt;clr.AddReference('System.ServiceModel')&lt;br /&gt;import System.ServiceModel&lt;br /&gt;clr.AddReference('TestServiceInterface')&lt;br /&gt;from TestServiceInterface import ImyService&lt;br /&gt;&lt;br /&gt;mycf = System.ServiceModel.ChannelFactory[ImyService](&lt;br /&gt;        System.ServiceModel.BasicHttpBinding(),&lt;br /&gt;        System.ServiceModel.EndpointAddress("http://localhost:9000/myWcfService"))&lt;br /&gt;wcfcli = mycf.CreateChannel()&lt;br /&gt;print "WCF service returned:\n%s" % wcfcli.GetData(11)&lt;/pre&gt;&lt;br /&gt;Disadvantages:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;You can have only single instance of the service because you are passing the service &lt;i&gt;instance&lt;/i&gt; instead of service &lt;i&gt;type&lt;/i&gt;.&lt;/li&gt;&lt;li&gt;You cannot easily use &lt;i&gt;.config&lt;/i&gt; file to configure your service.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Note: If you see closing tags (e.g. &lt;i&gt;enter&lt;/i&gt; or &lt;i&gt;ImyService&lt;/i&gt;) at the end of listings, it looks like SyntaxHighlighter bug in Google Chrome...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-3556934013257617305?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/10/wcf-service-in-ironpython.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-8991241609083242488</guid><pubDate>Thu, 24 Sep 2009 21:53:00 +0000</pubDate><atom:updated>2009-11-11T22:39:13.483+01:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>python</category><category domain='http://www.blogger.com/atom/ns#'>virtualbox</category><title>How to clone VirtualBox virtual machine</title><description>&lt;a href="http://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt; is great piece of software for virtualization. I like it more than &lt;a href="http://www.vmware.com/"&gt;VMWare&lt;/a&gt; or &lt;a href="http://www.microsoft.com/windows/virtual-pc/"&gt;VirtualPC&lt;/a&gt;. The downside of it is its lack of easy&amp;nbsp;cloning&amp;nbsp;or copying capabilities. There are none. And because everything in VirtualBox has UUID (guid), pure file copy does not work well.&lt;br /&gt;&lt;br /&gt;All advices I have seen were about: create the new virtual machine manually,&amp;nbsp;clone HDD .vdi file with &amp;nbsp;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;a href="http://srackham.wordpress.com/cloning-and-copying-virtualbox-virtual-machines/"&gt;VBoxManage clonevdi&lt;/a&gt;&lt;/span&gt;&amp;nbsp;command and attach it to the newly created virtual machine. &lt;i&gt;Manually!?&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;That's why I've created a simple Python script that cares about exporting and importing virtual machines (Thanks for the VirtualBox 3 SDK!). When exporting, &lt;b&gt;you can select the virtual machine and &lt;/b&gt;&lt;b&gt;snapshot you want to export&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_S0yH53CI4fI/SrvmorRrk5I/AAAAAAAAACI/3Xk5d1x0EIA/s1600-h/VBoxUtil.png" imageanchor="1"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_S0yH53CI4fI/SrvmorRrk5I/AAAAAAAAACI/3Xk5d1x0EIA/s400/VBoxUtil.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The exported machines are stored in &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;exp&lt;/span&gt; folder at the script file. The&amp;nbsp;time stamp&amp;nbsp;is added to the machine name for unique identification.&amp;nbsp;When importing, you are offered with the saved virtual machines and you simply choose one. Of course you can copy the exported machine to different computer (having the same VirtualBox versions is recommended).&lt;br /&gt;&lt;br /&gt;The script is very simple and targeted to my needs. That means it exports only primary HDD and network adapter 0. It does not export CD/DVD-ROM, Floppy nor Serial ports.&lt;br /&gt;&lt;br /&gt;Try it and let me know whether it's helpful:&amp;nbsp;&lt;a href="http://gui-at.cendaweb.cz/2009/09/VBoxUtil.py"&gt;download script&lt;/a&gt;&amp;nbsp;(it requires&amp;nbsp;&lt;a href="http://www.voidspace.org.uk/python/configobj.html"&gt;ConfigObj 4&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update 1. 10. 2009:&lt;/b&gt;&amp;nbsp;I struggled running the script on my new Win 7 64-bit system. It complained class is not registered for VirtualBox.Session. The reason was mixing 32-bit and 64-bit programs - see the &lt;a href="http://vbox.innotek.de/pipermail/vbox-users/2008-May/003308.html"&gt;explanation&lt;/a&gt;. &lt;b&gt;If you use 64-bit OS, you have to have installed 64-bit version of Python and pywin32&lt;/b&gt;!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update 11. 11. 2009:&lt;/b&gt; I have updated the script to better serve my needs. For example, when restoring virtual machine, you can enter a new name for it. Be carefull when restoring one saved machine to two new ones as you have to chagne MAC address manually.&lt;br /&gt;&lt;br /&gt;Unfortunately, the old config file is not compactible with the new version. But I think you can guess from the Python exception what is wrong with the config file and fix it. The old version is still &lt;a href="http://gui-at.cendaweb.cz/2009/09/VBoxUtil.old.py"&gt;available&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-8991241609083242488?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/09/how-to-clone-virtualbox-virtual-machine.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_S0yH53CI4fI/SrvmorRrk5I/AAAAAAAAACI/3Xk5d1x0EIA/s72-c/VBoxUtil.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-4297872760962914668</guid><pubDate>Sat, 16 May 2009 16:26:00 +0000</pubDate><atom:updated>2009-05-16T18:32:29.288+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>links</category><title>Pycon 2009: Functional Testing of Desktop Applications</title><description>Here is a link to &lt;span class="fn"&gt;Michael Foord&lt;/span&gt; talk at Pycon 2009 in Chicago about functional testing of desktop applications:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://pycon.blip.tv/file/1957454/"&gt;Functional Testing of Desktop Applications&lt;/a&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Many advocates of unit testing believe that testing desktop (GUI) applications is so difficult as to not be worth it. Not only is it possible, but 'functional testing' (testing an application from the point of view of the user) is an important part of an agile development process.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I watched it yesterday and it is very good!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-4297872760962914668?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2009/05/pycon-2009-functional-testing-of.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-4609531643659187214</guid><pubDate>Fri, 15 May 2009 15:25:00 +0000</pubDate><atom:updated>2009-05-16T18:34:30.615+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>accessibility</category><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Testing an unknown application</title><description>From time to time you may need to test an unknown application. I have encounter it when I needed to test our installation program. The task was simple - install the application for automated smoke tests. In such cases I gladly return to &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application.html"&gt;Accessibility&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let's pretend our testing application is not written in .NET and the only way how to explore it is through the accessibility (AccExplorer):&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s1600-h/AccExplorer.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s320/AccExplorer.PNG" alt="" id="BLOGGER_PHOTO_ID_5207784789725286610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All we need to do is to access Accessibility objects from IronPython. There is a project called &lt;a href="http://mwinapi.sourceforge.net/"&gt;Managed Windows API&lt;/a&gt; that nicely wraps accessibility for .NET. It also wraps other Win32 API calls (mouse clicks etc.) but I stay with &lt;a href="http://gui-at.blogspot.com/2008/07/simulate-users-input.html"&gt;Win32API.dll&lt;/a&gt; because of my laziness :-).&lt;br /&gt;&lt;br /&gt;Utilizing the &lt;span style="font-style: italic;"&gt;Managed Windows API&lt;/span&gt; you can control the accessibility objects. Here is the snippet:&lt;br /&gt;&lt;pre name="code" class="python"&gt;import clr&lt;br /&gt;# Win32API provide access to Win32 API functions&lt;br /&gt;clr.AddReference('Win32API')&lt;br /&gt;from Win32API import Win32API&lt;br /&gt;# ManagedWinapi provide access to Accessibility objects&lt;br /&gt;clr.AddReference('ManagedWinapi')&lt;br /&gt;import ManagedWinapi.Accessibility as ma&lt;br /&gt;import ManagedWinapi.Windows as mw&lt;br /&gt;&lt;br /&gt;def GetGUIATWindow():&lt;br /&gt;   """ Return GUIAT_PoC window accessibility object. """&lt;br /&gt;   def callback(aWindow):&lt;br /&gt;       return aWindow.Title == 'GUIAT - Proof of Concept'&lt;br /&gt;   guiat_window = mw.SystemWindow.FilterToplevelWindows(callback)&lt;br /&gt;   # assume guiat_window is list with just one object&lt;br /&gt;   return ma.SystemAccessibleObject.FromWindow(guiat_window[0],&lt;br /&gt;       ma.AccessibleObjectID.OBJID_WINDOW)&lt;br /&gt;&lt;br /&gt;guiat_acc = GetGUIATWindow()&lt;br /&gt;# position of the 'New listbox item' text box&lt;br /&gt;pos = guiat_acc.Children[3].Children[1].Location&lt;br /&gt;# focus the text box&lt;br /&gt;Win32API.MouseClick(pos.X + pos.Width/2, pos.Y + pos.Height/2)&lt;br /&gt;Win32API.SendString('Accessibility test')&lt;br /&gt;# position of the 'Add Item' button&lt;br /&gt;pos = guiat_acc.Children[3].Children[2].Location&lt;br /&gt;# click the button&lt;br /&gt;Win32API.MouseClick(pos.X + pos.Width/2, pos.Y + pos.Height/2)&lt;/pre&gt;To run it, download &lt;a href="http://prdownloads.sourceforge.net/mwinapi/managedwinapi-0.3.zip?download"&gt;managedwinapi-0.3.zip&lt;/a&gt; and extract the &lt;span style="font-style: italic;"&gt;ManagedWinapi.dll&lt;/span&gt; to the same folder as the &lt;a href="http://gui-at.cendaweb.cz/GUIAT_Acc.zip"&gt;source code&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;When you run the code, it enters &lt;span style="font-style: italic;"&gt;Accessibility test&lt;/span&gt; text into &lt;span style="font-style: italic;"&gt;New listbox item&lt;/span&gt; text box and clicks &lt;span style="font-style: italic;"&gt;Add Item&lt;/span&gt; button. The controls are always on the same position within the Children enumeration so we can use direct referencing: e.g. &lt;span style="font-family:courier new;"&gt;guiat_acc.Children[3].Children[2]&lt;/span&gt; is the button accessibility object.&lt;br /&gt;&lt;br /&gt;Enhancing this example is up to you - I have created several functions that take care about entering the text into text boxes, selecting buttons or a checking check boxes. That's all I need to create a script that installs our application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-4609531643659187214?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/10/testing-unknown-application.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s72-c/AccExplorer.PNG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-288007437954784993</guid><pubDate>Thu, 30 Oct 2008 07:50:00 +0000</pubDate><atom:updated>2009-05-16T18:15:17.806+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Building the framework (3)</title><description>After a while, it's time to continue building the GUI Automated Testing framework. Today, I focus on a list box. You can download the &lt;a href="http://gui-at.cendaweb.cz/v3/v3.zip"&gt;source&lt;/a&gt; as usual.&lt;br /&gt;&lt;br /&gt;I assume standard windows list box component where only unique items are stored and only one item can be selected. These two conditions are set only because of simplicity of the example. If you don't like them, enhance the example by yourself as your homework :-)&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://gui-at.cendaweb.cz/v3/ListBox.py"&gt;list box&lt;/a&gt; component is again a subclass of &lt;a href="http://gui-at.cendaweb.cz/v3/BaseComponent.py"&gt;BaseComponent&lt;/a&gt;. It is quite simple - it has one method and two properties:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Select(self, aItem)&lt;/span&gt;&lt;br /&gt;The method selects &lt;span style="font-style: italic;"&gt;aItem&lt;/span&gt; in the list box.&lt;br /&gt;&lt;pre name="code" class="python"&gt;def Select(self, aItem):&lt;br /&gt;  """ select an item from list box&lt;br /&gt;  @aItem - string with item to select&lt;br /&gt;  """&lt;br /&gt;  if aItem not in self.items:&lt;br /&gt;    raise Exception("Item '%s' not in list box" % aItem)&lt;br /&gt;  self.guiat.Activate()&lt;br /&gt;  self._CheckVisibility()&lt;br /&gt;  pos = self.location&lt;br /&gt;  # click on the first item to focus the list box&lt;br /&gt;  Win32API.MouseClick(pos[0] + (pos[2]/2), pos[1] + 3)&lt;br /&gt;  # send Home to be sure we are on the first item&lt;br /&gt;  # (we could be scrolled down a little)&lt;br /&gt;  Win32API.SendKey(Win32API.VK_HOME)&lt;br /&gt;  # simulate pressing down arrow until we find the item&lt;br /&gt;  # we should find it because it is among self.items&lt;br /&gt;  while self.value != aItem:&lt;br /&gt;    Win32API.SendKey(Win32API.VK_DOWN)&lt;/pre&gt;First, it checks whether &lt;span style="font-style: italic;"&gt;aItem&lt;/span&gt; is in the list box and raises an exception if not. Then it clicks onto the first visible list box item, simulates pressing &lt;span style="font-style: italic;"&gt;Home&lt;/span&gt; key to focus the first item and repeatedly press &lt;span style="font-style: italic;"&gt;Down&lt;/span&gt; key until the &lt;span style=""&gt;value&lt;/span&gt; equals &lt;span style="font-style: italic;"&gt;aItem&lt;/span&gt;.&lt;br /&gt;This approach has the advantage we don't need to care about scroll box. The basic windows list box does not provide nice properties or methods to return its state. We would have to dive into Win32 API to find it. For example, the DevExpress &lt;a href="http://www.devexpress.com/Help/Content.aspx?help=XtraEditors&amp;amp;document=clsDevExpressXtraEditorsListBoxControltopic.htm"&gt;ListBoxControl&lt;/a&gt; has method &lt;a href="http://www.devexpress.com/Help/Content.aspx?help=XtraEditors&amp;amp;document=DevExpressXtraEditorsBaseControl_GetViewInfotopic.htm"&gt;GetViewInfo&lt;/a&gt; that returns information about internal list box state.&lt;br /&gt;&lt;br /&gt;This  brings us to the important note:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;We do not test the list box component. We test the application.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One way of selecting item in a list box is enough. Of course, we must be aware of its limitations and side effects. Selecting an item with our GUIAT component fires one OnClick and several OnChange events.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;items&lt;/span&gt;&lt;br /&gt;The property contains read only list of all items in the list box.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;value&lt;/span&gt;&lt;br /&gt;The property contains the selected item in the list box. User can assign a string to it to select the string in the list box.&lt;br /&gt;&lt;br /&gt;Incorporating the new GUIAT &lt;a href="http://gui-at.cendaweb.cz/v3/ListBox.py"&gt;ListBox&lt;/a&gt; class into the framework is easy - just add it into the &lt;span style="font-family:courier new;"&gt;RecognizableComponents&lt;/span&gt; dictionary of the &lt;a href="http://gui-at.cendaweb.cz/v3/Form.py"&gt;Form&lt;/a&gt; class.&lt;br /&gt;&lt;br /&gt;This is the last post about controlling components. You know the idea so developing a new GUIAT class controlling your component should be easy.&lt;br /&gt;&lt;br /&gt;Next time, I show how to control application that is already started.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-288007437954784993?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/10/building-framework-3.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-2844435405499264296</guid><pubDate>Thu, 25 Sep 2008 22:55:00 +0000</pubDate><atom:updated>2009-08-26T22:46:49.214+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>links</category><title>GUI Testing at Resolver Systems</title><description>I'm currently quite busy at work and with my other activities (like &lt;a href="http://iceland.cendaweb.cz/"&gt;photos&lt;/a&gt;). That's why instead of writing another chapter of the GUI Automated Testing framework, I point you to the great article of &lt;a href="http://www.voidspace.org.uk/python/weblog/index.shtml"&gt;Michael &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Foord&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.voidspace.org.uk/python/articles/testing/index.shtml"&gt;Functional Testing of GUI Applications&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Michael describes his experiences with GUI automated testing in &lt;a href="http://www.resolversystems.com/"&gt;Resolver Systems&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;They use quite similar approach to run the tested application. It is run in another thread but the thread invoking is different. I am not a specialist in threading but I will try to find out more about which way is better or whether there are any catches[1].&lt;br /&gt;&lt;br /&gt;They also do not use &lt;a href="http://gui-at.blogspot.com/2008/07/simulate-users-input.html"&gt;win32&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;api&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; for simulating user's input. They usually call directly the .NET method responsible for generating the requested event (e.g. &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspx"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;PerformClick&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;). That can be dangerous because your test can pass even when user is unable to click the button - the button  could be hidden behind another component.&lt;br /&gt;&lt;br /&gt;[1] My current problem can be caused &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_3"&gt;by&lt;/span&gt; threading. When I run our application from automated testing tool, two buttons overlap. When I run it normally, it is OK. To be it stranger, it occurs only on my PC. I have no idea why...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Update 10/30/2008:&lt;/span&gt; I have not found any problem with my way of starting the tested application. I asked my co-&lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_3"&gt;workers&lt;/span&gt;, searched for articles about threading and found both ways should be similar. [1] is still mystery to me, though.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Update 8/20/2009:&lt;/span&gt; Mystery [1] solved - it was bug in our application :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-2844435405499264296?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/09/gui-testing-at-resolver-systems.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-4191029127098879692</guid><pubDate>Sun, 17 Aug 2008 22:30:00 +0000</pubDate><atom:updated>2009-05-16T18:13:20.831+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Building the framework (2)</title><description>&lt;a href="http://gui-at.blogspot.com/2008/07/building-framework-1.html"&gt;Last time&lt;/a&gt; we have started building the GUI Automated Testing framework. Today we are going to enhance it. Download the &lt;a href="http://gui-at.cendaweb.cz/v2/v2.zip"&gt;source&lt;/a&gt; to be able to follow the text.&lt;br /&gt;&lt;br /&gt;The first version implemented the &lt;a href="http://gui-at.cendaweb.cz/v2/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class to represent windows components. We could not do anything but find out location of the component. It would be nice to be able write text into a text box or click a button by simple method, wouldn't it?&lt;br /&gt;&lt;br /&gt;To do that, we need to know the type of each component. The type name of .NET components is stored in &lt;span style="font-family:courier new;"&gt;component.GetType().Name&lt;/span&gt;. Knowing the type, we create subclass of &lt;a href="http://gui-at.cendaweb.cz/v2/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; for each type. In the subclass, we provide nice methods and properties.&lt;br /&gt;&lt;br /&gt;First, we enhance &lt;a href="http://gui-at.cendaweb.cz/v2/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class. We add &lt;span style="font-weight: bold;font-family:courier new;" &gt;_CheckVisibility(self)&lt;/span&gt; method that checks whether the component is visible. If not, it raises an exception. We need it for checking if button is visible so we can click it or text box is visible to write it. And we add &lt;span style="font-weight: bold;font-family:courier new;" &gt;guiat&lt;/span&gt; property to be able to activate the tested application from a component by calling &lt;span style="font-family:courier new;"&gt;self.guiat.Activate()&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Let's look on a button. The &lt;a href="http://gui-at.cendaweb.cz/v2/Button.py"&gt;Button&lt;/a&gt; class is very simple:&lt;br /&gt;&lt;pre name="code" class="python"&gt;from time import sleep&lt;br /&gt;from Win32API import Win32API&lt;br /&gt;from BaseComponent import BaseComponent&lt;br /&gt;&lt;br /&gt;class Button(BaseComponent):&lt;br /&gt;   """interface to the Button component"""&lt;br /&gt;&lt;br /&gt;   def Click(self):&lt;br /&gt;       """ perform left mouse click on the center of the button, no parameters"""&lt;br /&gt;       self.guiat.Activate()&lt;br /&gt;       self._CheckVisibility()&lt;br /&gt;       pos = self.location&lt;br /&gt;       Win32API.MouseClick(pos[0] + (pos[2]/2), pos[1] + (pos[3]/2))&lt;br /&gt;       sleep(0.1)&lt;/pre&gt;The &lt;span style="font-weight: bold;font-family:courier new;" &gt;Click(self)&lt;/span&gt; method activates the tested application, checks whether the component is visible, finds out the position of the button, clicks into the middle of the button position, and finally waits a little bit. I do not like the waiting but it is here for safety. Windows may repainting some areas or do some other cool thinks, so it is better to give them some time for it.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://gui-at.cendaweb.cz/v2/TextBox.py"&gt;TextBox&lt;/a&gt; class provides three methods and one property:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;FocusEditor(self)&lt;/span&gt;&lt;br /&gt;The method essentially does the same as Button's &lt;span style="font-family:courier new;"&gt;Click&lt;/span&gt; method. It activates the tested application, checks whether the component is visible, and clicks into the middle of the &lt;a href="http://gui-at.cendaweb.cz/v2/TextBox.py"&gt;TextBox&lt;/a&gt; position to focus the editor.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Clear(self)&lt;/span&gt;&lt;br /&gt;The method focuses the text box, moves cursor to the start position simulating pressing &lt;span style="font-style: italic;"&gt;Home&lt;/span&gt; key, and simulates pressing &lt;span style="font-style: italic;"&gt;Delete&lt;/span&gt; key until the text in text box is empty. If the text is not empty then, it raises exception.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;Write(self, aString)&lt;/span&gt;&lt;br /&gt;The method clears the text box and uses &lt;a href="http://gui-at.blogspot.com/2008/07/simulate-users-input.html"&gt;Win32API&lt;/a&gt; method &lt;span style="font-family:courier new;"&gt;SendString&lt;/span&gt; to simulate typing &lt;span style="font-style: italic;"&gt;aString&lt;/span&gt;. Then checks whether the text box contains the &lt;span style="font-style: italic;"&gt;aString&lt;/span&gt; value and raises exception if not.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;value&lt;/span&gt;&lt;br /&gt;The property contains the actual value of the text box. When user assigns a string to it, the string is written to the text box.&lt;/li&gt;&lt;/ul&gt;Now look on the creating instances of GUIAT components in the &lt;a href="http://gui-at.cendaweb.cz/v2/Form.py"&gt;Form&lt;/a&gt; class. We have simply added dictionary with known component types (&lt;span style="font-weight: bold;font-family:courier new;" &gt;RecognizableComponents&lt;/span&gt;). When we go through all components on the form in the &lt;span style="font-family:courier new;"&gt;_AnalyzeStructure&lt;/span&gt; method, we first check whether we know the component type or not. If so, we create instance of the appropriate component type class (e.g. &lt;a href="http://gui-at.cendaweb.cz/v2/Button.py"&gt;Button&lt;/a&gt; or &lt;a href="http://gui-at.cendaweb.cz/v2/TextBox.py"&gt;TextBox&lt;/a&gt;). If not, we create instance of the &lt;a href="http://gui-at.cendaweb.cz/v2/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class.&lt;br /&gt;&lt;br /&gt;Let's try a small example:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; import GUIAT&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; g = GUIAT.GUIAT()&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; g.Run()&lt;br /&gt;Starting GUIAT...&lt;br /&gt;"frmGUIAT" (frmGUIAT)&lt;br /&gt;  "btnAddItem" (Button)&lt;br /&gt;  "lblNewItem" (Label)&lt;br /&gt;  "txtNewItem" (TextBox)&lt;br /&gt;  "lbxItems" (ListBox) - UNKNOWN&lt;br /&gt;  "btnQuit" (Button)&lt;br /&gt;Starting GUIAT done.&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; txt = g.mainForm._GetComponentByName('txtNewItem')&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; btn = g.mainForm._GetComponentByName('btnAddItem')&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; txt.value = 'Hello world!'&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; btn.Click()&lt;/pre&gt;The result of the above small script is a new line in the list box. You see that the button, label, and text box are know component types. The label is treated as &lt;a href="http://gui-at.cendaweb.cz/v2/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; (see &lt;span style="font-family:courier new;"&gt;RecognizableComponents&lt;/span&gt; in &lt;a href="http://gui-at.cendaweb.cz/v2/Form.py"&gt;Form.py&lt;/a&gt;). The list box is unknown component.&lt;br /&gt;&lt;br /&gt;Today, we have shown how to create button and text box GUIAT classes that control respective .NET components. &lt;span style="font-weight: bold;"&gt;We can already script our small tested application!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next time, we add list box class and logging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-4191029127098879692?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/08/building-framework-2.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-3097055103774776536</guid><pubDate>Tue, 29 Jul 2008 21:28:00 +0000</pubDate><atom:updated>2009-05-16T18:12:16.715+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Building the framework (1)</title><description>Today we start building the automated test framework. We have prepared tools in previous parts. See them to learn how to &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-1.html"&gt;run tested application&lt;/a&gt; in &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-2.html"&gt;a separate thread&lt;/a&gt; or how to &lt;a href="http://gui-at.blogspot.com/2008/07/simulate-users-input.html"&gt;simulate user's input&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The foundation of our test framework are IronPython classes that control Windows components. Simply said, everything in Windows is a component. So we create IronPython layer that allows controlling each Windows component easily. Then we create classes that will control forms with many components. And finally, we build test scripts and test suites for the whole application.&lt;br /&gt;&lt;br /&gt;We start with just three simple classes. The first class, &lt;a href="http://gui-at.cendaweb.cz/v1/GUIAT.py"&gt;GUIAT&lt;/a&gt;, is the core class taking care of running, activating (focusing), and inspecting the tested application. The second class, &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt;, is ancestor of all component classes. The last one, &lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt;, descendant of BaseComponent, is ancestor of all forms.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class provides access to common properties of all components. There is just one in the first version:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;location&lt;/span&gt; - size and position of the component on the screen (not within the parent form)&lt;/li&gt;&lt;/ul&gt;The &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class has also several private variables and methods:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_name&lt;/span&gt; - name of the component, not all components have this field filled&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_control&lt;/span&gt; - reference to the .NET component instance&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_guiat&lt;/span&gt; - reference to the main GUIAT object (see below)&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_guiatComponents&lt;/span&gt; - dictionary with all child GUIAT components&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_GetComponentByName&lt;/span&gt; - method that searches for component with given name&lt;/li&gt;&lt;/ul&gt;Note: The &lt;span style="font-style: italic;"&gt;.NET component&lt;/span&gt; means instance of the Windows component in the tested application. The &lt;span style="font-style: italic;"&gt;GUIAT component&lt;/span&gt; means instance of the IronPython class that controls the .NET component.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt; class extends the &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; class. Its purpose is to find and store all components on itself. It has one private method that does it:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;_AnalyzeStructure&lt;/span&gt; - method that searches and stores components on a form. It is recursively called for each member of the Controls collection. It prints out the name, type, and depth level of the found components. Then it creates &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; instance and stores it into the &lt;span style="font-style: italic;"&gt;_guiatComponents&lt;/span&gt; dictionary of the parent component.&lt;/li&gt;&lt;/ul&gt;The &lt;a href="http://gui-at.cendaweb.cz/v1/GUIAT.py"&gt;GUIAT&lt;/a&gt; class as the core class of the framework contains in the first version only one property and two methods:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;mainForm&lt;/span&gt; - GUIAT representation of the main form of the tested application (&lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt; instance)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Run&lt;/span&gt; - method that runs the tested application in separate thread and creates the &lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt; instance of the main form&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Activate&lt;/span&gt; - method that activates (focuses) the tested application&lt;/li&gt;&lt;/ul&gt;Let's try a small example:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; import GUIAT&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; g = GUIAT.GUIAT()&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; g.Run()&lt;br /&gt;Starting GUIAT...&lt;br /&gt;"frmGUIAT" (frmGUIAT)&lt;br /&gt;  "btnAddItem" (Button)&lt;br /&gt;  "lblNewItem" (Label)&lt;br /&gt;  "txtNewItem" (TextBox)&lt;br /&gt;  "lbxItems" (ListBox)&lt;br /&gt;  "btnQuit" (Button)&lt;br /&gt;Starting GUIAT done.&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; print g.mainForm._GetComponentByName('txtNewItem').location&lt;br /&gt;(212, 177, 96, 16)&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; g.Activate()&lt;br /&gt;True&lt;/pre&gt;The above code runs the tested application, lists name and type of all components, then prints location of the text box, and finally activates the tested application.&lt;br /&gt;&lt;br /&gt;To sum up the process again:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create instance of the GUIAT class - let's call it &lt;span style="font-family:courier new;"&gt;g&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;g.Run()&lt;/span&gt; runs the tested application&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:courier new;"&gt;g.Run()&lt;/span&gt; creates instance of IronPython &lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt; class for the main form of the tested application&lt;/li&gt;&lt;li&gt;The &lt;a href="http://gui-at.cendaweb.cz/v1/Form.py"&gt;Form&lt;/a&gt; instance searches during its initialization all components on the main form, prints information about them, and creates &lt;a href="http://gui-at.cendaweb.cz/v1/BaseComponent.py"&gt;BaseComponent&lt;/a&gt; instance for each of them&lt;/li&gt;&lt;li&gt;To find location of "txtNewItem" component, execute:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;g.mainForm._GetComponentByName("txtNewItem").location&lt;/span&gt;&lt;/li&gt;&lt;li&gt;To activate tested application, execute:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;g.Activate()&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;Today I presented the core of my GUI automated testing framework (&lt;a href="http://gui-at.cendaweb.cz/v1/v1.zip"&gt;source&lt;/a&gt;). I'm going to extend it and make it more user friendly in next parts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-3097055103774776536?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/07/building-framework-1.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-7327428004134885612</guid><pubDate>Tue, 08 Jul 2008 19:12:00 +0000</pubDate><atom:updated>2009-05-16T18:09:12.649+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Simulate user's input</title><description>We have learned in the &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-2.html"&gt;previous part&lt;/a&gt; how to explore the tested application and read its values. To test it, we also need set values to its fields.&lt;br /&gt;&lt;br /&gt;The first idea may be to utilize the .NET objects. When we can read values from the tested application fields, we can also set them. Use the code snippet from the &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-2.html"&gt;previous part&lt;/a&gt; to run the tested application and follow it by command&lt;br /&gt;&lt;pre name="code" class="python"&gt;App.Controls[2].Text = 'GUIATtext'&lt;br /&gt;&lt;/pre&gt;The tested application is started and &lt;span style="font-style: italic;"&gt;GUIATtext&lt;/span&gt; appears in the &lt;span style="font-style: italic;"&gt;New listbox item&lt;/span&gt; text box.&lt;br /&gt;&lt;br /&gt;Well, it does not appear as a proper testing to me. I'd rather simulate user's interaction with mouse and keyboard. Unfortunately, sending key strokes and mouse events is not job for .NET framework. We have to dive deep into Windows and use &lt;span style="font-style:italic;"&gt;Win32 API&lt;/span&gt; to perform these tasks.&lt;br /&gt;&lt;br /&gt;I have created a simple DLL to make Win32 API functions available for IronPython [1]. Moreover, I have added functions to simulate user's input. Here is the list of functions in the Win32API namespace with a short description:&lt;br /&gt;&lt;pre name="code" class="python"&gt;GetForegroundWindow()&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return handle of the active window&lt;br /&gt;&lt;pre name="code" class="python"&gt;SetForegroundWindow(handle)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set the active window to the window with &lt;span style="font-style: italic;"&gt;handle&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return boolean&lt;br /&gt;&lt;pre name="code" class="python"&gt;ShowWindow(handle, state)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set window with &lt;span style="font-style: italic;"&gt;handle&lt;/span&gt; to &lt;span style="font-style: italic;"&gt;state&lt;/span&gt; (minimalized, maximalized, ...)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return boolean&lt;br /&gt;&lt;pre name="code" class="python"&gt;GetWindowText(handle, title, capacity)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;span style="font-style: italic;"&gt;title&lt;/span&gt; of window with &lt;span style="font-style: italic;"&gt;handle&lt;/span&gt;, &lt;span style="font-style: italic;"&gt;title&lt;/span&gt; variable type is &lt;span style="font-style: italic;"&gt;String&lt;/span&gt; of &lt;span style="font-style:italic;"&gt;capacity&lt;/span&gt; size&lt;br /&gt;&lt;pre name="code" class="python"&gt;MouseClick(X, Y)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;simulate click with left mouse button on position &lt;span style="font-style: italic;"&gt;X, Y&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;SendKey(virtual_key)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;simulate pressing &lt;span style="font-style: italic;"&gt;virtual_key&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;SendString(string)&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;simulate typing a &lt;span style="font-style: italic;"&gt;string&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I will not go into details here. Anyone interested can explore the &lt;a href="http://gui-at.cendaweb.cz/Win32API.zip"&gt;sources&lt;/a&gt; of the &lt;a href="http://gui-at.cendaweb.cz/Win32API.dll"&gt;Win32API.dll&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Using these functions is straightforward in IronPython. Just download the &lt;a href="http://gui-at.cendaweb.cz/Win32API.dll"&gt;Win32API.dll&lt;/a&gt; and look at the example below how to perform a mouse click on the specific position:&lt;br /&gt;&lt;pre name="code" class="python"&gt;import clr&lt;br /&gt;clr.AddReference('Win32API')&lt;br /&gt;from Win32API import Win32API&lt;br /&gt;Win32API.MouseClick(10, 10)&lt;br /&gt;&lt;/pre&gt;The code snippet moves mouse to the coordinates 10, 10 (that is to the top-left corner of the screen) and perform a click with the left mouse button. More useful examples will follow in next parts.&lt;br /&gt;&lt;br /&gt;Finally, couple of warnings. The simulated mouse click is caught by the top most window on the position. And the simulated key strokes are sent to the active window. &lt;span style="font-weight: bold;"&gt;That means we have to pay attention to position and active state of the tested application.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the next part, we start building the GUIAT testing framework.&lt;br /&gt;&lt;br /&gt;[1] I do not know how to access Win32 API directly from IronPython.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-7327428004134885612?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/07/simulate-users-input.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>4</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-515908161107747009</guid><pubDate>Tue, 24 Jun 2008 19:12:00 +0000</pubDate><atom:updated>2009-05-16T18:06:57.601+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Exploring test application: IronPython (2)</title><description>We demonstrated how to run a .NET application from IronPython in the &lt;a href="http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-1.html"&gt;previous part&lt;/a&gt;. However, we couldn't control it while it was running. The solution for this problem is to run the tested application in a separate thread. Thus we will be able to enter commands in IronPython console while the tested application is running.  Here is a snippet from the source:&lt;br /&gt;&lt;pre name="code" class="python"&gt;import clr&lt;br /&gt;clr.AddReference('System')&lt;br /&gt;clr.AddReference("System.Windows.Forms")&lt;br /&gt;from System import *&lt;br /&gt;from System.Reflection import *&lt;br /&gt;from System.Threading import *&lt;br /&gt;from System.Windows.Forms import Application&lt;br /&gt;from time import sleep&lt;br /&gt;&lt;br /&gt;def RunMeCallBack(var):&lt;br /&gt;    global App&lt;br /&gt;    asm = Assembly.LoadFrom('GUIAT_PoC.exe')&lt;br /&gt;    asm_type = asm.GetType('GUIAT_PoC.frmGUIAT')&lt;br /&gt;    App = Activator.CreateInstance(asm_type)&lt;br /&gt;    Application.Run(App)&lt;br /&gt;&lt;br /&gt;App = None&lt;br /&gt;ThreadPool.QueueUserWorkItem(WaitCallback(RunMeCallBack))&lt;br /&gt;while not App:&lt;br /&gt;    sleep(0.2)&lt;br /&gt;&lt;/pre&gt;The &lt;span style="font-style: italic;"&gt;RunMeCallBack&lt;/span&gt; function starts the tested application the same way as we showed in the previous part. We create an independent thread and run this function in it so it does not block the console. The thread finishes its work when the tested application terminates (the main form of the application is closed) or when the console is closed.&lt;br /&gt;&lt;br /&gt;The important part is line&lt;br /&gt;&lt;pre name="code" class="python"&gt;App = Activator.CreateInstance(asm_type)&lt;/pre&gt;Here we remember the instance of the main form in the variable &lt;span style="font-style: italic;"&gt;App&lt;/span&gt;. &lt;span style="font-weight: bold;"&gt;We have access to the whole application thanks to the &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;App&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; variable!&lt;/span&gt; The while cycle at the end ensures waiting until the &lt;span style="font-style: italic;"&gt;App&lt;/span&gt; variable is not None. Which only happens when our tested application is up and running.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;App&lt;/span&gt; variable is our Holy Grail. Let's explore what is inside:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; App&lt;br /&gt;&amp;lt;GUIAT_PoC.frmGUIAT object at 0x000000000000002B&lt;br /&gt;[GUIAT_PoC.frmGUIAT, Text: GUIAT - Proof of Concept]&amp;gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; App.Text&lt;br /&gt;'GUIAT - Proof of Concept'&lt;br /&gt;&lt;/pre&gt;Basically, we have access to all public properties and methods. Try &lt;span style="font-family:courier new;"&gt;dir(App)&lt;/span&gt; and you'll see. With a trick, we can even access private properties and methods (using the power of reflection).&lt;br /&gt;&lt;br /&gt;To find what components are on the main form, iterate through the &lt;span style="font-style: italic;"&gt;Controls&lt;/span&gt; collection:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; for c in App.Controls:&lt;br /&gt;...   print c.Name, c.GetType()&lt;br /&gt;...&lt;br /&gt;btnAddItem System.Windows.Forms.Button&lt;br /&gt;lblNewItem System.Windows.Forms.Label&lt;br /&gt;txtNewItem System.Windows.Forms.TextBox&lt;br /&gt;lbxItems System.Windows.Forms.ListBox&lt;br /&gt;btnQuit System.Windows.Forms.Button&lt;br /&gt;&lt;/pre&gt;To find out what text is in the text box, try the following:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; App.Controls[2].Text&lt;br /&gt;''&lt;br /&gt;&lt;/pre&gt;Now, write something directly into the text box in the tested application and call the statement again:&lt;br /&gt;&lt;pre name="code" class="python"&gt;&amp;gt;&amp;gt;&amp;gt; App.Controls[2].Text&lt;br /&gt;'something'&lt;br /&gt;&lt;/pre&gt;Cool, isn't it? ;-)&lt;br /&gt;&lt;br /&gt;Next time, I show you how to simulate user interaction programatically - how to send a text or click to the tested application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-515908161107747009?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-2.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-1313246025409031626</guid><pubDate>Sun, 22 Jun 2008 11:33:00 +0000</pubDate><atom:updated>2009-05-16T18:02:39.753+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><category domain='http://www.blogger.com/atom/ns#'>ironpython</category><title>Exploring test application: IronPython (1)</title><description>How can IronPython help with exploring the test application? The answer is &lt;span style="font-style: italic;"&gt;.NET Reflection&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Reflection&lt;/span&gt; is the mechanism of discovering information solely at run time.&lt;br /&gt;&lt;br /&gt;We can discover both class and instance information. That's important. Knowing class information, we know what the object is capable of. We know whether it is a button having &lt;span style="font-style: italic;"&gt;click&lt;/span&gt; method or a text edit having &lt;span style="font-style: italic;"&gt;value&lt;/span&gt; property. And knowing instance information, we can find out what text the text edit displays.&lt;br /&gt;&lt;br /&gt;That's nice but to be able to utilize the reflection, we need access to the tested application's objects from our testing framework.  That's easy. The tested application is a .NET application so we can run it directly from IronPython.&lt;br /&gt;&lt;br /&gt;When you look to &lt;span style="font-family:courier new;"&gt;Program.cs&lt;/span&gt; (&lt;a href="http://gui-at.cendaweb.cz/GUIAT_PoC.zip"&gt;source&lt;/a&gt;), you see how the tested application is started. If you don't have the sources of tested application available, you can use &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Lutz Roeder's .NET Reflector&lt;/a&gt; to find the information.&lt;br /&gt;&lt;pre name="code" class="c#"&gt;static void Main()&lt;br /&gt;{&lt;br /&gt;   Application.EnableVisualStyles();&lt;br /&gt;   Application.SetCompatibleTextRenderingDefault(false);&lt;br /&gt;   Application.Run(new frmGUIAT());&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Let's mimic the start in IronPython. We are not interested in the first two rows. The third row is the core. The &lt;span style="font-weight: bold;"&gt;Application&lt;/span&gt; class is part of &lt;span style="font-style: italic;"&gt;System.Windows.Forms&lt;/span&gt; namespace. So we just need to create an instance of &lt;span style="font-weight: bold;"&gt;frmGUIAT&lt;/span&gt; class. To create it, we use method &lt;span style="font-weight: bold;"&gt;CreateInstance&lt;/span&gt; of &lt;span style="font-weight: bold;"&gt;Activator&lt;/span&gt; class from &lt;span style="font-style: italic;"&gt;System&lt;/span&gt; namespace. The &lt;span style="font-weight: bold;"&gt;CreateInstance&lt;/span&gt; method needs to know the type of the future instance. We find the type utilizing the reflection.&lt;br /&gt;&lt;br /&gt;The whole code looks like this:&lt;br /&gt;&lt;pre name="code" class="python"&gt;import clr&lt;br /&gt;clr.AddReference('System')&lt;br /&gt;clr.AddReference("System.Windows.Forms")&lt;br /&gt;from System import *&lt;br /&gt;from System.Reflection import *&lt;br /&gt;from System.Windows.Forms import Application&lt;br /&gt;&lt;br /&gt;asm = Assembly.LoadFrom('GUIAT_PoC.exe')&lt;br /&gt;asm_type = asm.GetType('GUIAT_PoC.frmGUIAT')&lt;br /&gt;App = Activator.CreateInstance(asm_type)&lt;br /&gt;Application.Run(App)&lt;br /&gt;&lt;/pre&gt;When you run the above code from IronPython console, the tested application is displayed. Note the IronPython must be started form the directiory where GUIAT_PoC.exe is located. The disadvantage is we cannot do anything in IronPython console while the tested application is running. The solution is to run it in separate thread. I will show it in the next article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-1313246025409031626?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/06/exploring-test-application-ironpython-1.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-1957681261587382931</guid><pubDate>Thu, 12 Jun 2008 21:50:00 +0000</pubDate><atom:updated>2009-05-16T17:47:01.260+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>accessibility</category><category domain='http://www.blogger.com/atom/ns#'>guiat</category><title>Exploring test application: Accessibility</title><description>&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Accessibility&lt;/span&gt; looks more promising:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Active Accessibility (AA) is technology developed by Microsoft to make the Windows platform more accessible to people with disabilities. It consists of a set of COM interfaces and methods which allow an application to expose information to third parties, making it easier to implement tools such as magnifiers and screen readers. It proves very useful also for testing utilities. Microsoft has implemented the accessibility interfaces for the standard Windows controls.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;AccExplorer (&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=3755582A-A707-460A-BF21-1373316E13F0&amp;amp;displaylang=en"&gt;download&lt;/a&gt;) shows you the test application structure:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s1600-h/AccExplorer.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s320/AccExplorer.PNG" alt="" id="BLOGGER_PHOTO_ID_5207784789725286610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You see nice hierarchical window structure. Every object has several properties:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Name&lt;/span&gt; - e.g. caption of button&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Value&lt;/span&gt; - e.g. value of list box&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Role Text&lt;/span&gt; - type of the component&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Location&lt;/span&gt; - position on the screen&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;State&lt;/span&gt; - e.g. disabled, normal, etc.&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Def Action&lt;/span&gt; - default action for the component&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The properties provides more information than Win32 API. But when you look closer, you see it is not enough:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;We still cannot distinguish the similar controls. Both buttons have role &lt;span style="font-style: italic;"&gt;push buttons&lt;/span&gt; and can be distinguished only by displayed name. Which is problematic when names change or you need to test localized applications.&lt;/li&gt;&lt;li&gt;Some components do not have name at all. In our example it is the text box - its name in AccExplorer is &lt;span style="font-style: italic;"&gt;NAMELESS&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;The third party components usually lack support for the accessibility in the same quality as Microsoft. For example, DevExpress grid only tells you "I am a grid". It does not tell you how many rows it contains, what cells are there, etc...&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The good news is developers can change this behavior. They can define AccessibleName property for a component so we can later easily find exactly what we need. If I have set AccessibleName for the text box to &lt;span style="font-style: italic;"&gt;myTextBox&lt;/span&gt;, we would have seen &lt;span style="font-style: italic;"&gt;myTextBox&lt;/span&gt; instead of &lt;span style="font-style: italic;"&gt;NAMELESS&lt;/span&gt; in AccExplorer now. For grid, they can define the whole structure of accessible objects to represent the grid (see &lt;a href="http://msdn.microsoft.com/en-us/library/ms971325.aspx"&gt;Exposing Data Tables through Microsoft Active Accessibility&lt;/a&gt;). Unfortunately, when your application does not have sufficient support for accessibility, it is quite lot of work...&lt;br /&gt;&lt;br /&gt;Microsoft tries to address testing issues with his new framework in .NET 3.5: &lt;a href="http://msdn.microsoft.com/en-us/library/ms753388.aspx"&gt;Microsoft UI Automation&lt;/a&gt;. I have not tried it as our applications do not run on .NET 3.5.&lt;br /&gt;&lt;br /&gt;Also DevExpress promised to enhance their components with better support for UI testing tools - see the &lt;a href="http://www.devexpress.com/Home/Announces/Roadmap2008.xml"&gt;2008 roadmap&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But we don't want to wait, right? We want to test our .NET application right now! I will show how in the next article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-1957681261587382931?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/06/exploring-test-application.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_S0yH53CI4fI/SEXErJpCENI/AAAAAAAAAA0/dZNbgnkTLzc/s72-c/AccExplorer.PNG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-451926307527729582</guid><pubDate>Tue, 03 Jun 2008 22:30:00 +0000</pubDate><atom:updated>2009-05-16T17:45:20.866+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><title>Exploring test application: Win32 API</title><description>Let's look on what we can discover about our simple test application when it is running. Before IronPython, we had two options:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Win32 API&lt;/li&gt;&lt;li&gt;Accessibility&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Win32 API&lt;/span&gt; provides several functions that return information about an application. First, we have to find the appliction handle. We utilize functions &lt;span style="font-style: italic;"&gt;EnumWindows&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;GetWindowText&lt;/span&gt;&lt;span&gt; from &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=78018"&gt;Python for Windows extensions&lt;/a&gt; project&lt;/span&gt;:&lt;span style="font-size:100%;"&gt;&lt;pre name="code" class="python"&gt;def enum(hwnd, extra):&lt;br /&gt;   global app_handle&lt;br /&gt;   if winxpgui.GetWindowText(hwnd).find('GUIAT - Proof') &gt;= 0:&lt;br /&gt;       app_handle = hwnd&lt;br /&gt;&lt;br /&gt;app_handle = None&lt;br /&gt;winxpgui.EnumWindows(enum, '')&lt;br /&gt;print 'Test application handle:', app_handle&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;When we know the application handle, we can enumerate its children:&lt;span style="font-size:100%;"&gt;&lt;pre name="code" class="python"&gt;def enum_child(hwnd, extra):&lt;br /&gt;   print '%s %s:    %s' % (hwnd, winxpgui.GetClassName(hwnd),&lt;br /&gt;           winxpgui.GetWindowText(hwnd))&lt;br /&gt;&lt;br /&gt;winxpgui.EnumChildWindows(app_handle, enum_child, '')&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;When you run the whole script (&lt;a href="http://gui-at.cendaweb.cz/Win32API_Enum.py"&gt;source&lt;/a&gt;), you get:&lt;span style="font-size:100%;"&gt;&lt;pre name="code" class="python"&gt;Test application handle: 2949744&lt;br /&gt;2621886 WindowsForms10.BUTTON.app.0.378734a:    Add Item&lt;br /&gt;7668314 WindowsForms10.STATIC.app.0.378734a:    New listbox item&lt;br /&gt;4194952 WindowsForms10.EDIT.app.0.378734a:&lt;br /&gt;2753142 WindowsForms10.LISTBOX.app.0.378734a:&lt;br /&gt;3342924 WindowsForms10.BUTTON.app.0.378734a:    Quit&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;Here is the catch. How shall we identify &lt;span style="font-size:100%;"&gt;&lt;span style="font-family:courier new;"&gt;Add Item&lt;/span&gt;&lt;/span&gt; button from &lt;span style=";font-family:courier new;font-size:100%;"  &gt;Quit&lt;/span&gt; button? Both have the same class name &lt;span style=";font-family:courier new;font-size:100%;"  &gt;WindowsForms10.BUTTON.app.0.378734a&lt;/span&gt;.  Sure, the text differs, but this isn't always true. Imagine two text boxes - both having the same class name &lt;span style="font-size:100%;"&gt;&lt;span style="font-family:courier new;"&gt;WindowsForms10.EDIT.app.0.378734a&lt;/span&gt;&lt;/span&gt;. What then? Of course, you can check positions. But this is leads you back to record/play tools and that is exactly what I want to avoid.&lt;br /&gt;&lt;br /&gt;So this is the terminus for Win32 API. Next time - Accessibility.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-451926307527729582?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/06/exploring-test-application-win32-api.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-8060659719792604491</guid><pubDate>Wed, 28 May 2008 18:40:00 +0000</pubDate><atom:updated>2009-05-16T17:36:28.702+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><title>GUI Application to Test</title><description>Let's start with something easy. We have a Windows GUI application that looks like this:&lt;br /&gt;&lt;br /&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_S0yH53CI4fI/SD2ozdu9qnI/AAAAAAAAAAs/eXC1eed5M98/s320/TestedApplication.PNG" alt="" id="BLOGGER_PHOTO_ID_5205502346418563698" border="0" /&gt;&lt;br /&gt;The application contains a text box, two buttons, and a list box. It simply adds a text from text box as the last item to the list box (&lt;a href="http://gui-at.cendaweb.cz/GUIAT_PoC.exe"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;exe&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://gui-at.cendaweb.cz/GUIAT_PoC.zip"&gt;source&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;The testing steps might be as follows:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Run the application.&lt;/li&gt;&lt;li&gt;Check the 'New &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;listbox&lt;/span&gt; item' fields is empty.&lt;/li&gt;&lt;li&gt;Check the list box contains three rows with texts: 'This is', '&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;GUIAT&lt;/span&gt;', 'demo.'.&lt;/li&gt;&lt;li&gt;Enter a text (e.g. 'new line') into text box, press 'Add Item' button. Verify your text ('new line') appears as the fourth line/item in the list box.&lt;/li&gt;&lt;li&gt;Press 'Quit' button. Verify the application terminates.&lt;/li&gt;&lt;/ol&gt;Any record/play testing tool can do the test up to point 4. There it cannot verify whether the text was added to the correct place in the list box. These tools also cannot handle moving 'Add Item' button closer to the text box. They would then click to empty place. Sure there are more sophisticated tools that can handle the above problems. But I do not know about any for free.&lt;br /&gt;&lt;br /&gt;Next time we try some dead ends from my  beginnings :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-8060659719792604491?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/05/gui-application-to-test.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_S0yH53CI4fI/SD2ozdu9qnI/AAAAAAAAAAs/eXC1eed5M98/s72-c/TestedApplication.PNG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1384551653506604356.post-495552271729175244</guid><pubDate>Thu, 22 May 2008 15:33:00 +0000</pubDate><atom:updated>2009-05-16T17:35:01.937+02:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>guiat</category><title>The beginning</title><description>Testing GUI application can be tedious work. Usually, you have to manually click through the interfaces. The first round is fun, the second is OK, and from the third round on it is boring.&lt;br /&gt;&lt;br /&gt;When I joined  Radiant, I started to think about automation. I searched on &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_0"&gt;Internet&lt;/span&gt; but I did not find anything satisfying. All tools were basically record/play applications. That is not sufficient for testing. There are many concerns, for example:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;How do you verify the test result?&lt;/li&gt;&lt;li&gt;How easy can you change the script (add testing of a new field, new form, etc.)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Scalability - how easy can you join basic scripts and create bigger (regression) script?&lt;/li&gt;&lt;li&gt;How the test application works with your amended &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_1"&gt;components&lt;/span&gt;?&lt;/li&gt;&lt;li&gt;etc.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;I know the testing tool cannot do everything. So I set up several goals I'd like to achieve:&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Allow to control GUI application.&lt;/span&gt;&lt;br /&gt;That means to start it, navigates through it, close it. To know its status. &lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Allow to read values from the screen.&lt;/span&gt;&lt;br /&gt;You have to know what is on the screen to be able to test it.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Allow to set values.&lt;/span&gt;&lt;br /&gt;Also, you have to be able to set/write values into the application to be able to test it.&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Easy to create.&lt;/span&gt;&lt;br /&gt;Testers are not experienced programmers. The tool must be easy to use. Anybody, who knows what a &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_2"&gt;program&lt;/span&gt; is, should be able to write a test script.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Easy to maintain.&lt;br /&gt;&lt;/span&gt;When the tested application changes, amending a test script should not be necessary or be a piece of cake.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Scalability.&lt;/span&gt;&lt;br /&gt;Joining test scripts together, creating regression scripts.&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;In next few weeks, you'll find out on this blog how I succeed in this task.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1384551653506604356-495552271729175244?l=gui-at.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gui-at.blogspot.com/2008/05/beginning.html</link><author>noreply@blogger.com (Lukáš Čenovský)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item></channel></rss>