I have a test harness that runs in an embedded IronPython engine in our C# app. Some of the tests are UI automation that simulate button clicks, etc.
# assume code to find an existing button, 'b' is an instance of System.Windows.Forms.Button
b.OnClick(EventArgs())
The issue I have is that the above code works on IPy 2.0.2 and not on 2.6. Reading the link below, I can see why it no longer works.
http://dlr.codeplex.com/Thread/View.aspx?ThreadId=57324
So I created a python sublclass as follows:
class PyButton(Button):pass
This works fine if you are going to create a new instance of PyButton and attempt the OnClick(). However, in my case, I need to perform an OnClick against an existing Button. Essentially I want to do the following, to allow me to simulate the click on the button:
- Get a reference to existing winforms Button
- Cast/convert Button to custom PyButton subclass (to allow for OnClick)
- Call OnClick
I tried using clr.Convert:
import clr
from System.Windows.Forms import *
class PyButton(Button):pass
# assume b = existing button
pb = clr.Convert(b, clr.GetClrType(PyButton))
... but get this error:
expected Button_2$2, got Button
input was pb = clr.Convert(b, clr.GetClrType(PyButton))