OK, I'm hooked. Ruby is the bomb and I'm loving it. We shall see what the future brings, the debugger is iffy, I need to recompile Notepad2 like Wes did with Ruby syntax support, but otherwise I'm digging it.

好吧,我迷上了。 Ruby是炸弹,我很喜欢它。 我们将看到未来带来的情况,调试器尚无定论,我需要像Wes在Ruby语法支持下所做的那样重新编译Notepad2 ,否则我将继续进行挖掘。

The back story is this. I've been trying to find the Holy Grail, or even the 40% Grail of Automated Web UI Testing for at least the last 5 years. We use NUnit for everything, so it'd be cool if whatever we chose could fail NUnit tests.

背后的故事是这个。 至少在过去的五年中,我一直在尝试寻找“圣杯”,甚至40%的自动化Web UI测试。 我们使用NUnit进行所有操作,因此如果我们选择的任何方法都无法通过NUnit测试,那就太酷了。

Lately folks have been trying again all over the next and lots of good stuff has been happening in this space.

最近,人们一直在尝试再次尝试,并且在这个空间中发生了很多好事。

  • NUnitASP - http://nunitasp.sourceforge.net/

    NUnitASP - http: //nunitasp.sourceforge.net/

    • Pros: C# class library for downloading and parsing web pages. Very CSharpy.

      优点: C#类库,用于下载和解析网页。 非常CSharpy。

    • Cons: Nothing has happened with this since November 2004. Have to extend it constantly for more complex controls. Thinks about things in a Control way.

      缺点:自2004年11月以来,此操作未发生任何事情。必须不断扩展它以实现更复杂的控件。 以控制方式思考事物。

    NUnitASP - http://nunitasp.sourceforge.net/

    NUnitASP - http: //nunitasp.sourceforge.net/

  • SAMIE - http://samie.sourceforge.net/

    SAMIE - http://samie.sourceforge.net/

    • Pros: Uses Perl to drive IE around using it's OLE automation interface. Keeps logs, can fill with data from databases, and there's a cheesy but functional WinForms app to help write the scripting language.

      优点:使用Perl使用OLE自动化界面来驱动IE。 保留日志,可以填充数据库中的数据,并且有一个俗气但功能强大的WinForms应用程序可帮助编写脚本语言。

    • Cons: Uses Perl. LOL.

      缺点:使用Perl。 大声笑。

    SAMIE - http://samie.sourceforge.net/

    SAMIE - http://samie.sourceforge.net/

  • HttpUnit - http://httpunit.sourceforge.net/

    HttpUnit - http://httpunit.sourceforge.net/

    • Pros: Feels good to the Java folks, integrates with JUnit, lower level focused.

      优点:对Java专家感觉很好,与JUnit集成,专注于较低级别。

    • Cons: May not be actively developed, no activity since October 2004.

      缺点:可能没有得到积极开发,自2004年10月以来没有任何活动。

  • IEUnit - http://ieunit.sourceforge.net/

    IEUnit - http: //ieunit.sourceforge.net/

    • Pros: Almost zero installation footprint. Javascript based engine uses the language we were all born knowing. Rich debugging because you can use the Windows Script Debugger. Fairly simple in design. Actively developed. Nice WinForms script helper. Good if you already dig the DOM.

      优点:安装空间几乎为零。 基于Java的引擎使用了我们天生知道的语言。 丰富的调试功能,因为您可以使用Windows脚本调试器。 设计上相当简单。 积极发展。 不错的WinForms脚本助手。 如果您已经研究过DOM,那就很好。

    • Cons: Slightly cheesy handling of model dialogs. Steals focus while running tests.

      缺点:对模型对话框的处理比较随意。 在运行测试时窃取焦点。

  • Selenium - http://selenium.thoughtworks.com/

    Selenium-http : //selenium.thoughtworks.com/

    • Pros: Good for testing cross browser compatibility. Actively worked on. Selenium tests can be expanded to use other languages.

      优点:适用于测试跨浏览器的兼容性。 积极工作。 Selenium测试可以扩展为使用其他语言。

    • Cons: Uses a Fit-like HTML as it's source code. This takes a mind shift and freaks out some folks. Server-side component required.

      缺点:使用类似Fit的HTML作为源代码。 这需要转变思路并吓到一些人。 需要服务器端组件。

    Selenium - http://selenium.thoughtworks.com/

    Selenium-http : //selenium.thoughtworks.com/

And the one I'm currently enamored with is Watir. There's a great comparison of Watir and Selenium by a contributor to both here.:

