<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>进化的测试 &#187; 自动化测试</title>
	<atom:link href="http://magustest.com/blog/tag/test-automation/feed/" rel="self" type="application/rss+xml" />
	<link>http://magustest.com/blog</link>
	<description>关注软件测试，白盒测试，自动化测试，性能测试</description>
	<lastBuildDate>Wed, 02 Jun 2010 16:12:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>DSL与自动化测试 &#8211; 用Python实现简单的DSL</title>
		<link>http://magustest.com/blog/automationtesting/dsl-automation-testing-using-python/</link>
		<comments>http://magustest.com/blog/automationtesting/dsl-automation-testing-using-python/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 06:15:32 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[自动化测试]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=655</guid>
		<description><![CDATA[自动化测试，一个在测试领域中被广为熟知，也是被谈论最多的概念之一。DSL (Domain Specific Language)，一种高度抽象，用于某个特定领域下编程语言。软件测试在大多数情况下都是对某个特定行业的软件系统进行测试，所以这两者应该可以很好的结合起来，事实上也是这样的，QTP里面的keyword view，其实就是DSL的一个实现。DSL一般可以分为两个大的类型，分别是External DSL 和 Internal DSL （引用自Martin Fowler）。External DSL 一般来说是跟其实现语言不一样的 DSL，常见的External DSL 有：SQL和XML配置文件；而Internal DSL 一般来说就是该DSL使用某个现成的编程语言（就是所谓的host language)，然后对host language进行一些改造而成。 我们在测试中会遇到很多问题，其中一些问题，几乎是所有公司所有团队都会遇到的，例如测试覆盖率不够，测试的时间不够等等。面对这些问题，自动化测试自然而然地成为解决这些问题的首选方法。但是自动化测试真的就是银弹麽？不见得！以前曾经在ASP.NET QA 的博客中给他们留言，请教过关于自动化测试的事情，我记得其中有一个回复是说，在某个release中过度地使用自动化测试，一切东西都想实现自动化测试，而忽略了产品本身的功能、特性的关注，结果就是超高的自动化测试覆盖率，但是很差的产品质量。大家都去实现自动化测试了，谁来做功能点的覆盖呢？某些领域的专家（SME），他们可能对测试技术是一无所知的，要把这些领域专家和测试实施结合起来，DSL就是一个比较好的桥梁。 我在工作中遇到的问题是，我需要测试一个类似UV（独立用户访问数）统计的系统，统计UV的方法其实就是根据_uid cookie的值来判断这个用户在某段时间内访问过我们的系统多少次，访问了哪些站点，进行了什么样的行为。其中有2个地方比较麻烦，第一就是在测试过程中要不断地拷贝cookie，这样拷来拷去两三次以后很容易就混乱，出错；第二就是需要记录访问哪些站点，这些站点都只是ID，也是需要不断地修改请求，测试时间长了也是很容易出错。所以我就打算在原来的测试工具基础上，实现一个简单的Internal DSL。先看成品： @tc def uniq_inventory_case01&#40;&#41;: test= testTool&#40;&#41; test.user&#40;'a'&#41;.view&#40;'asset55100002'&#41;.anetwork&#40;'55100'&#41;.onsite&#40;'site55100503'&#41;.snetwork&#40;'55100'&#41;.dnetwork&#40;'55100'&#41;.times&#40;1&#41;.go&#40;&#41; test.user&#40;'b'&#41;.view&#40;'asset55100002'&#41;.anetwork&#40;'55100'&#41;.onsite&#40;'site55100503'&#41;.snetwork&#40;'55100'&#41;.dnetwork&#40;'55100'&#41;.times&#40;2&#41;.go&#40;&#41; test.user&#40;'b'&#41;.view&#40;'asset55100002'&#41;.anetwork&#40;'55100'&#41;.onsite&#40;'site55100504_noad'&#41;.snetwork&#40;'55100'&#41;.dnetwork&#40;'55100'&#41;.times&#40;4&#41;.go&#40;&#41; 实例化一个testTool对象，然后就是指定哪个用户：user(&#8216;a&#8217;)或者user(&#8216;b&#8217;)，看的视频的ID：view(&#8216;asset55100002&#8242;)，这个视频属于哪个CRO呢？anetwork(&#8217;55100&#8242;)；放在哪个网站呢？onsite(&#8216;site55100503&#8242;)；网站是谁的呢？snetwork(&#8217;55100&#8242;)；谁是分发者呢？dnetwork(&#8217;55100&#8242;)；看了多少次呢？times(4)；最后一个有点儿丑陋的go()。 像这样子一句话里面N个方法连着用，就叫Method Chaining，Method Chaining通常可以让代码变得更加人性化，读起来更加容易。但是使用Method Chaining通常会遇到一个问题，就是很难判断就是到了哪个方法才是终结呢？是不是有些方法的调用是可选的，有些是必选的呢？其中一个解决方法就是我用到的，放一个.go()方法在最后，作为终结方法。要实现Method Chaining，其实只需要顶一个类，对于需要做连接的方法，最后都返回这个类的实例。例如： def view&#40;self, assetid&#41;: if assetid: self.asset_id = assetid return self &#160; def anetwork&#40;self, networkid&#41;: if [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>自动化测试，一个在测试领域中被广为熟知，也是被谈论最多的概念之一。DSL (Domain Specific Language)，一种高度抽象，用于某个特定领域下编程语言。软件测试在大多数情况下都是对某个特定行业的软件系统进行测试，所以这两者应该可以很好的结合起来，事实上也是这样的，QTP里面的keyword view，其实就是DSL的一个实现。DSL一般可以分为两个大的类型，分别是External DSL 和 Internal DSL （引用自Martin Fowler）。External DSL 一般来说是跟其实现语言不一样的 DSL，常见的External DSL 有：SQL和XML配置文件；而Internal DSL 一般来说就是该DSL使用某个现成的编程语言（就是所谓的host language)，然后对host language进行一些改造而成。</p>
<p>我们在测试中会遇到很多问题，其中一些问题，几乎是所有公司所有团队都会遇到的，例如测试覆盖率不够，测试的时间不够等等。面对这些问题，自动化测试自然而然地成为解决这些问题的首选方法。但是自动化测试真的就是银弹麽？不见得！以前曾经在ASP.NET QA 的博客中给他们留言，请教过关于自动化测试的事情，我记得其中有一个回复是说，在某个release中过度地使用自动化测试，一切东西都想实现自动化测试，而忽略了产品本身的功能、特性的关注，结果就是超高的自动化测试覆盖率，但是很差的产品质量。大家都去实现自动化测试了，谁来做功能点的覆盖呢？某些领域的专家（SME），他们可能对测试技术是一无所知的，要把这些领域专家和测试实施结合起来，DSL就是一个比较好的桥梁。</p>
<p>我在工作中遇到的问题是，我需要测试一个类似UV（独立用户访问数）统计的系统，统计UV的方法其实就是根据_uid cookie的值来判断这个用户在某段时间内访问过我们的系统多少次，访问了哪些站点，进行了什么样的行为。其中有2个地方比较麻烦，第一就是在测试过程中要不断地拷贝cookie，这样拷来拷去两三次以后很容易就混乱，出错；第二就是需要记录访问哪些站点，这些站点都只是ID，也是需要不断地修改请求，测试时间长了也是很容易出错。所以我就打算在原来的测试工具基础上，实现一个简单的Internal DSL。先看成品：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@tc
<span style="color: #ff7700;font-weight:bold;">def</span> uniq_inventory_case01<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">test</span>= testTool<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">test</span>.<span style="color: #dc143c;">user</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'a'</span><span style="color: black;">&#41;</span>.<span style="color: black;">view</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'asset55100002'</span><span style="color: black;">&#41;</span>.<span style="color: black;">anetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">onsite</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'site55100503'</span><span style="color: black;">&#41;</span>.<span style="color: black;">snetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">dnetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">times</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>.<span style="color: black;">go</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">test</span>.<span style="color: #dc143c;">user</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'b'</span><span style="color: black;">&#41;</span>.<span style="color: black;">view</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'asset55100002'</span><span style="color: black;">&#41;</span>.<span style="color: black;">anetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">onsite</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'site55100503'</span><span style="color: black;">&#41;</span>.<span style="color: black;">snetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">dnetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">times</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>.<span style="color: black;">go</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">test</span>.<span style="color: #dc143c;">user</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'b'</span><span style="color: black;">&#41;</span>.<span style="color: black;">view</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'asset55100002'</span><span style="color: black;">&#41;</span>.<span style="color: black;">anetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">onsite</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'site55100504_noad'</span><span style="color: black;">&#41;</span>.<span style="color: black;">snetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">dnetwork</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'55100'</span><span style="color: black;">&#41;</span>.<span style="color: black;">times</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>.<span style="color: black;">go</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>实例化一个testTool对象，然后就是指定哪个用户：user(&#8216;a&#8217;)或者user(&#8216;b&#8217;)，看的视频的ID：view(&#8216;asset55100002&#8242;)，这个视频属于哪个CRO呢？anetwork(&#8217;55100&#8242;)；放在哪个网站呢？onsite(&#8216;site55100503&#8242;)；网站是谁的呢？snetwork(&#8217;55100&#8242;)；谁是分发者呢？dnetwork(&#8217;55100&#8242;)；看了多少次呢？times(4)；最后一个有点儿丑陋的go()。</p>
<p>像这样子一句话里面N个方法连着用，就叫Method Chaining，Method Chaining通常可以让代码变得更加人性化，读起来更加容易。但是使用Method Chaining通常会遇到一个问题，就是很难判断就是到了哪个方法才是终结呢？是不是有些方法的调用是可选的，有些是必选的呢？其中一个解决方法就是我用到的，放一个.go()方法在最后，作为终结方法。要实现Method Chaining，其实只需要顶一个类，对于需要做连接的方法，最后都返回这个类的实例。例如：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> view<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, assetid<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> assetid:     <span style="color: #008000;">self</span>.<span style="color: black;">asset_id</span> = assetid
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> anetwork<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, networkid<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> networkid:   <span style="color: #008000;">self</span>.<span style="color: black;">a_network_id</span> = networkid
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> snetwork<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, networkid<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> networkid:   <span style="color: #008000;">self</span>.<span style="color: black;">s_network_id</span> = networkid
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> dnetwork<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, networkid<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> networkid:   <span style="color: #008000;">self</span>.<span style="color: black;">d_network_id</span> = networkid
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> onsite<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, sectionid<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> sectionid:   <span style="color: #008000;">self</span>.<span style="color: black;">site_section_id</span> = sectionid
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> times<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, times<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> times<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">0</span>:       <span style="color: #008000;">self</span>.<span style="color: black;">request_times</span> = times
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span></pre></div></div>

<p>最后一个终结方法go()，就做真正的处理</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> go<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">asset_id</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">site_section_id</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">times</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">a_network_id</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">s_network_id</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">prepareRequest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request_times</span><span style="color: black;">&#41;</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">sendRequest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">cleanup</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        info = <span style="color: #483d8b;">'Required information missing, abort running.'</span>
        <span style="color: #dc143c;">logging</span>.<span style="color: black;">debug</span><span style="color: black;">&#40;</span>info<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> info</pre></div></div>

<p>如果是实现一个External DSL 的话，的确难度不小；但是Internal DSL其实并不是很高深，也不是很难实现，在它的帮助下，可以把工作完成的更好，对自己以后维护测试用例也带来了不少方便。</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F&amp;t=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F&title=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F&title=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F&amp;title=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=DSL%E4%B8%8E%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%20-%20%E7%94%A8Python%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E7%9A%84DSL%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdsl-automation-testing-using-python%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/automationtesting/dsl-automation-testing-using-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>自动化测试中的sleep</title>
		<link>http://magustest.com/blog/automationtesting/sleep-in-test-automation/</link>
		<comments>http://magustest.com/blog/automationtesting/sleep-in-test-automation/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 13:44:40 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[自动化测试]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=647</guid>
		<description><![CDATA[最近在修改公司现有的一个自动化测试框架，里面用了很多time.sleep()方法，看着不是很爽，为什么我觉得sleep方法在自动化测试中不应该过多的使用呢，我甚至觉得应该尽可能避免sleep方法的使用，sleep可以作为增加自动化测试稳定性的手段，但是不能依赖sleep来让自动化系统稳定。 举个例子，如果一个UI的自动化测试，需要等待某个页面load完成以后才进行操作，那么需要对那个页面是否已经Load完成进行判断，而不应该sleep(x)，x是一个magic number，有时候1、2秒就足以，有时候它却不知道有多大，因为已经超时了！那如果我们在check页面状态之前做一个短时间的sleep，那么在某些场合下可以增加这个自动化测试的稳定性，但是最终整个自动化测试的脚本是不会依赖于这个sleep的语句来达到稳定的。 在做自动化测试的时候，最常见的两种判断就是1. 某程序已经成功启动，某页面已经加载完毕。 2. 某程序已经正常关闭，某服务已经顺利停止。 回到实际的工作，我要判断被测的程序是否已经正常启动，可以用系统提供的一些工具，或者调用一些接口，例如SNMP命令，或者是调用一下Lua脚本等，如果他们都返回我们期望的数据，那么可以认为程序已经成功启动了。反之，如果前面的这些命令出错了，那么我也可以认为程序已经是关闭了的。 要实现自动化测试，就必须要让测试代码每时每刻都掌握着被测系统的状态，sleep方法会让自动化测试脚本的行为变得诡异。 Share and Enjoy: No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>最近在修改公司现有的一个自动化测试框架，里面用了很多time.sleep()方法，看着不是很爽，为什么我觉得sleep方法在自动化测试中不应该过多的使用呢，我甚至觉得应该尽可能避免sleep方法的使用，sleep可以作为增加自动化测试稳定性的手段，但是不能依赖sleep来让自动化系统稳定。</p>
<p>举个例子，如果一个UI的自动化测试，需要等待某个页面load完成以后才进行操作，那么需要对那个页面是否已经Load完成进行判断，而不应该sleep(x)，x是一个magic number，有时候1、2秒就足以，有时候它却不知道有多大，因为已经超时了！那如果我们在check页面状态之前做一个短时间的sleep，那么在某些场合下可以增加这个自动化测试的稳定性，但是最终整个自动化测试的脚本是不会依赖于这个sleep的语句来达到稳定的。</p>
<p>在做自动化测试的时候，最常见的两种判断就是1. 某程序已经成功启动，某页面已经加载完毕。 2. 某程序已经正常关闭，某服务已经顺利停止。</p>
<p>回到实际的工作，我要判断被测的程序是否已经正常启动，可以用系统提供的一些工具，或者调用一些接口，例如SNMP命令，或者是调用一下Lua脚本等，如果他们都返回我们期望的数据，那么可以认为程序已经成功启动了。反之，如果前面的这些命令出错了，那么我也可以认为程序已经是关闭了的。</p>
<p>要实现自动化测试，就必须要让测试代码每时每刻都掌握着被测系统的状态，sleep方法会让<a href="http://magustest.com/blog/automationtesting/avoid-flakey-automation-test/" target="_blank">自动化测试脚本的行为变得诡异</a>。</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&amp;annotation=%E6%9C%80%E8%BF%91%E5%9C%A8%E4%BF%AE%E6%94%B9%E5%85%AC%E5%8F%B8%E7%8E%B0%E6%9C%89%E7%9A%84%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%EF%BC%8C%E9%87%8C%E9%9D%A2%E7%94%A8%E4%BA%86%E5%BE%88%E5%A4%9Atime.sleep%28%29%E6%96%B9%E6%B3%95%EF%BC%8C%E7%9C%8B%E7%9D%80%E4%B8%8D%E6%98%AF%E5%BE%88%E7%88%BD%EF%BC%8C%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E8%A7%89%E5%BE%97sleep%E6%96%B9%E6%B3%95%E5%9C%A8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%B8%8D%E5%BA%94%E8%AF%A5%E8%BF%87%E5%A4%9A%E7%9A%84%E4%BD%BF%E7%94%A8%E5%91%A2%EF%BC%8C%E6%88%91%E7%94%9A%E8%87%B3%E8%A7%89%E5%BE%97%E5%BA%94%E8%AF%A5%E5%B0%BD%E5%8F%AF%E8%83%BD%E9%81%BF%E5%85%8Dsleep%E6%96%B9%E6%B3%95%E7%9A%84" title="Google Bookmarks"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&amp;bodytext=%E6%9C%80%E8%BF%91%E5%9C%A8%E4%BF%AE%E6%94%B9%E5%85%AC%E5%8F%B8%E7%8E%B0%E6%9C%89%E7%9A%84%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%EF%BC%8C%E9%87%8C%E9%9D%A2%E7%94%A8%E4%BA%86%E5%BE%88%E5%A4%9Atime.sleep%28%29%E6%96%B9%E6%B3%95%EF%BC%8C%E7%9C%8B%E7%9D%80%E4%B8%8D%E6%98%AF%E5%BE%88%E7%88%BD%EF%BC%8C%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E8%A7%89%E5%BE%97sleep%E6%96%B9%E6%B3%95%E5%9C%A8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%B8%8D%E5%BA%94%E8%AF%A5%E8%BF%87%E5%A4%9A%E7%9A%84%E4%BD%BF%E7%94%A8%E5%91%A2%EF%BC%8C%E6%88%91%E7%94%9A%E8%87%B3%E8%A7%89%E5%BE%97%E5%BA%94%E8%AF%A5%E5%B0%BD%E5%8F%AF%E8%83%BD%E9%81%BF%E5%85%8Dsleep%E6%96%B9%E6%B3%95%E7%9A%84" title="Digg"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&amp;notes=%E6%9C%80%E8%BF%91%E5%9C%A8%E4%BF%AE%E6%94%B9%E5%85%AC%E5%8F%B8%E7%8E%B0%E6%9C%89%E7%9A%84%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%EF%BC%8C%E9%87%8C%E9%9D%A2%E7%94%A8%E4%BA%86%E5%BE%88%E5%A4%9Atime.sleep%28%29%E6%96%B9%E6%B3%95%EF%BC%8C%E7%9C%8B%E7%9D%80%E4%B8%8D%E6%98%AF%E5%BE%88%E7%88%BD%EF%BC%8C%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E8%A7%89%E5%BE%97sleep%E6%96%B9%E6%B3%95%E5%9C%A8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%B8%8D%E5%BA%94%E8%AF%A5%E8%BF%87%E5%A4%9A%E7%9A%84%E4%BD%BF%E7%94%A8%E5%91%A2%EF%BC%8C%E6%88%91%E7%94%9A%E8%87%B3%E8%A7%89%E5%BE%97%E5%BA%94%E8%AF%A5%E5%B0%BD%E5%8F%AF%E8%83%BD%E9%81%BF%E5%85%8Dsleep%E6%96%B9%E6%B3%95%E7%9A%84" title="del.icio.us"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;t=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&amp;body=%E6%9C%80%E8%BF%91%E5%9C%A8%E4%BF%AE%E6%94%B9%E5%85%AC%E5%8F%B8%E7%8E%B0%E6%9C%89%E7%9A%84%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%EF%BC%8C%E9%87%8C%E9%9D%A2%E7%94%A8%E4%BA%86%E5%BE%88%E5%A4%9Atime.sleep%28%29%E6%96%B9%E6%B3%95%EF%BC%8C%E7%9C%8B%E7%9D%80%E4%B8%8D%E6%98%AF%E5%BE%88%E7%88%BD%EF%BC%8C%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E8%A7%89%E5%BE%97sleep%E6%96%B9%E6%B3%95%E5%9C%A8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E4%B8%8D%E5%BA%94%E8%AF%A5%E8%BF%87%E5%A4%9A%E7%9A%84%E4%BD%BF%E7%94%A8%E5%91%A2%EF%BC%8C%E6%88%91%E7%94%9A%E8%87%B3%E8%A7%89%E5%BE%97%E5%BA%94%E8%AF%A5%E5%B0%BD%E5%8F%AF%E8%83%BD%E9%81%BF%E5%85%8Dsleep%E6%96%B9%E6%B3%95%E7%9A%84" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84sleep%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fsleep-in-test-automation%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/automationtesting/sleep-in-test-automation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>实现数据驱动的CodedUI Test</title>
		<link>http://magustest.com/blog/automationtesting/data-driven-codedui-test/</link>
		<comments>http://magustest.com/blog/automationtesting/data-driven-codedui-test/#comments</comments>
		<pubDate>Thu, 21 May 2009 02:37:05 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[自动化测试]]></category>
		<category><![CDATA[CodedUI Test]]></category>
		<category><![CDATA[VSTS]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=498</guid>
		<description><![CDATA[昨天介绍了如何创建一个简单的CodedUI Test。我们也知道，依靠录制回放产生的自动化测试是非常不可靠的，那些在微软的大牛们肯定也早就知道了。虽然用VSTS录制一个自动化测试脚本的过程不是那么友好，也不是很方便，不过它产生的测试代码修改起来还是比较容易的。下面我们就看看如何把一个简单的CodedUI Test改造为数据驱动脚本。 对于每一段录制的操作，VSTS都可以把它抽象成一个方法，它会把这些操作以静态方法的形式存放在一个叫RecordedMethods的类里面。可以对这些方法做任意的修改，我就把给需要输入的方法增加一个输入的参数。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class RecordedMethods &#123; public static void FirstClick&#40;TestContext testContext, string first&#41; &#123; //第一个输入 &#125; &#160; public static void Operation&#40;TestContext testContext, string operater&#41; &#123; //操作符 &#125; &#160; public static void [...]


Related posts:<ol><li><a href='http://magustest.com/blog/whiteboxtesting/three-different-test-fixture-setup-approach/' rel='bookmark' title='Permanent Link: 单元测试中三种准备Test Fixture的方法比较'>单元测试中三种准备Test Fixture的方法比较</a></li>
<li><a href='http://magustest.com/blog/automationtesting/create-web-test-plugin-in-vsts/' rel='bookmark' title='Permanent Link: 在VSTS中创建Web Test的插件'>在VSTS中创建Web Test的插件</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/unit-test-pattern/' rel='bookmark' title='Permanent Link: 单元测试中的常用测试模式'>单元测试中的常用测试模式</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>昨天介绍了<a href="http://magustest.com/blog/softwaretesting/vsts2010-test-edition-article-collection/" target="_blank">如何创建一个简单的CodedUI Test</a>。我们也知道，依靠录制回放产生的自动化测试是非常不可靠的，那些在微软的大牛们肯定也早就知道了。虽然用VSTS录制一个自动化测试脚本的过程不是那么友好，也不是很方便，不过它产生的测试代码修改起来还是比较容易的。下面我们就看看如何把一个简单的CodedUI Test改造为数据驱动脚本。</p>
<p>对于每一段录制的操作，VSTS都可以把它抽象成一个方法，它会把这些操作以静态方法的形式存放在一个叫RecordedMethods的类里面。可以对这些方法做任意的修改，我就把给需要输入的方法增加一个输入的参数。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> RecordedMethods
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> FirstClick<span style="color: #000000;">&#40;</span>TestContext testContext, <span style="color: #FF0000;">string</span> first<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//第一个输入</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Operation<span style="color: #000000;">&#40;</span>TestContext testContext, <span style="color: #FF0000;">string</span> operater<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//操作符</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> SecordClick<span style="color: #000000;">&#40;</span>TestContext testContext, <span style="color: #FF0000;">string</span> second<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//第二个输入</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> GetResult<span style="color: #000000;">&#40;</span>TestContext testContext<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//按那个等于号</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-498"></span></p>
<p>这些方法其实是怎么工作的呢？</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Click<span style="color: #000000;">&#40;</span>TestContext testContext, <span style="color: #FF0000;">string</span> first<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// Click '1' button</span>
	WinWindow 计算器Window <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WinWindow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#region Search Criteria</span>
	计算器Window.<span style="color: #0000FF;">SearchProperties</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Name&quot;</span>, <span style="color: #666666;">&quot;计算器&quot;</span>, <span style="color: #666666;">&quot;ClassName&quot;</span>, <span style="color: #666666;">&quot;SciCalc&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#endregion</span>
	WinWindow item1Window <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WinWindow<span style="color: #000000;">&#40;</span>计算器Window<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#region Search Criteria</span>
	item1Window.<span style="color: #0000FF;">SearchProperties</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ControlId&quot;</span>, <span style="color: #666666;">&quot;125&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#endregion</span>
	WinButton item1Button <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WinButton<span style="color: #000000;">&#40;</span>item1Window<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#region Search Criteria</span>
	item1Button.<span style="color: #0000FF;">SearchProperties</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Name&quot;</span>, first<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008080;">#endregion</span>
	Mouse.<span style="color: #0000FF;">Click</span><span style="color: #000000;">&#40;</span>item1Button, <span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span>, <span style="color: #FF0000;">12</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>首先是创建一个WinWindow对象，这个WinWindow类最终是继承自UITestControl类，这个类在Microsoft.VisualStudio.TestTools.UITesting.dll，是VSTS2010新引入的。程序首先找到计算器这个窗口，然后在计数器窗口上面找到输入的控件，然后在输入的控件上找到具体点击的按钮。这里我只需要对最后的一个搜索的条件进行参数化就可以了。</p>
<p>下面就是要准备一些数据作为输入：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;testdatas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>+<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/first<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/last<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expected<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/testdatas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>通过向该CodedUI Test添加数据源，实现简单的数据驱动。<br />
<img class="alignnone size-full wp-image-501" title="test-data" src="http://magustest.com/blog/wp-content/uploads/2009/05/test-data1.png" alt="test-data" width="540" height="476" /></p>
<p>完成后的代码如下</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddOperationTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// From the context menu, select &quot;Edit CodedUITest&quot; and choose any of options to add automation code.</span>
	RecordedMethods.<span style="color: #0000FF;">Click</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TestContext</span>, TestContext.<span style="color: #0000FF;">DataRow</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;First&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RecordedMethods.<span style="color: #0000FF;">Click</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TestContext</span>, TestContext.<span style="color: #0000FF;">DataRow</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Operator&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RecordedMethods.<span style="color: #0000FF;">Click</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TestContext</span>, TestContext.<span style="color: #0000FF;">DataRow</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Last&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RecordedMethods.<span style="color: #0000FF;">GetResult</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TestContext</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Validate UIItemEdit.Text AreEqual 'xxx. '</span>
	Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span>TestContext.<span style="color: #0000FF;">DataRow</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Expected&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">+</span><span style="color: #666666;">&quot;. &quot;</span>, UIMap.<span style="color: #0000FF;">UI</span>计算器Window.<span style="color: #0000FF;">UIItemWindow</span>.<span style="color: #0000FF;">UIItemEdit</span>.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>体会：VSTS自动生成的那个RecordedMethods类，里面的方法都是可以重用的，稍加修改，就能达到比较好的效果，同时也需要对这个类的方法进行清理。例如在本文中，RecordedMethods类中总共有4个方法，其中的三个方法FirstClick，Operation，SecordClick，它们其实都是一样的，就是点击计数器上的某个按钮，所以说这3个方法可以统一为一个方法Click。</p>
<p>微软一直以来所提供的傻瓜式的数据驱动的支持，很好地帮助我们实现数据驱动，有利于把测试脚本的编写与测试的设计分离。这一点如果有安装了TFS以后就能体验到，CodedUI Test可以与某个测试用例关联起来，公用数据。</p>
<p>如果大家对CodedUI Test很感兴趣，推荐大家看这个人（<a href="http://blogs.msdn.com/mathew_aniyan/default.aspx" target="_blank">Mathew Aniyan</a>）的博客，满城尽带CodedUI Test。</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&amp;title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&amp;bodytext=%E6%98%A8%E5%A4%A9%E4%BB%8B%E7%BB%8D%E4%BA%86%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84CodedUI%20Test%E3%80%82%E6%88%91%E4%BB%AC%E4%B9%9F%E7%9F%A5%E9%81%93%EF%BC%8C%E4%BE%9D%E9%9D%A0%E5%BD%95%E5%88%B6%E5%9B%9E%E6%94%BE%E4%BA%A7%E7%94%9F%E7%9A%84%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%98%AF%E9%9D%9E%E5%B8%B8%E4%B8%8D%E5%8F%AF%E9%9D%A0%E7%9A%84%EF%BC%8C%E9%82%A3%E4%BA%9B%E5%9C%A8%E5%BE%AE%E8%BD%AF%E7%9A%84%E5%A4%A7%E7%89%9B%E4%BB%AC%E8%82%AF%E5%AE%9A%E4%B9%9F%E6%97%A9%E5%B0%B1%E7%9F%A5%E9%81%93%E4%BA%86%E3%80%82%E8%99%BD%E7%84%B6%E7%94%A8VSTS%E5%BD%95%E5%88%B6%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC%E7%9A%84%E8%BF%87%E7%A8%8B" title="Digg"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&amp;title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&amp;notes=%E6%98%A8%E5%A4%A9%E4%BB%8B%E7%BB%8D%E4%BA%86%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84CodedUI%20Test%E3%80%82%E6%88%91%E4%BB%AC%E4%B9%9F%E7%9F%A5%E9%81%93%EF%BC%8C%E4%BE%9D%E9%9D%A0%E5%BD%95%E5%88%B6%E5%9B%9E%E6%94%BE%E4%BA%A7%E7%94%9F%E7%9A%84%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%98%AF%E9%9D%9E%E5%B8%B8%E4%B8%8D%E5%8F%AF%E9%9D%A0%E7%9A%84%EF%BC%8C%E9%82%A3%E4%BA%9B%E5%9C%A8%E5%BE%AE%E8%BD%AF%E7%9A%84%E5%A4%A7%E7%89%9B%E4%BB%AC%E8%82%AF%E5%AE%9A%E4%B9%9F%E6%97%A9%E5%B0%B1%E7%9F%A5%E9%81%93%E4%BA%86%E3%80%82%E8%99%BD%E7%84%B6%E7%94%A8VSTS%E5%BD%95%E5%88%B6%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC%E7%9A%84%E8%BF%87%E7%A8%8B" title="del.icio.us"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&amp;t=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&amp;title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F&amp;title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&amp;body=%E6%98%A8%E5%A4%A9%E4%BB%8B%E7%BB%8D%E4%BA%86%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84CodedUI%20Test%E3%80%82%E6%88%91%E4%BB%AC%E4%B9%9F%E7%9F%A5%E9%81%93%EF%BC%8C%E4%BE%9D%E9%9D%A0%E5%BD%95%E5%88%B6%E5%9B%9E%E6%94%BE%E4%BA%A7%E7%94%9F%E7%9A%84%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%98%AF%E9%9D%9E%E5%B8%B8%E4%B8%8D%E5%8F%AF%E9%9D%A0%E7%9A%84%EF%BC%8C%E9%82%A3%E4%BA%9B%E5%9C%A8%E5%BE%AE%E8%BD%AF%E7%9A%84%E5%A4%A7%E7%89%9B%E4%BB%AC%E8%82%AF%E5%AE%9A%E4%B9%9F%E6%97%A9%E5%B0%B1%E7%9F%A5%E9%81%93%E4%BA%86%E3%80%82%E8%99%BD%E7%84%B6%E7%94%A8VSTS%E5%BD%95%E5%88%B6%E4%B8%80%E4%B8%AA%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC%E7%9A%84%E8%BF%87%E7%A8%8B" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E9%A9%B1%E5%8A%A8%E7%9A%84CodedUI%20Test%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fdata-driven-codedui-test%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>Related posts:<ol><li><a href='http://magustest.com/blog/whiteboxtesting/three-different-test-fixture-setup-approach/' rel='bookmark' title='Permanent Link: 单元测试中三种准备Test Fixture的方法比较'>单元测试中三种准备Test Fixture的方法比较</a></li>
<li><a href='http://magustest.com/blog/automationtesting/create-web-test-plugin-in-vsts/' rel='bookmark' title='Permanent Link: 在VSTS中创建Web Test的插件'>在VSTS中创建Web Test的插件</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/unit-test-pattern/' rel='bookmark' title='Permanent Link: 单元测试中的常用测试模式'>单元测试中的常用测试模式</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/automationtesting/data-driven-codedui-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>开源自动化测试框架WatiN 2.0 CTP2已经发布</title>
		<link>http://magustest.com/blog/automationtesting/watin-ctp2-released/</link>
		<comments>http://magustest.com/blog/automationtesting/watin-ctp2-released/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 09:10:16 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[自动化测试]]></category>
		<category><![CDATA[WatiN]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=315</guid>
		<description><![CDATA[WatiN是一个开源自动化测试框架，在一些中小型的项目中可以取代昂贵的商业工具，例如QTP。今天WatiN发布了第二个社区预览版(CTP)。这个版本的详细release note还没有出来，但是我已经发现了一个非常好的改进，就是抽象出了IBrowser接口，IE和Firefox这两个类都实现了IBrowser接口，真的可以实现写一次代码，在若干个不同的浏览器中运行自动化测试了。 写一个简单的方法，这个方法要做的就是浏览MySpace聚友网的主页，然后检查一下有没有“关于我们”这段文字（但是即使不存在也没事，这个例子只是意思意思）。 1 2 3 4 5 private void BrowseMySpaceSplash&#40;IBrowser browser&#41; &#123; browser.GoTo&#40;&#34;www.myspace.cn&#34;&#41;; browser.ContainsText&#40;&#34;关于我们&#34;&#41;; &#125; 枚举BrowserType里面所以的值（现在有IE和Firefox这两个），创建浏览器对象，然后作为参数传递给刚才的方法，这就是一个简单的一段自动化测试代码运行在IE和Firefox两种浏览器上的实现。 1 2 3 4 5 6 7 8 9 private void button1_Click&#40;object sender, EventArgs e&#41; &#123; foreach &#40;BrowserType bt in Enum.GetValues&#40;typeof&#40;BrowserType&#41;&#41;&#41; &#123; IBrowser browser = BrowserFactory.Create&#40;bt&#41;; BrowseMySpaceSplash&#40;browser&#41;; browser.Dispose&#40;&#41;; &#125; &#125; 注意：要让Firefox能正常运行自动化测试，需要在WatiN目录下的Mozilla目录中安装相应的Firefox插件。 其实WatiN已经比较好用，而且比较轻，完全有可能代替诸如QTP这样庞大而昂贵的商业工具。当然，大家还可以选择Selenium Share and Enjoy: > Related posts:在VSTS中创建Web [...]


Related posts:<ol><li><a href='http://magustest.com/blog/automationtesting/create-web-test-plugin-in-vsts/' rel='bookmark' title='Permanent Link: 在VSTS中创建Web Test的插件'>在VSTS中创建Web Test的插件</a></li>
<li><a href='http://magustest.com/blog/automationtesting/adding-web-test-verifaction-rule/' rel='bookmark' title='Permanent Link: 自己动手创建Web测试验证规则'>自己动手创建Web测试验证规则</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="https://sourceforge.net/projects/watin/" target="_blank">WatiN</a>是一个开源自动化测试框架，在一些中小型的项目中可以取代昂贵的商业工具，例如QTP。今天WatiN发布了第二个社区预览版(CTP)。这个版本的详细release note还没有出来，但是我已经发现了一个非常好的改进，就是抽象出了IBrowser接口，IE和Firefox这两个类都实现了IBrowser接口，真的可以实现写一次代码，在若干个不同的浏览器中运行自动化测试了。</p>
<p>写一个简单的方法，这个方法要做的就是浏览MySpace聚友网的主页，然后检查一下有没有“关于我们”这段文字（但是即使不存在也没事，这个例子只是意思意思）。<br />
<span id="more-315"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> BrowseMySpaceSplash<span style="color: #000000;">&#40;</span>IBrowser browser<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    browser.<span style="color: #0600FF;">GoTo</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;www.myspace.cn&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    browser.<span style="color: #0000FF;">ContainsText</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;关于我们&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>枚举BrowserType里面所以的值（现在有IE和Firefox这两个），创建浏览器对象，然后作为参数传递给刚才的方法，这就是一个简单的一段自动化测试代码运行在IE和Firefox两种浏览器上的实现。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>BrowserType bt <span style="color: #0600FF;">in</span> <span style="color: #FF0000;">Enum</span>.<span style="color: #0000FF;">GetValues</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>BrowserType<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        IBrowser browser <span style="color: #008000;">=</span> BrowserFactory.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>bt<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        BrowseMySpaceSplash<span style="color: #000000;">&#40;</span>browser<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        browser.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>注意：要让Firefox能正常运行自动化测试，需要在WatiN目录下的Mozilla目录中安装相应的Firefox插件。</p>
<p>其实WatiN已经比较好用，而且比较轻，完全有可能代替诸如QTP这样庞大而昂贵的商业工具。当然，大家还可以选择Selenium</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F&amp;t=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F&title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F&title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F&amp;title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F&amp;title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83&amp;body=WatiN%E6%98%AF%E4%B8%80%E4%B8%AA%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6%EF%BC%8C%E5%9C%A8%E4%B8%80%E4%BA%9B%E4%B8%AD%E5%B0%8F%E5%9E%8B%E7%9A%84%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%8F%AF%E4%BB%A5%E5%8F%96%E4%BB%A3%E6%98%82%E8%B4%B5%E7%9A%84%E5%95%86%E4%B8%9A%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%BE%8B%E5%A6%82QTP%E3%80%82%E4%BB%8A%E5%A4%A9WatiN%E5%8F%91%E5%B8%83%E4%BA%86%E7%AC%AC%E4%BA%8C%E4%B8%AA%E7%A4%BE%E5%8C%BA%E9%A2%84%E8%A7%88%E7%89%88%28CTP%29%E3%80%82%E8%BF%99%E4%B8%AA%E7%89%88%E6%9C%AC%E7%9A%84%E8%AF%A6%E7%BB%86release%20note%E8%BF%98%E6%B2%A1%E6%9C%89%E5%87%BA%E6%9D%A5%EF%BC%8C%E4%BD%86%E6%98%AF%E6%88%91%E5%B7%B2%E7%BB%8F%E5%8F%91%E7%8E%B0%E4%BA%86%E4" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%E5%BC%80%E6%BA%90%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6WatiN%202.0%20CTP2%E5%B7%B2%E7%BB%8F%E5%8F%91%E5%B8%83%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fautomationtesting%2Fwatin-ctp2-released%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>Related posts:<ol><li><a href='http://magustest.com/blog/automationtesting/create-web-test-plugin-in-vsts/' rel='bookmark' title='Permanent Link: 在VSTS中创建Web Test的插件'>在VSTS中创建Web Test的插件</a></li>
<li><a href='http://magustest.com/blog/automationtesting/adding-web-test-verifaction-rule/' rel='bookmark' title='Permanent Link: 自己动手创建Web测试验证规则'>自己动手创建Web测试验证规则</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/automationtesting/watin-ctp2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
