Question

I am working on some UI automation software and just recently moved the project from Python to IronPython since the requirements for this project state it will only be used in a Windows environment. However, I need to automated the UI of a program that uses Windows Presentation Foundation (WPF). I found this one library that looks like it might be useful called White.

http://white.codeplex.com/

So I would like to use this in my IronPython program but all the example code I have been seeing so far for importing modules written in C# or with a C# interface has been for the Microsoft/Windows built-ins. I figured I should be able to reference it since you can do it with IronRuby according to this article.

http://www.natontesting.com/2010/02/17/how-to-test-a-wpf-app-using-ironruby-and-white/

However, I have to imagine the means/syntax by which IronRuby would import/reference White is very different than how IronPython would do it. I have also found posts by other developers saying they are using IronPython and White, but can't find a post that includes the code to actually make the reference to White. How would I go about this?

Was it helpful?

Solution

import clr
clr.AddReference("White.Core")
clr.AddReference("White.NUnit")
from White.NUnit import *
from White import *
from White.Core import *
from White.Core.Configuration import *
from White.Core.UIItems import *
from White.Core.UIItems.WindowItems import *
from White.Core.UIItems.ListBoxItems import *
from White.Core.UIItems.Container import *
from White.Core.UIItems.Finders import *
from White.Core.Factory import *
from White.Core.Finder import *
from White.Core.AutomationElementSearch import *
from White.Core.WindowsAPI import *

Then use the white api as normal.

app = Application.Attach(proc)
win = app.GetWindow('Window Caption')
print win.Name
box = win.Get[MultilineTextBox]('textBoxId')
print box.Text

OTHER TIPS

IronPython is capable of addressing any CLR assembly using the following:

import clr

clr.AddReference("AssemblyName")

Because the white project is .NET based this will work. To use objects from the assembly:

from AssemblyName import *

(of course you can use a subset here)

Then simply instantiate and use your objects:

from System.Collections import BitArray
ba = BitArray(5)
ba.Set(0, True) # call the Set method
ba[0]

This documentation should help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top