我现在最着迷的是Watir。 这里的贡献者对Watir和Selenium进行了很好的比较。

  • Watir (Pronounced "Water") Web Application Testing in Ruby - http://wtr.rubyforge.org/

    的Watir(发音为“水”)的Web应用测试在Ruby中- http://wtr.rubyforge.org/

    • Pros: Actively being worked on. Uses Ruby, the language du jour. Can run tests asychronously. Simple, elegant, fast. Ruby's interactive shell makes it easy to develop tests (more on this later in this post). Great support for client side things like script events, and even mouse rollovers.

      优点:积极地工作。 使用Ruby,即dujour语言。 可以异步运行测试。 简单,优雅,快速。 Ruby的交互式外壳使开发测试变得容易(本文稍后会对此进行更多介绍)。 对客户端事件(例如脚本事件,甚至鼠标悬停)的强大支持。

    • Cons: Haven't found any yet, but I'm sure they are out there. Very focused on the DOM.

      缺点:尚未找到任何东西,但我确定它们在那里。 非常关注DOM。

    Watir (Pronounced "Water") Web Application Testing in Ruby - http://wtr.rubyforge.org/

    的Watir(发音为“水”)的Web应用测试在Ruby中- http://wtr.rubyforge.org/

Ok, just to level set if you made it this far: Watir is an open source functional testing library for automated tests to be developed and run against a web browser. Cool?

好的,就目前而言,只要设定水平即可: Watir是一个开源功能测试库,用于针对要在Web浏览器上开发和运行的自动化测试。 凉?

Here's an example that visits Google, searches for "Programming Ruby" and confirms that it found what it was looking for. The stuff after the # are comments.

这是一个访问Google,搜索“ Programming Ruby”并确认其已找到所需内容的示例。 #之后的内容是注释。

require 'watir' # the watir controllerinclude Watir
test_site = 'http://www.google.com'ie = IE.newie.goto(test_site)ie.text_field(:name, "q").set("pickaxe") # q is the name of the search fieldie.button(:name, "btnG").click # "btnG" is the name of the Search buttonif ie.contains_text("Programming Ruby")   puts "Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results."else  puts "Test Failed! Could not find: 'Programming Ruby'" end

要求 瓦特尔 #watir控制器包括 瓦蒂尔test_site = “ http://www.google.com” 即 = IE浏览器 转到( test_site ) text_field (: name “ q” )。 设置( “ pickaxe” ) #q是搜索字段的名称即 按钮(:名称 “ btnG” )。 点击 #“ btnG”是“搜索”按钮的名称如果 contains_text ( “编程Ruby” ) 放 “测试通过。找到测试字符串:'Programming Ruby'。实际结果与预期结果匹配。” 其他放 “测试失败!找不到:'编程Ruby'” 结束

Very simple. So, Patrick and I wanted to integrate this into our NUnit tests, some of which already use Cassini for self-contained tests, and others are more complex but ultimately result in a web site. We wanted to do something like this from our existing infrastructure:

很简单。 因此,帕特里克和我想将其集成到我们的NUnit测试中,其中一些已经使用Cassini进行独立测试,而其他一些则更为复杂,但最终导致了网站的出现。 我们想在现有基础架构中执行以下操作:

[TestFixture]
    public class WatirTest 
    {
        public WatirTest(){}
 
        [Test]
        public void FirstTest()
        {
            WatirAssert.TestPassed("ibcexample.rb");
        }
    }

This was the Goal. We talked about adding [WatirTest] attributes or extending a new WatirTestCase and even a whole new series of Assertions, but we didn't see any reason to be tricky, other than to be tricky. We opted for simple simple simple.

这就是目标。 我们讨论了添加[WatirTest]属性或扩展新的WatirTestCase甚至是全新的断言系列,但是除了棘手之外,我们没有发现其他任何棘手的原因。 我们选择了简单简单简单。

public class WatirAssert 
{
    public static void TestPassed(string rubyFileName)
    {
        string output = String.Empty;
        using(Process p = new Process())
        {
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "ruby.exe";
            p.StartInfo.Arguments = rubyFileName;
            p.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
            p.Start();
            output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
        }
        Console.Write(output);
        Trace.Write(output);
        Regex reg = new Regex(@"(?<tests>\d+) tests, (?<assertions>\d+) assertions,                  (?<failures>\d+) failures, (?<errors>\d+) errors",
            RegexOptions.Compiled);
        Match m = reg.Match(output);
        try
        {
            int tests = int.Parse(m.Groups["tests"].Value);
            int assertions = int.Parse(m.Groups["assertions"].Value);
            int failures = int.Parse(m.Groups["failures"].Value);
            int errors = int.Parse(m.Groups["errors"].Value);
 
            if (tests > 0 && failures > 0) 
            {
                Assert.Fail(String.Format("WatirAssert: Failures {0}", failures));
            }
            else if (errors > 0) 
            {
                Assert.Fail(String.Format("WatirAssert: Errors {0}", errors));
            }
        }
        catch(Exception e)
        {
            Assert.Fail("WatirAssert EXCEPTION: " + e.ToString());
        }
    }
}

