watir_适用于.NET的WATIR-WatiN即将发布0.8版并通过PowerShell自动执行IE

watir

watir

I'm a big fan of WATIR (pronounced "Water"). However many folks have said they wish they could have a similar tool in .NET. WatiN may be that tool. Looks like they'll be releasing 0.8.0 around September 1st with these changes:

我是WATIR (发音为“水”)的忠实粉丝。 但是,许多人表示,他们希望他们可以在.NET中使用类似的工具。 WatiN可能就是那个工具。 看起来他们将在9月1日左右发布0.8.0,其中包含以下更改

  • An even more Watir like syntax to access an element. There's no need anymore to use MainDocument to access, for example, a TextField. You will now write code like:

    甚至可以使用类似Watir的语法来访问元素。 不再需要使用MainDocument来访问例如TextField。 您现在将编写如下代码:

    An even more Watir like syntax to access an element. There's no need anymore to use MainDocument to access, for example, a TextField. You will now write code like: ie.TextField("textfieldid).Text 

    访问元素的语法更像Watir。 不再需要使用MainDocument来访问例如TextField。 您现在将编写如下代码: ie.TextField(“ textfieldid).Text

  •  Support for finding matching element attribute values by using regular expressions.

    支持使用正则表达式查找匹配的元素属性值。
  • Out of the box support for finding images by their Src attribute (no need to create your own AttributeValue class for this anymore).

    开箱即用的支持,通过它们的Src属性查找图像(不再需要为此创建自己的AttributeValue类)。
  • Updated documentation.

    更新了文档。

Looks like a pretty nice, pretty clean implementation of an IE abstraction layer for .NET that will be getting even cleaner very soon. 

看起来像.NET的IE抽象层的一个非常漂亮,非常干净的实现,它将很快变得更加干净。

Aside: Another great .NET-based IE Automator is Alex Furman's SWExplorerAutomation. Here's an example of integrating SWEA with NUnit.

顺便说一句:另一个很棒的基于.NET的IE Automator是Alex Furman的SWExplorerAutomation 是将SWEA与NUnit集成示例

Back on the Watir side, one of the coolest things about Watir is "putting IE on a string" from the Interactive RuBy shell, or IRB. Leon has a great 3 mins to Watir tutorial that uses the IRB with Watir to interactively poke around at a site. Many folks find this more useful and interesting than using a recorder tool.

回到Watir方面,关于Watir的最酷的事情之一是从Interactive RuBy shell或IRB中“将IE放在字符串上”。 Leon在Watir教程上花了3分钟的时间,该教程使用IRB和Watir在网站上进行交互式交互。 许多人发现这比使用记录器工具更有用和有趣。

For example, assuming you've installed Ruby with the Windows Ruby Installer, open up a cmd.exe prompt and run

例如,假设您已使用Windows Ruby Installer安装Ruby ,则打开cmd.exe提示符并运行

gem install Watir

宝石安装瓦蒂尔

to get Watir. Then run IRB.exe (Interactive Ruby) and do this:

得到瓦蒂尔。 然后运行IRB.exe(交互式Ruby)并执行以下操作:

irb(main):001:0> require 'watir'irb(main):002:0> include Watirirb(main):003:0> ie = Watir::IE.newirb(main):004:0> ie.goto("http://google.com")irb(main):005:0> ie.text_field(:name, "q").set("Scott Hanselman")irb(main):006:0> ie.button(:name, "btnG").click

