0

我正在开发一些 UI 自动化软件,最近才将项目从 Python 转移到 IronPython,因为该项目的要求表明它只能在 Windows 环境中使用。但是,我需要自动化使用 Windows Presentation Foundation (WPF) 的程序的 UI。我发现了一个看起来很有用的库,叫做 White。

http://white.codeplex.com/

所以我想在我的 IronPython 程序中使用它,但是到目前为止我看到的所有用于导入用 C# 或使用 C# 接口编写的模块的示例代码都是用于 Microsoft/Windows 内置的。我想我应该可以参考它,因为您可以根据本文使用 IronRuby 来完成它。

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

但是,我不得不想象 IronRuby 导入/引用 White 的方式/语法与 IronPython 的方式非常不同。我还发现其他开发人员的帖子说他们正在使用 IronPython 和 White,但找不到包含实际引用 White 的代码的帖子。我该怎么办?

4

2 回答 2

4
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 *

然后像往常一样使用白色的api。

app = Application.Attach(proc)
win = app.GetWindow('Window Caption')
print win.Name
box = win.Get[MultilineTextBox]('textBoxId')
print box.Text
于 2011-10-25T14:42:59.800 回答
3

IronPython 能够使用以下方法处理任何 CLR 程序集:

import clr

clr.AddReference("AssemblyName")

因为白色项目是基于 .NET 的,所以这将起作用。要使用程序集中的对象:

from AssemblyName import *

(当然你可以在这里使用一个子集)

然后简单地实例化并使用你的对象:

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

文档应该有所帮助。

于 2011-10-24T17:28:48.403 回答