Using this, and armed with increasing knowledge of Ruby we started writing test cases (one per use case) for a large bank as a good test of this concept. These tests would run at the very end of the build process. After the build, test, docs, etc, we'd run the smoke (or integration) tests using Watir.

使用此工具,并随着对Ruby的了解越来越多,我们开始为大型银行编写测试用例(每个用例一个),作为对该概念的良好测试。 这些测试将在构建过程的最后运行。 构建,测试,文档等之后,我们将使用Watir运行冒烟(或集成)测试。

UPDATE: Your Ruby classes have to derive from the Ruby Unit Testing framework for this to work automatically. So your "template" would be (Note: the class name has an initial capital letter):

更新:您的Ruby类必须从Ruby Unit Testing框架派生,才能自动工作。 因此,您的“模板”应为(注意:类名具有首字母大写):

require 'watir'
include Watirrequire 'test/unit'

需要“ watir” 包括瓦蒂尔要求“测试/单位”

class TestExampleTemplate < Test::Unit::TestCase   def test_search
    ie = IE.new
    ie.goto("
http://www.google.com")
    ie.text_field(:name, "q").set("pickaxe")
    ie.button(:value, "Google Search").click
    assert(ie.contains_text("Programming Ruby, 2nd Ed."))
  end
end

类Test ExampleTemplate <Test :: Unit :: TestCase def test_search 即= IE.new ie.goto(“ http://www.google.com ”) ie.text_field(:name,“ q”)。set(“ pickaxe”) ie.button(:value,“ Google搜索”).click assert(ie.contains_text(“ Programming Ruby,2nd Ed。”)) 结束结束

Now, referring back to the syntax:

现在,回到语法:

ie.text_field(:name, "q").set("pickaxe") # q is the name of the search fieldie.button(:name, "btnG").click # "btnG" is the name of the Search button

text_field (: name “ q” )。 设置( “ pickaxe” ) #q是搜索字段的名称即 按钮(:名称 “ btnG” )。 点击 #“ btnG”是“搜索”按钮的名称

You may think it'll be a hassle to do a lot of View|Source work and figure out the names and IDs of these textboxes and buttons. However, even though Watir only runs IE (remember it wraps IE's COM stuff) FireFox presented a great way to avoid all that poking through HTML source. Yes, it's the greatest thing FireFox brought to the Web Developer (besides Venkman), it's the Web Developer Extension.

您可能会认为,麻烦的是执行大量View | Source工作并弄清楚这些文本框和按钮的名称和ID。 但是,即使Watir只运行IE(记住它包装了IE的COM内容),FireFox还是提供了一种避免通过HTML源代码进行戳戳的好方法。 是的,这是FireFox带给Web开发人员的最伟大的事情(除了Venkman之外),它是Web开发人员扩展。

Bring up your site in FireFox and from the Web Developer toolbar, click Forms|Display Form Details. Notice as in the screen shot below you'll get the IDs and Names of all your form elements. Then code your Watir script to them. Shiny.

在FireFox中打开您的站点,然后从Web Developer工具栏上,单击Forms | Display Form Details 。 请注意,如下面的屏幕快照所示,您将获得所有表单元素的ID和名称。 然后将您的Watir脚本编码给他们。 闪亮

If you want get Ruby and Watir and start playing:

如果您想获得Ruby和Watir并开始玩:

  • Download Ruby for Windows

    下载Ruby for Windows

  • Download Watir and run install.rb

    下载Watir并运行install.rb

  • Go into C:\watir_bonus\examples and run googleSuite_test.rb

    进入C:\ watir_bonus \ examples并运行googleSuite_test.rb

  • Then, look at articleExample.rb and make some changes to test your own site.

    然后,查看articleExample.rb并进行一些更改以测试您自己的站点。

  • Enjoy. Feel free to integrate into your NUnit tests if you like using our code above. If you expand it, let us know.请享用。 如果您喜欢使用我们上面的代码,请随时集成到您的NUnit测试中。 如果您将其扩展,请告诉我们。

翻译自: https://www.hanselman.com/blog/integrating-ruby-and-watir-with-nunit

将Ruby和Watir与NUnit集成相关推荐

  1. ruby Rspec+jenkins+allure持续集成

    1.Allure2使用说明 2.ruby下载allure的gem gem install allure-rspec 3.修改源码 C:\Ruby23-x64\lib\ruby\gems\2.3.0\g ...

  2. shell脚本spawn_如何使用child_process.spawn将Python / Ruby / PHP Shell脚本与Node.js集成

    shell脚本spawn There are occasions when running a Python/Ruby/PHP shell script from Node.js is necessa ...

  3. nunit 2.2.3 released, 支持vs2005 和.net 2.0了.

    主要是提供对vs 2005 及.net 2.0的支持,同时修正了一些bug.对于没有使用vs team suite的人而言,可以将nunit集成到vs 2005 professional了. http ...

  4. NUnit 入门知识

    1.介绍 NUnit 是一个免费开源的(http://www.nunit.org)产品,它提供了一套测试框架和一个测试运行程序(test runner).注意:test tunner 知道如何寻找具有 ...

  5. Watir测试工具简述

    Watir的官方网站 http://wtr.rubyforge.org/index.html Watir全称与发音 Watir全称是"Web Application Testing in R ...

  6. ruby实现按键精灵的功能

    先说下利用了AutoItX3.dll这个API,这个东西没有怎么办,ruby的watir GEM包里自带这个dll. 如果出现 "unknown OLE server: 'AutoItX3. ...

  7. 集成极光推送的一点说明

    http://blog.csdn.net/wwj_748/article/details/41867467 关于推送服务,国内有很多选择,笔者也对它们进行了一个详细的对比,一般我们产品选择推送服务主要 ...

  8. 单元测试与Nunit的基本使用

    一.单元测试是什么 单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证.对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体含义,如C语言中单元指一个函数,C# ...

  9. Scott Hanselman的2006 Windows最终开发者和高级用户工具列表

    enjoyed this post, or this blog, please 喜欢这篇文章或博客,请make a secure tax-deductable donation to the Amer ...

  10. PHP自动测试框架Top 10

    2019独角兽企业重金招聘Python工程师标准>>> 对于很多PHP开发新手来说,测试自己编写的代码是一个非常棘手的问题.如果出现问题,他们将不知道下一步该怎么做.花费很长的时间调 ...

最新文章

  1. 日常积累的一些linux和运维的东西 [转]
  2. js setTimeout 传递带参数的函数的2种方式
  3. Java实现线性表(顺序表,链表)
  4. Haproxy 管控台介绍
  5. 美国团购巨头是怎样衰落的
  6. MySQL优化详解(五)——MySQL分库分表
  7. opencv+Dlib python瘦脸代码
  8. 惠普z800工作站bios设置_HP工作站BIOS说明书适用Z228Z440Z230Z640Z840Z800Z620Z420Z820主板设置.doc...
  9. 为什么html中图片显示不出来,网页图片显示不出来是什么原因?
  10. CMOS逻辑门电路的重要技术参数
  11. 推荐几款网页截图工具可以全屏截图,也可对图片编辑
  12. 自同步扰乱编码器的原理与MATLAB仿真
  13. 用php语言说句情话,说给女朋友的感动情话50句
  14. 冷色调的亮度越高--越偏暖,暖色调的亮度越高--越偏冷
  15. Android课程设计-体育新闻app
  16. oppok3如何刷机_[oppok3刷机教程]oppok3怎么刷机
  17. 网页的linke rel=icon详解 favicon深究
  18. 传智播客 php系列,传智播客PHP 2015-JS高级系列视频教程 83集
  19. 传统教培机构搭建网校平台是否成必然的趋势?
  20. 如何制作我的第一个Phaser.js游戏

热门文章

  1. node.js历史版本下载安装
  2. java 四级联动,省市区镇四级联动附代码和数据库
  3. 博弈论——拍卖会(Auctions)
  4. LPC1788内部EEPROM使用的问题
  5. 视频编解码(三):H265编码器
  6. 有序表归并算法(数据结构学习笔记)
  7. volte的sip信令流程_VOLTE-SIP代码详解及SIP流程图解
  8. 阿里王坚:区块链与数据价值的交换
  9. 5款最好用的免费3D建模软件(附下载链接)
  10. 按时间抽取的基-2 FFT算法 C语言实现(快速傅里叶变换,蝶形算法)