<?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; Selenium</title>
	<atom:link href="http://blog.liuhongwei.cn/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.liuhongwei.cn</link>
	<description>Agile, Startup, 产品管理, Google开发, iPhone开发</description>
	<lastBuildDate>Fri, 30 Jul 2010 10:31:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Selenium测试支持JavaScript</title>
		<link>http://blog.liuhongwei.cn/agile/selenium-javascript/</link>
		<comments>http://blog.liuhongwei.cn/agile/selenium-javascript/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 12:44:21 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Agile开发]]></category>
		<category><![CDATA[工具]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=92</guid>
		<description><![CDATA[Agile自动测试的重要利器，Selenium测试，功能强劲，适合对web程序进行自动测试。测试脚本，一次编写，反复自动测试，在开发过程中，起到了将功能锁定的作用。
今天有同事问，Selenium测试脚本，是否可以获取当前日期？查了一下发现可以。而且可以把当前日期以各种形式保存在脚本中，供此后输入、比较等操作。这一切源于，Selenium测试脚本可以执行JavaScript片段，这样，JavaScript具有的各种功能，都可以提供给Selenium测试了。
下面这个脚本，可以获取当前日期，可以把日期存储在currentdate变量中，可以用该变量比较界面上的值，还可以把变量的值输入到浏览器的输入框。

&#60;tr&#62;
 &#60;td&#62;type&#60;/td&#62;
 &#60;td&#62;classCIpRanges[0].readableIpAddressRange&#60;/td&#62;
 &#60;td&#62;javascript{&#38;quot;&#38;quot;+((new Date()).getMonth()+1)+&#38;quot;/&#38;quot;+(new Date()).getDate()+&#38;quot;/&#38;quot;+(new Date()).getFullYear()}&#60;/td&#62;
&#60;/tr&#62;
&#60;tr&#62;
 &#60;td&#62;storeEval&#60;/td&#62;
 &#60;td&#62;javascript{&#38;quot;&#38;quot;+((new Date()).getMonth()+1)+&#38;quot;/&#38;quot;+(new Date()).getDate()+&#38;quot;/&#38;quot;+(new Date()).getFullYear()}&#60;/td&#62;
 &#60;td&#62;currentdate&#60;/td&#62;
&#60;/tr&#62;
&#60;tr&#62;
 &#60;td&#62;assertValue&#60;/td&#62;
 &#60;td&#62;classCIpRanges[0].readableIpAddressRange&#60;/td&#62;
 &#60;td&#62;${currentdate}&#60;/td&#62;
&#60;/tr&#62;

]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.liuhongwei.cn/category/agile/dmap/">Agile</a>自动测试的重要利器，<a href="http://seleniumhq.org/">Selenium</a>测试，功能强劲，适合对web程序进行自动测试。测试脚本，一次编写，反复自动测试，在开发过程中，起到了将功能锁定的作用。</p>
<p>今天有同事问，Selenium测试脚本，是否可以获取当前日期？查了一下发现可以。而且可以把当前日期以各种形式保存在脚本中，供此后输入、比较等操作。这一切源于，<a href="http://seleniumhq.org/docs/04_selenese_commands.html#javascript-and-selenese-parameters">Selenium测试脚本可以执行JavaScript片段</a>，这样，JavaScript具有的各种功能，都可以提供给Selenium测试了。</p>
<p>下面这个脚本，可以获取当前日期，可以把日期存储在currentdate变量中，可以用该变量比较界面上的值，还可以把变量的值输入到浏览器的输入框。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>type<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>classCIpRanges[0].readableIpAddressRange<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javascript{<span style="color: #ddbb00;">&amp;quot;&amp;quot;</span>+((new Date()).getMonth()+1)+<span style="color: #ddbb00;">&amp;quot;</span>/<span style="color: #ddbb00;">&amp;quot;</span>+(new Date()).getDate()+<span style="color: #ddbb00;">&amp;quot;</span>/<span style="color: #ddbb00;">&amp;quot;</span>+(new Date()).getFullYear()}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>storeEval<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javascript{<span style="color: #ddbb00;">&amp;quot;&amp;quot;</span>+((new Date()).getMonth()+1)+<span style="color: #ddbb00;">&amp;quot;</span>/<span style="color: #ddbb00;">&amp;quot;</span>+(new Date()).getDate()+<span style="color: #ddbb00;">&amp;quot;</span>/<span style="color: #ddbb00;">&amp;quot;</span>+(new Date()).getFullYear()}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>currentdate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>assertValue<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>classCIpRanges[0].readableIpAddressRange<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${currentdate}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/agile/selenium-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