irb(main):001:0>需要'watir' irb(main):002:0>包含Watir irb(main):003:0>即= Watir :: IE.new irb(main):004:0> ie.goto(“ http://google.com ”) irb(main):005:0> ie.text_field(:name,“ q”)。set(“ Scott Hanselman”) irb(main):006:0> ie.button(:name,“ btnG”)。click

And that's interactive Watir, right? Yay.

那就是交互式Watir,对不对? 好极了。

So, if I take a look at this WatiN (pronounced WHAT'n as in What'n'tha'heck maybe?) using the only interactive .NET Shell I have available to me...could I do Watir/IRB style interactive work using PowerShell?

因此,如果我使用唯一可用的交互式.NET Shell来查看此WatiN(在What'n'tha'heck中发音为“?”),我可以进行Watir / IRB风格的交互吗使用PowerShell工作?

PS[1] C:\WatiN-0.7.0.4000\bin
> [System.Reflection.Assembly]::LoadFile((get-item WatiN.Core.dll).FullName)

PS [1] C:\ WatiN-0.7.0.4000 \ bin > [System.Reflection.Assembly] :: LoadFile((获取项目WatiN.Core.dll).FullName)

GAC    Version        Location
---    -------        --------
False  v1.1.4322      C:\WatiN-0.7.0...

GAC版本位置--------- -------- 虚假v1.1.4322 C:\ WatiN-0.7.0 ...

PS[2] C:\WatiN-0.7.0.4000\bin
> $ie = new-object WatiN.Core.IE("
http://www.google.com")
New-Object : Exception calling ".ctor" with "1" argument(s): "Could not load fi
le or assembly 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyTok
en=null' or one of its dependencies. The system cannot find the file specified.
"
At line:1 char:17
+ $ie = new-object  <<<< WatiN.Core.IE("
http://www.google.com")

PS [2] C:\ WatiN-0.7.0.4000 \ bin > $ ie =新对象WatiN.Core.IE(“ http://www.google.com ”) 新对象:使用“ 1”参数调用“ .ctor”的异常:“无法加载fi 文件或程序集'Interop.SHDocVw,版本= 1.1.0.0,文化=中性,PublicKeyTok en = null”或其依赖项之一。 该系统找不到指定的文件。 在线:1字符:17 + $ ie =新对象<<<< WatiN.Core.IE(“ http://www.google.com ”)

Looks like since he's using an unsigned IE interop assembly it can't load it from the current application directory. That's c:/Program Files/Windows PowerShell/v1.0/, not the current directory. At this point I have two choices. I can copy the unsigned intern assembly Interop.SHDocVw.dll to the PowerShell folder, or I can rebuild the project against a Signed Primary Interop Assembly for IE. I'll copy it over for now.

由于他使用的是未签名的IE互操作程序集,因此无法从当前应用程序目录中加载它。 那是c:/ Program Files / Windows PowerShell / v1.0 /,而不是当前目录。 在这一点上,我有两种选择。 我可以将未签名的内部程序集Interop.SHDocVw.dll复制到PowerShell文件夹,也可以针对IE的Signed Primary Interop Assembly重建项目。 我现在将其复制。

PS[1] C:\WatiN-0.7.0.4000\bin
> [System.Reflection.Assembly]::LoadFile((get-item WatiN.Core.dll).FullName)

PS [1] C:\ WatiN-0.7.0.4000 \ bin > [System.Reflection.Assembly] :: LoadFile((获取项目WatiN.Core.dll).FullName)

GAC    Version        Location
---    -------        --------
False  v1.1.4322      C:\WatiN-0.7.0...

GAC版本位置--------- -------- 虚假v1.1.4322 C:\ WatiN-0.7.0 ...

PS[2] C:\WatiN-0.7.0.4000\bin
> $ie = new-object WatiN.Core.IE("
http://www.google.com")
New-Object : Exception calling ".ctor" with "1" argument(s): "Specified cast is
 not valid."
At line:1 char:17
+ $ie = new-object  <<<< WatiN.Core.IE("
http://www.google.com")

PS [2] C:\ WatiN-0.7.0.4000 \ bin > $ ie =新对象WatiN.Core.IE(“ http://www.google.com ”) 新对象:使用“ 1”参数调用“ .ctor”的异常:“指定的强制转换为无效。” 在线:1字符:17 + $ ie =新对象<<<< WatiN.Core.IE(“ http://www.google.com ”)

Yikes. Looks like folks are pissed off; so pissed off this forcibly closed PowerShell also.

kes。 看起来人们很生气。 所以也讨厌这个被强制关闭的PowerShell。

Ok, so WatiN is doing something tricky that PowerShell doesn't like. Well, since PowerShell has its own concept of how .NET and COM should interact. Let's cut out the middle man (WatiN in this case) and go direct to IE from PowerShell .

好的,WatiN正在做一些PowerShell不喜欢的棘手的事情。 好吧,因为PowerShell具有.NET和COM应该如何交互的自己的概念。 让我们切出中间人(在本例中为WatiN),然后从PowerShell直接转到IE。

PS[1]>$psie = new-object -com InternetExplorer.Application
PS[2]>$psie.Navigate("
http://www.google.com")
PS[3]>$q = ($psie.Document.GetElementsByTagname("input") | where { $_.Name -eq "q" } #get the input box called "q"
PS[4]>$q.value = "Scott Hanselman"
PS[5]>$search = $psie.Document.GetElementsByTagname("input") | where { $_.Name -eq "btnG" }
PS[6]>$search.click()

PS [1]> $ psie = new-object -com InternetExplorer.Application PS [2]> $ psie.Navigate(“ http://www.google.com ”) PS [3]> $ q =($ psie.Document.GetElementsByTagname(“ input”)|其中{$ _。Name -eq“ q”}#获取名为“ q”的输入框PS [4]> $ q.value =“ Scott Hanselman” PS [5]> $ search = $ psie.Document.GetElementsByTagname(“ input”)| 其中{$ _。Name -eq“ btnG”} PS [6]> $ search.click()

Gross, not easy, but shows potential. You know, a weekend, some UpdateType-Data action and a few functions and one could get a WatiPSH (!?) prototype running that would be very PowerShelly...I wonder if the PowerShell type extension stuff works as nicely with COM objects...

毛重,不容易,但显示出潜力。 您知道,一个周末,执行一些UpdateType-Data操作和一些功能,并且可以运行WatiPSH(!?)原型,这将非常具有PowerShelly功能...我想知道PowerShell类型扩展名的东西是否可以与COM对象很好地配合使用。 ..

If the WatiN team considers PowerShell in their use cases, their abstraction layer might make a suitable interface for PowerShell scripting. Or, perhaps a few well written PowerShell scripts could give Watir-like syntax on PowerShell. Either way, WatiN has the potential to be pretty useful, particularly within NUnit if you find the Watir NUnit Integration distasteful (some do, I don't, I started it).

如果WatiN团队在用例中考虑使用PowerShell,则其抽象层可能会为PowerShell脚本编写合适的接口。 或者,也许一些编写良好的PowerShell脚本可以在PowerShell上提供类似Watir的语法。 无论哪种方式,WatiN都可能会很有用,特别是如果您发现Watir NUnit Integration令人反感(在某些情况下,我不这样做,我就开始了),则在NUnit中尤其如此

For now, I'll stick with the simplicity and IJW of Watir, but I'm keeping my eye on WatiN.

现在,我将继续使用Watir的简单性和IJW,但我会一直关注WatiN。

Now playing: Stephen Lynch - Superhero

现在播放: Stephen Lynch-超级英雄

翻译自: https://www.hanselman.com/blog/watir-for-net-watin-approaches-08-release-and-automating-ie-from-powershell

watir

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值