Search code examples
wpfwindowsironpythonui-automationwhite-framework

How do I import the white project into an IronPython program?


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?


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