﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-qileilove-随笔分类-selenium and watir webdrivers 自动化测试学习</title><link>http://www.blogjava.net/qileilove/category/51346.html</link><description>不想做屌丝的码农，不是好项目经理！屌丝生涯从此开始！</description><language>zh-cn</language><lastBuildDate>Tue, 23 Dec 2014 01:27:25 GMT</lastBuildDate><pubDate>Tue, 23 Dec 2014 01:27:25 GMT</pubDate><ttl>60</ttl><item><title>Selenium中常用的xpath</title><link>http://www.blogjava.net/qileilove/archive/2014/12/23/421653.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 22 Dec 2014 16:00:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/12/23/421653.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/421653.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/12/23/421653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/421653.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/421653.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　selenium大部分的方法参数都是<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>.lang.String locator,假如我们想传入xptah表达式,可以在表达式的开头加上"xpath=",也可以不加.如下面的两个效果是一样的.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　selenium.getAttribute("//tr/input/@type") &nbsp;=== selenium.getAttribute("xpath=//tr/input/@type")</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　selenium中有一个比较特别而非常有用的方法</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　java.lang.Number getXpathCount(java.lang.String xpath)</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　通过此方法我们可以得到所有匹配xpath的数量,调用此方法,传入的表达式就不能以"xpath="</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　开头.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　另外需要知道的是:当xpath表达式匹配到的内容有多个时,seleium默认的是取第一个,假如,我们想</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　自己指定第几个,可以用"xpath=(xpath表达式)[n]"来获取,例如:</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　selenium.getText("//table[@id='order']//td[@contains(text(),'删除')]");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在id为order的table下匹配第一个包含删除的td.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　selenium.getText("xpath=(//table[@id='order']//td[@contains(text(),'删除')])[2]");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　匹配第二个包含删除的td.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在调试xpath的时候,我们可以下个firefox的xpath插件,这样可以在页面上通过右键开启xpath插件.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　然后随时可以检验xpath所能匹配的内容,非常方便.假如通过插件<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>的xpath表达式可以匹配</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　到预期的内容,但是放到selenium中跑却拿不到,那么最有可能出现的问题是:在你调用seleium方法</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　时,传入的xpath表达式可能多加了或者是少加了"xpath=".</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　以下为几个常用的xpath:</strong></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1.selenium.getAttribute("//tr/input/@type")</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2.selenium.isElementPresent("//span[@id='submit' and @class='size:12']");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3.selenium.isElementPresent("//tr[contains(@sytle,'display:none')]");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　4.selenium.isElementPresent("//*[contains(name(),'a')]"); //这个等价于 //a</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5.selenium.isElementPresent("//tr[contains(text(),'金钱')]");</div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/421653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-12-23 00:00 <a href="http://www.blogjava.net/qileilove/archive/2014/12/23/421653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Windows环境搭建Web自动化测试框架Watir</title><link>http://www.blogjava.net/qileilove/archive/2014/12/03/420986.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 03 Dec 2014 05:47:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/12/03/420986.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/420986.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/12/03/420986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/420986.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/420986.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　一、前言</strong></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Web</strong></u></a>自动化<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>一直是一个比较迫切的问题，对于现在web开发的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">敏捷</strong></u></a>开发，却没有相对应的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">敏捷测试</strong></u></a>，故开此主题，一边研究，一边将Web自动化测试应用于<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>中，进而形成能够独立成章的博文，希望能够为国内web自动化测试的发展做一点绵薄的贡献吧，笑~</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　二、Watir搭建流程</strong></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49772" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212510919dDh.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-1 需要安装的工具</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　因为安装<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Ruby</strong></u></a>还需要用到其他的一些开发工具集，所以建议从网站下载，而且使用该安装包的话，它会帮你把环境变量也设置完毕，我使用的版本是：railsinstaller-2.2.4.exe，建议下载最新版本。</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49773" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021251092jjvk.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-2 RailsInstaller工具包安装界面</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　开始安装RailsInstaller工具包，安装到默认位置即可。</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49774" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212510935opw.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-3 安装完毕界面</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　这个对勾建议打上，它会帮你配置git和ssh，安装过程中ruby等一系列环境变量也配置OK了，挺好~</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49775" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021251094h0Y7.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-4 测试Ruby安装情况</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　安装好railsinstaller-2.2.4.exe后，打开cmd命令行，输入命令：ruby &#8211;v，如果，出现图1-4所示ruby的版本情况，则说明ruby已经安装完毕，我们也可以输入命令测试一下gem的版本：gem &#8211;v，如图1-4所示，gem也是安装成功。</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<a href="http://www.51testing.com/batch.download.php?aid=49776" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212513013998.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-5 gem安装情况</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　使用命令：gem list，查看一下，如图1-5，你会发现，railsinstaller安装完毕后，默认是不包含Watir自动化测试工具的，所以我们现在要开始安装watir。</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49777" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021251302BwV9.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-6 gem命令</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　先简单看一眼gem怎么用，如上图1-6所示，</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a href="http://www.51testing.com/batch.download.php?aid=49778" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021251303S7Iv.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-7 安装watir命令</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　使用命令：gem install watir，进行安装watir，如果顺利的话，下面会出现很多的successfully等文字；不过在国内，你一般是看不到successfully等文字的，因为https://rubygems.org/已经被墙了，现在我们要对gem的源进行修改一下，来达到安装watir的目的。</div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<a href="http://www.51testing.com/batch.download.php?aid=49779" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212513041PLe.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　图1-8 RubyGems镜像网址<br /><div style="word-break: break-all; margin: 10px 0px;">首先使用命令：gem sources -l，查看一下gem的当前源，一般都是：https://rubygems.org/</div><div style="word-break: break-all; margin: 10px 0px;">　　然后我们使用命令：gem sources --remove https://rubygems.org/</div><div style="word-break: break-all; margin: 10px 0px;">　　接着输入命令：gem sources -a https://ruby.taobao.org/</div><div style="word-break: break-all; margin: 10px 0px;">　　参考上图。</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49780" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212513057SMg.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-9 查看gem的源</div><div style="word-break: break-all; margin: 10px 0px;">　　现在再看一下gem的源这是是否正确：gem sources -l，如果只有：https://ruby.taobao.org/，一个源，则说明配置正确。然后再使用命令安装Watir：gem install watir，这次应该就能够安装成功了。</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49781" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212520518zes.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-10 commonwatir和watir版本</div><div style="word-break: break-all; margin: 10px 0px;">　　我们可以再次使用命令：gem list，可以看到，list里面有好多与watir相关的内容，这里主要关心两个工具，如上图所示，commonwatir和watir，这里需要给commonwatir和watir降版本到3.0.0，如果不进行降级，会出现NameError错误，命令如下：</div><div style="word-break: break-all; margin: 10px 0px;">　<a href="http://www.51testing.com/batch.download.php?aid=49782" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021252052fdH8.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-11 watir降级到3.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　输入命令：gem uninstall watir -v 5.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　输入命令：gem install watir -v 3.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49783" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021252053Bev7.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-12 commonwatir降级到3.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　输入命令：gem uninstall commonwatir -v 4.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　输入命令：gem install commonwatir -v 3.0.0</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49784" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021252054gEXF.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-13 ruby测试代码</div><div style="word-break: break-all; margin: 10px 0px;">　　require "watir"</div><div style="word-break: break-all; margin: 10px 0px;">　　puts "Open IE..."</div><div style="word-break: break-all; margin: 10px 0px;">　　ie=Watir::IE.new</div><div style="word-break: break-all; margin: 10px 0px;">　　ie.goto(http://www.baidu.com/)</div><div style="word-break: break-all; margin: 10px 0px;">　　puts "IE is opened - enjoy it :)"</div><div style="word-break: break-all; margin: 10px 0px;">　　在文本编辑器中新建一个test.rb文件，输入以上代码，强烈建议手动输入，空格不慎也会导致运行失败。</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49785" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_201412021252055n3Nu.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-14 ruby文件编码</div><div style="word-break: break-all; margin: 10px 0px;">　　编码也要注意，使用UTF-8编码。</div><div style="word-break: break-all; margin: 10px 0px;">　　<a href="http://www.51testing.com/batch.download.php?aid=49786" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/12/14982672_2014120212520568UBL.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　图1-15 测试效果</div><div style="word-break: break-all; margin: 10px 0px;">　　将test.rb保存完毕后，在cmd命令行输入命令：ruby test.rb如果ruby代码没有报错，程序就会自动打开IE浏览器，自动输入http://www.baidu.com/，打开百度页面。至此，《Windows环境搭建Web自动化测试框架Watir（基于Ruby）第1章》编写完毕。</div><div style="word-break: break-all; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">三、本章总结</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　我们通过一系列的配置，将ruby和watir部署到windows平台上，下一步，我们就可以编写各种各样的测试脚本，针对不同的web应用，进行不同的测试。</div></div><img src ="http://www.blogjava.net/qileilove/aggbug/420986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-12-03 13:47 <a href="http://www.blogjava.net/qileilove/archive/2014/12/03/420986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium之利用Excel实现参数化</title><link>http://www.blogjava.net/qileilove/archive/2014/11/26/420620.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 26 Nov 2014 06:21:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/26/420620.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/420620.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/26/420620.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/420620.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/420620.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　说明：我是通过Workbook方式来读取excel文件的,这次以登陆界面为例</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　备注：使用Workbook读取excel文件，前提是excel需要2003版本，其他版本暂时不支持</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　具体步骤：</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　第一步：新建一个excel文件，并且输入数据内容</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　第二步:在eclipse中新建一个<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>&nbsp;class，编写获取excel文件的代码</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　CODE:</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.io.File;</div><div style="word-break: break-all; margin: 10px 0px;">import java.io.IOException;</div><div style="word-break: break-all; margin: 10px 0px;">import java.util.ArrayList;</div><div style="word-break: break-all; margin: 10px 0px;">import java.util.List;</div><div style="word-break: break-all; margin: 10px 0px;">import jxl.Sheet;</div><div style="word-break: break-all; margin: 10px 0px;">import jxl.Workbook;</div><div style="word-break: break-all; margin: 10px 0px;">/*</div><div style="word-break: break-all; margin: 10px 0px;">* 获取Excel文件的内容,使用Workbook方式来读取excel</div><div style="word-break: break-all; margin: 10px 0px;">*/</div><div style="word-break: break-all; margin: 10px 0px;">public class ExcelWorkBook {</div><div style="word-break: break-all; margin: 10px 0px;">//利用list集合来存放数据，其类型为String</div><div style="word-break: break-all; margin: 10px 0px;">private List&lt;string&gt; list=new ArrayList&lt;/string&gt;&lt;string&gt;();</div><div style="word-break: break-all; margin: 10px 0px;">//通过Workbook方式来读取excel</div><div style="word-break: break-all; margin: 10px 0px;">Workbook book;</div><div style="word-break: break-all; margin: 10px 0px;">String username;</div><div style="word-break: break-all; margin: 10px 0px;">/*</div><div style="word-break: break-all; margin: 10px 0px;">* 获取excel文件第一列的值，这里取得值为username</div><div style="word-break: break-all; margin: 10px 0px;">*/</div><div style="word-break: break-all; margin: 10px 0px;">public List&lt;/string&gt;&lt;string&gt; readUsername(String sourceString) throws IOException,Exception{</div><div style="word-break: break-all; margin: 10px 0px;">List&lt;/string&gt;&lt;string&gt; userList = new ArrayList&lt;/string&gt;&lt;string&gt;();</div><div style="word-break: break-all; margin: 10px 0px;">try {</div><div style="word-break: break-all; margin: 10px 0px;">Workbook book =Workbook.getWorkbook(new File(sourceFile));</div><div style="word-break: break-all; margin: 10px 0px;">Sheet sheet=book.getSheet(0);</div><div style="word-break: break-all; margin: 10px 0px;">//获取文件的行数</div><div style="word-break: break-all; margin: 10px 0px;">int rows=sheet.getRows();</div><div style="word-break: break-all; margin: 10px 0px;">//获取文件的列数</div><div style="word-break: break-all; margin: 10px 0px;">int cols=sheet.getColumns();</div><div style="word-break: break-all; margin: 10px 0px;">//获取第一行的数据，一般第一行为属性值，所以这里可以忽略</div><div style="word-break: break-all; margin: 10px 0px;">String col1=sheet.getCell(0,0).getContents().trim();</div><div style="word-break: break-all; margin: 10px 0px;">String col2=sheet.getCell(1,0).getContents().trim();</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println(col1+","+col2);</div><div style="word-break: break-all; margin: 10px 0px;">//把第一列的值放在userlist中</div><div style="word-break: break-all; margin: 10px 0px;">for(int z=1;z&lt;rows ;z++){</div><div style="word-break: break-all; margin: 10px 0px;">String username=sheet.getCell(0,z).getContents();</div><div style="word-break: break-all; margin: 10px 0px;">userList.add(username);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">} catch (Exception e) {</div><div style="word-break: break-all; margin: 10px 0px;">e.printStackTrace();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">//把获取的值放回出去，方便调用</div><div style="word-break: break-all; margin: 10px 0px;">return userList;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">/*</div><div style="word-break: break-all; margin: 10px 0px;">* 获取excel文件第二列的值，这里取得值为password</div><div style="word-break: break-all; margin: 10px 0px;">*/</div><div style="word-break: break-all; margin: 10px 0px;">public List&lt;String&gt; readPassword(String sourceString) throws IOException,Exception{</div><div style="word-break: break-all; margin: 10px 0px;">List&lt;string&gt; passList = new ArrayList&lt;/string&gt;&lt;string&gt;();</div><div style="word-break: break-all; margin: 10px 0px;">try {</div><div style="word-break: break-all; margin: 10px 0px;">Workbook book =Workbook.getWorkbook(new File(sourceFile));</div><div style="word-break: break-all; margin: 10px 0px;">Sheet sheet=book.getSheet(0);</div><div style="word-break: break-all; margin: 10px 0px;">int rows=sheet.getRows();</div><div style="word-break: break-all; margin: 10px 0px;">for(int z=1;z&lt;rows ;z++){</div><div style="word-break: break-all; margin: 10px 0px;">String password=sheet.getCell(1,z).getContents();</div><div style="word-break: break-all; margin: 10px 0px;">passList.add(password);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">} catch (Exception e) {</div><div style="word-break: break-all; margin: 10px 0px;">e.printStackTrace();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">return passList;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">public List&lt;String&gt; getList(){</div><div style="word-break: break-all; margin: 10px 0px;">return list;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　第三步：新建一个TestNg Class，把excel数据填写到测试界面，具体代码如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　CODE:</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import java.io.File;</div><div style="word-break: break-all; margin: 10px 0px;">import java.util.List;</div><div style="word-break: break-all; margin: 10px 0px;">import java.util.concurrent.TimeUnit;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.By;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebElement;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.firefox.FirefoxDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.firefox.FirefoxProfile;</div><div style="word-break: break-all; margin: 10px 0px;">import org.testng.annotations.BeforeClass;</div><div style="word-break: break-all; margin: 10px 0px;">import org.testng.annotations.Test;</div><div style="word-break: break-all; margin: 10px 0px;">import File.ExcelWorkBook;</div><div style="word-break: break-all; margin: 10px 0px;">public class LoginCenter {</div><div style="word-break: break-all; margin: 10px 0px;">private WebDriver driver;</div><div style="word-break: break-all; margin: 10px 0px;">private String url;</div><div style="word-break: break-all; margin: 10px 0px;">String sourceFile="你文件的路径和文件名称";</div><div style="word-break: break-all; margin: 10px 0px;">@BeforeClass</div><div style="word-break: break-all; margin: 10px 0px;">public void testBefore(){</div><div style="word-break: break-all; margin: 10px 0px;">//设置firefox浏览器</div><div style="word-break: break-all; margin: 10px 0px;">FirefoxProfile file=new FirefoxProfile(new File("C:\\Users\\qinfei\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\t5ourl6s.selenium"));</div><div style="word-break: break-all; margin: 10px 0px;">driver=new FirefoxDriver(file);</div><div style="word-break: break-all; margin: 10px 0px;">url="你的测试地址";</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">@Test</div><div style="word-break: break-all; margin: 10px 0px;">public void login() throws Exception{</div><div style="word-break: break-all; margin: 10px 0px;">//初始化ExcelWorkBook Class</div><div style="word-break: break-all; margin: 10px 0px;">ExcelWorkBook excelbook=new ExcelWorkBook();</div><div style="word-break: break-all; margin: 10px 0px;">//进入到你的测试界面</div><div style="word-break: break-all; margin: 10px 0px;">driver.get(url);</div><div style="word-break: break-all; margin: 10px 0px;">driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);</div><div style="word-break: break-all; margin: 10px 0px;">try{</div><div style="word-break: break-all; margin: 10px 0px;">//把取出的username放在userlist集合里面</div><div style="word-break: break-all; margin: 10px 0px;">List&lt;string&gt; userList=excelbook.readUsername(sourceFile);</div><div style="word-break: break-all; margin: 10px 0px;">//把取出的password放在passlist集合里面</div><div style="word-break: break-all; margin: 10px 0px;">List&lt;/string&gt;&lt;string&gt; passList=excelbook.readPassword(sourceFile);</div><div style="word-break: break-all; margin: 10px 0px;">//把取出来的值，输入到界面的输入框中</div><div style="word-break: break-all; margin: 10px 0px;">int usersize=userList.size();</div><div style="word-break: break-all; margin: 10px 0px;">for(int i=0;i&lt;usersize ;i++){</div><div style="word-break: break-all; margin: 10px 0px;">//通过css定位到username输入框</div><div style="word-break: break-all; margin: 10px 0px;">WebElement username=driver.findElement(By.cssSelector("input[name=\"j_username\"]"));</div><div style="word-break: break-all; margin: 10px 0px;">//通过css定位到password输入框</div><div style="word-break: break-all; margin: 10px 0px;">WebElement password=driver.findElement(By.cssSelector("input[name=\"j_password\"]"));</div><div style="word-break: break-all; margin: 10px 0px;">//通过xpath定位登录按钮</div><div style="word-break: break-all; margin: 10px 0px;">WebElement submit=driver.findElement(By.xpath("//button//span[contains(text(),'登录')]"));</div><div style="word-break: break-all; margin: 10px 0px;">//清除username输入框的内容</div><div style="word-break: break-all; margin: 10px 0px;">username.clear();</div><div style="word-break: break-all; margin: 10px 0px;">//把list中数据一个一个的取出来</div><div style="word-break: break-all; margin: 10px 0px;">String name=userList.get(i);</div><div style="word-break: break-all; margin: 10px 0px;">//然后填写到username输入框</div><div style="word-break: break-all; margin: 10px 0px;">username.sendKeys(name);</div><div style="word-break: break-all; margin: 10px 0px;">for(int j=0;j&lt;passList.size();j++){</div><div style="word-break: break-all; margin: 10px 0px;">password.clear();</div><div style="word-break: break-all; margin: 10px 0px;">String pass=passList.get(j);</div><div style="word-break: break-all; margin: 10px 0px;">password.sendKeys(pass);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">//点击登录按钮</div><div style="word-break: break-all; margin: 10px 0px;">submit.click();</div><div style="word-break: break-all; margin: 10px 0px;">driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);</div><div style="word-break: break-all; margin: 10px 0px;">//通过xpath定位登出按钮</div><div style="word-break: break-all; margin: 10px 0px;">WebElement logoutButton=driver.findElement(By.xpath("//button//span[contains(text(),'登出')]"));</div><div style="word-break: break-all; margin: 10px 0px;">logoutButton.click();</div><div style="word-break: break-all; margin: 10px 0px;">driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}catch(Exception e){</div><div style="word-break: break-all; margin: 10px 0px;">e.printStackTrace();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/420620.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-26 14:21 <a href="http://www.blogjava.net/qileilove/archive/2014/11/26/420620.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用Selenium自动化WEB测试</title><link>http://www.blogjava.net/qileilove/archive/2014/11/21/420400.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 21 Nov 2014 02:52:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/21/420400.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/420400.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/21/420400.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/420400.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/420400.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 简介　　Selenium&nbsp;是一个健壮的工具集合，跨很多平台支持针对基于&nbsp;web&nbsp;的应用程序的测试自动化的敏捷开发。它是一个开源的、轻量级的自动化工具，很容易集成到各种项目中，支持多种编程语言，比如 .NET、Perl、Python、Ruby&nbsp;和 Java? 编程语言。　　利用 Selenium 测试 Ajax 应用程序　　Asynchronous JavaS...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/archive/2014/11/21/420400.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/420400.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-21 10:52 <a href="http://www.blogjava.net/qileilove/archive/2014/11/21/420400.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RFS+AutoItLibrary测试Web对话框</title><link>http://www.blogjava.net/qileilove/archive/2014/11/11/419905.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 11 Nov 2014 02:10:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/11/419905.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419905.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/11/419905.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419905.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419905.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　Selenium2library在我们实际测试<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>页面的时候基本上已经够用了，不过还是会有部分情况下会脱离Selenium2library的控制，无法进行操作。比如说下载文件的时候，要选择保存文件在什么地方，比如说上传文件的时候，要选择上传哪个文件，这些在Selenium2library下都没有很好的处理办法。但是结合上AutoItLibrary，就可以很好的来进行处理了。结合AutoItLibrary的内容分2篇，本篇介绍AutoItLibrary安装使用和对话框处理，下篇介绍上传下载。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　下载解压缩后直接用ride打开里面的tests看代码或者运行案例即可。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">1、AutoItLibrary安装</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　简单说下安装，把下面2个下载了，先安装pywin32，然后再安装AutoItLibrary，解压缩进入相应目录执行<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">python</strong></u></a>&nbsp;setup.py install</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　pywin32-217.win32-py2.7.exe（我之前下载的217，最新的好像是218，版本较多，请注意py版本）</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　AutoItLibrary-1.1.tar.gz（必须先安装上面的pywin32，并且Python的安装目录不能有空格，如果有空格会导致注册autoit的dll时出错。版本一直是1.1）</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　64位的机器：除了安装上面2个之外，还不得不再安装一个AutoItV3。一般情况下装完这个就能用了。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">2、AutoItLibrary对象识别</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　当成功安装AutoItLibrary之后，在你的硬盘某个盘根目录会多一个Robotframework的目录，具体哪个盘取决于你的User目录在哪个盘，例如我的是在D盘，因此多出来的这个目录就在如下路径：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　D:\RobotFramework\Extensions\AutoItLibrary</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　这里是一些辅助工具，比如AutoItX.chm是帮助文档，AutoItLibrary.html是<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>库的关键字文档说明，Au3Info.exe是最重要的识别对象的工具了。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在Finder Tool的位置有个十字星，可以用鼠标拖动他到你需要识别的对象上，就像下图这样：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=49271" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115341Z0ZF.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　AutoItLibrary的对象操作大体上有几大主要部分，Window操作、Control操作、Mouse操作、Process操作、Run操作、Reg操作还有一些其他的操作。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　其中前三个操作我比较常用，Window和Control应该比较好理解吧，你看到的窗口就是Window，窗口上的按钮、文本框等就是Control。所以在通常要去操作Control时，一般需要先激活窗口，再操作控件。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　AutoItLibrary的鼠标操作要用到真实坐标，这和Selenium2Library里的坐标略有差异，下篇会有例子。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　回到上图，可以看到最重要识别出来的属性，分两块，在左侧上半部分，Basic Window Info和Basic Control Info。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　经过我多次的使用，Window方面识别用Title比较多，Control主要用controlID，controlID就是在Basic Control Info里的Class+Instance，比如说图中这个对象，他的controlID就是Edit1，关键字里的strControl就是controlID（chm里都是写的controlID）。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　AutoItLibrary的关键字我就不一一介绍了，大家可以看Chm帮助或者html的关键字文档，不过chm是原生AutoIt的文档，对于理解关键字的作用比较有帮助。关键字文档只是列出来所有的关键字和参数，基本很少有说明。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">3、web对话框</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　a、你肯定见过这种对话框，前一个是只有确定的，还有确定取消2个按钮的。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=49272" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115342Xi56.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　b、你应该也见过这种对话框</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=49273" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115343eql4.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　c、还有那种在网页上弹出的要输入用户密码的登录框，我这里没有找到例子，也木有截图。（找到截图，见最底下）</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　以上这些都可以用AutoItLibrary来处理。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　对于a来说，Selenium2Library中的confirm action就可以处理了。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　对于b、c来说，都要用AutoItLibrary处理更好一些，因为那些文本框的输入已经脱离了Selenium2Library的控制了。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　先来看a这种对话框在Selenium2Library的处理，脚本如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=49274" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115344ra6d.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　其中最主要用到的就是confirm action，顺便普及下相关的关键字</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　Choose Cancel On Next Confirmation</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　Choose Ok On Next Confirmation</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　这2个关键字其实特别针对的是a里第二个那种，从字面意思可以理解，选择OK或者Cancel在下一次Confirmation，请注意是下一次Confirmation，也就是你必须还要使用Confirmation才行，而不是用了这个就等于选择OK或者Cancel了，具体可看脚本里的使用。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　再看看AutoItLibrary里的处理，脚本如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49275" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115345U0vm.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　我做了个关闭对话框的关键字，方便重复调用。这个关键字实现的功能我基本上参考了confirmation，除了点击按钮，还会把提示信息返回，不过我没做choose cancel的部分。具体关键字的脚本如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49276" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115346Eaeh.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　我的demo页面上面表格里有3个按钮，付款、确认、输入。付款和确认就是a那种类型的，输入是b那种类型的。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　我的脚本只做了a类型的处理，其他类型的请大家当作练习做吧。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　如果其他类型的不会做，可以参考下一篇的内容吧。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　找到c类型的截图了，IE里弹出这种窗口的时候，也可以用AutoItLibrary处理，有类似情况的可以自己练习下。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49277" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/11/14982672_201411101115347lD5A.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div></a></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419905.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-11 10:10 <a href="http://www.blogjava.net/qileilove/archive/2014/11/11/419905.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Firefox获取隐藏表单元素的parent节点的Bug</title><link>http://www.blogjava.net/qileilove/archive/2014/11/10/419849.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 10 Nov 2014 02:11:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/10/419849.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419849.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/10/419849.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419849.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419849.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">getXY : function(element){</div><div style="word-break: break-all; margin: 10px 0px;">var y = element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">var x = element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">while(element = element.offsetParent){</div><div style="word-break: break-all; margin: 10px 0px;">y += element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">x += element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">return (new Array(x,y));</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　貌似是这个问题,递归代码在火狐下好像有问题,要打桩测一下(不打桩了,有log输出就容易了)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">getXY : function(element){</div><div style="word-break: break-all; margin: 10px 0px;">var y = element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">var x = element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">var i=0;</div><div style="word-break: break-all; margin: 10px 0px;">while(element = element.offsetParent){</div><div style="word-break: break-all; margin: 10px 0px;">y += element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">x += element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">i++;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">//firefox debug</div><div style="word-break: break-all; margin: 10px 0px;">console.log(i);</div><div style="word-break: break-all; margin: 10px 0px;">console.log(y);</div><div style="word-break: break-all; margin: 10px 0px;">console.log(x);</div><div style="word-break: break-all; margin: 10px 0px;">return (new Array(x,y));</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在ie9下为4 120 100,正常</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　火狐为0 0 0,看来只要换个递归的写法就行了,</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　但是这个问题的原因要查清楚,项目里有这种风格写法的人,可能对于火狐的解析器来说</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　while(element = element.offsetParent)估计一开始就等于false啊..具体<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>下</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　具体文章javascript的互等性,要补一下了.</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　火狐下element.offsetParent一开始就等于null</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　还是要去打桩,bug无法确定了,有可能是递归写法问题,又可能是前面传的element对象不对</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　还是不用打桩,调试时的一个报错,说明火狐解析器对判断条件里的element = element.offsetParent的理解是正确的.</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　前面的传参不对,or火狐对offsetParent的属性理解不对(如果加悬浮布局,那么火狐下是直接父节点直接对应body的,然后当然是null,记得是),没有使用危险的css属性,应该不会有问题的啊,</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">getXY : function(element){</div><div style="word-break: break-all; margin: 10px 0px;">var y = element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">var x = element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">var i=0;</div><div style="word-break: break-all; margin: 10px 0px;">if(!element.offsetParent)</div><div style="word-break: break-all; margin: 10px 0px;">console.log("null");</div><div style="word-break: break-all; margin: 10px 0px;">console.log(element.id);</div><div style="word-break: break-all; margin: 10px 0px;">while(element = element.offsetParent){</div><div style="word-break: break-all; margin: 10px 0px;">y += element.offsetTop;</div><div style="word-break: break-all; margin: 10px 0px;">x += element.offsetLeft;</div><div style="word-break: break-all; margin: 10px 0px;">i++;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">//firefox debug</div><div style="word-break: break-all; margin: 10px 0px;">console.log(i);</div><div style="word-break: break-all; margin: 10px 0px;">console.log(y);</div><div style="word-break: break-all; margin: 10px 0px;">console.log(x);</div><div style="word-break: break-all; margin: 10px 0px;">return (new Array(x,y));</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　传参正确,获得的id和在ie下一样,不过应该没有并没有该id对应的对象在页面中存在,不过ie能理解,这个火狐也是认得,但是貌似这个parent对象火狐处理得和ie不同(直接为空,ie正常)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　差点以为有又有什么我不知道的写法,xx_xx什么的可以直接一起获取,当然不可能啊,草,怪怪的语言,随时提心吊胆的</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　是 获取一个隐藏的input对象的父节点问题,导致常用的递归获取元素绝对坐标方法的递归失败.在firefox下,隐藏表单字段估计直接对应body节点 (猜的),那么就是为空(或者直接就是对象属性封装的问题,反正是bug),估计就是这个问题了,稍微修改后BUG被clear(在getXY里用固有结 构,把对象指向日期框后解决)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　offsetParent这个属性是个level0的属性,实现各异</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　而jq中的&gt;可以跳来跳去,会不会也有这个bug呢?还是jq处理了这个BUG,等有时间再去测试吧</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　接下来就是一些css问题,和修复原控件的select的fous问题,还是尽量不要用input这玩意在ie6下并不好,xinput控件调用又太麻烦了</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　基于先前研究,进销存模块使用的透明图片加div颜色属性实现的皮肤效果,可以进行日期控件在保证其他位置引用兼容性的前提下,进行和进销存模块独有的表单皮肤系统整合</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在前辈的指导下修改了getYear(),getFullYear(),火狐是不支持 getYear()的,一开始我还以为那个控件一直是从Const里获得年月日的,其实是外部调用时传个date()对象?有时又在控件里建date()对象,当初可能是想做什么吧,中途可能放弃了,那Const里那个年月日是干嘛的,要好好看看去</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　发现火狐失去焦点事件的bug,可能比较难改,简单说就是点击旁边后,选择框不会关..选择时候的鼠标状态问题,火狐好像不会变选择手势呢</div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419849.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-10 10:11 <a href="http://www.blogjava.net/qileilove/archive/2014/11/10/419849.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>自动化还是不自动化，就是这个问题</title><link>http://www.blogjava.net/qileilove/archive/2014/11/07/419640.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 07 Nov 2014 02:22:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/07/419640.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419640.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/07/419640.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419640.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419640.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　你为什么要写<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>？为什么该选择用人工测试而不是自动化？什么时候该做这样的选择呢？事实上，几乎所有的测试工程师早晚都要面对的问题就是是否选择自动化以及自动化测试的程度。如果你只打算执行一次测试，根本没有必要自动化。可是，如果你打算测试两次呢？这也不意味着你应该使用自动化。有些软件在发布之前或者在维护阶段，可能需要执行上百次，上千次，甚至百万次的测试。有些因素有助于在具体环境下 &nbsp;准确地评估自动化的益处。如下是其中几个需要考量的因素：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">投入</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　确定创建自动化测试的投资回报率（ROI--Return On Investment）的第一步是确定要花费的投入和成本。 有些种类的产品或功能的自动化很简单，而其他的自动化却不可避免得很麻烦。例如，应用程序编程接口（API--Application Programming Interface）测试，以及别的通过编程对象的方式 展现给用户的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">功能测试</strong></u></a>，对其自动化往往都能够直截了当。而在另一方面，用户界面（UI--User Interface）的自动化测试常会遇到问题而需要花费更多的精力。----注---需要考量自动化的实施成本，难度太大的自动化不值得采用。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　测试的生命期</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　一个自动化测试在变得无用之前将会运行多少次？对测试的长期价值的评估是决定是否对某个特定的场景或者<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试用例</strong></u></a>实现自动化的考量的一部分。要考虑被测试的产品本身的使用寿命和产品开发周期长度。对于短期内就要发布而且将来不打算更新的产品，和对于两年后要发布将来也会有多次更新发布的产品，自动化的选择必须是不一样的。----注---短期内即可结束且后期不再多次迭代的软件项目，自动化可不必采用。软件周期较长，会经历多次迭代过程，自动化对于后期的回归测试会很有帮助。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　价值</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　要考虑自动化测试在其生命周期内的价值。有些测试人员说测试用例的价值是找到缺陷，但是很多自动化测试所找到的缺陷是在测试第一次运行时或者在写自动化测试时发现的。当缺陷被修复以后，这些测试成为了回归测试&#8212;&#8212;确认最近的改动不会导致以前能够正常运行的功能停止<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>。很多自动化测试技术通过改变测试用的数据，或者改变每次测试运行路径的方法，从而在测试的生命期中继续找到缺陷。对一个生命周期很长的产品来说，不断增长的回归测试套件有很大的优势：随着底层软件功能越来越复杂，存在大量的能确认以前工作的功能能够继续工作的测试是极为有用的 &nbsp;。----注---对于后期需要多次迭代，或者项目完成后需要长期维护并进行版本更新的项目，自动化的实施有很大价值，便于后期的回归验证。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">切入点</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　我目睹的许多成功的测试自动化项目都是测试团队从最开始的时候就参与了。代码写到尾声或者完成之后才开始想到加入自动化测试的项目通常都是失败的。----注---测试团队什么时候能参与项目的自动化测试过程中、项目时间安排是否允许加入自动化实施过程、测试人员的工作负载是否允许、人力资源的投入多少等都可能影响测试人员的自动化实施工作及效果。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　准确性</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　好的自动化测试在每次运行后会报告准确结果。企业管理层对自动化测试最大的抱怨之一是自动化测试中误报的数量。误报是指测试报告中的测试失败是由测试本身的某些问题造成的，与产品无关。项目的有些领域（例如经常变化的用户界面组件）难以用自动化测试分析，且较容易产生误报。 ----注---测试团队的自动化实施是否确定能达到预期的要求和效果、是否存在较大的技术难点和障碍等问题应该在确定是否实施自动化时加以考虑，否则有可能达不到预期的自动化测试效果，反而浪费了人力和时间。</div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-07 10:22 <a href="http://www.blogjava.net/qileilove/archive/2014/11/07/419640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium并行启动多个浏览器</title><link>http://www.blogjava.net/qileilove/archive/2014/11/06/419567.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Nov 2014 02:03:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/06/419567.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419567.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/06/419567.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419567.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419567.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">快速上手</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　如果你对&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>已经非常熟悉，你仅仅需要一个快速上手来使程序运行起来。本章节的内容能满足不同的技术层次，但是如果你仅仅需要一个可以快速上手的指引，那么就显得有点多。如果是这样，你可以参考 Selenium Wiki 的相关<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">文章</strong></u></a>。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　什么是 Selenium-Grid ?</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 允许你在多台机器的多个浏览器上并行的进行测试，也就是说，你可以同时运行多个测试。本质上来说就是，Selenium-Grid 支持分布式的测试执行。它可以让你的测试在一个分布式的执行环境中运行。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">何时需要使用</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　通常，以下两种情况你都会需要使用 Selenium-Grid。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在多个浏览器中运行测试，在多个版本的浏览器中进行测试，或在不同<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">操作系统</strong></u></a>的浏览器中进行测试。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　减少测试运行时间。</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 通过使用多台机器并行地运行测试来加速测试的执行过程。例如,如果你有一个包含100个<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试用例</strong></u></a>的测试套件,你使用 Selenium-Grid 支持4台不同的机器（虚拟机或实体机均可）来运行那些测试，同仅使用一台机器相比，你的测试所需要的运行时间大致为其 1/4。对于大型的测试套件和那些会进行大量数据校验的需要长时间运行的测试套件来说，这将节约很多时间。有些测试套件可能要运行好几小时。另一个需要缩短套件运行时间的原因是开发者检入（check-in）AUT 代码后，需要缩短测试的运行周期。越来越多的团队使用<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">敏捷</strong></u></a>开发，相比整夜整夜的等待测试通过，他们希望尽快地看到测试反馈。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 也可以用于支持多执行环境的测试运行，典型的，同时在多个不同的浏览器中运行。例如，Grid 的虚拟机可以安装测试必须的各种浏览器。于是，机器 1 上有 ie8，机器 2 上有 ie9，机器 3 上有最新版的 chrome，而机器 4 上有最新版的 firefox。当测试套件运行时，Selenium-Grid 可以使测试在指定的浏览器中运行，并且接收每个浏览器的运行结果。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　另外，我们可以拥有一个装有多个类型和版本都一样的浏览器 Grid。例如，一个 Grid 拥有 4 台机器，每台机器可以运行 3 个 firefox 12 实例，形成一个 firefox 的服务农场。当测试套件运行时，每个传递给 Selenium-Grid 的测试都被指派给下一个可用的 firefox 实例。通过这种方式，我们可以使得同时有 12 个测试在并行的运行以完成测试，显著地缩短了测试完成需要的时间。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 非常灵活。以上两个例子可以联合起来使用，这样可以就可以使得不同类型和版本的浏览器有多个可运行实例。使用这样的配置，既并行地执行测试，同时又可以测试多个浏览器类型和版本。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><strong style="word-break: break-all; line-height: normal !important;">　　Selenium-Grid 2.0</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 2.0 是在编写本文时(5/26/2012)已发布的最新版本。它同版本 1 有很多不同之处。在 2.0 中，Selenium-Grid 和 Selenium-RC 服务端进行了合并。现在，你仅需要下载一个 jar 包就可以获得它们。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">Selenium-Grid 1.0</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　版本 1 是 Selenium-Grid 的第一个发布版本。如果你是一个 Selenium-Grid 新手，你应该选择版本 2 。新版本已经在原有基础上进行了更新，页增加了一些新特性，并且支持 Selenium-WebDriver。一些老的系统可能仍然在使用版本 1.关于 Selenium-Grid 版本 1 的信息可以参考 Selenium-Grid website</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Selenium-Grid 的 Hub 和 Nodes 是如何<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>的？</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Grid 由一个中心和一到多个节点组成。两者都是通过 selenium-server.jar 启动。在接下来的章节中，我们列出了一些例子。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　中心接收要执行的测试信息，包括在哪些平台和浏览器执行等。它知道每个注册了的节点的配置。根据测试信息，它会选择符合需求的节点进行测试。一旦选定了一个节点，测试脚本就会初始化 Selenium 命令，并且由重心发送给选定的要运行测试的节点。这个节点会启动浏览器，然后在浏览器中执行这个 AUT 的 Selenium 命令。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　我们提供了一些图标来演示其原理。第二张图标是用以说明 Selenium-Grid 1 的，版本 2 也适用并且对于我们的描述是一个很好的说明。唯一的区别在于相关术语。使用&#8220;Selenium-Grid 节点&#8221;替换&#8220;Selenium Remote Control&#8221;即符合我们对 Selenium-Grid 2 的描述。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">下载</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　下载过程很简单。从 SeleniumHq 站点的下载页面下载 Selenium-Server jar 包。你需要的链接在&#8220;Selenium-Server (以前是 Selenium-RC)&#8221;章节中。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　将它存放到任意文件夹中。你需要确保机器上正确的安装了&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>。如果 java 没有正常运行，检查你系统的 path 变量是否包含了 java.exe 的路径。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">启动 Selenium-Grid</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　由于节点对中心有依赖，所以你通常需要先启动一个中心。这也不是必须的，因为节点可以识别其中心是否已经启动，反之亦然。作为教程，我们建议你先启动中心，否则会显示一些错误信息，你应该不会想在第一次使用 Selenium-Grid 的时候就看到它们。<br /><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><strong style="word-break: break-all; line-height: normal !important;">启动中心</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　通过在命令行执行以下命令，可以启动一个使用默认设置的中心。所有平台可用，包括 Windows Linux, 或 MacOs 。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role hub</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　我们将在接下来的章节中解释各个参数。注意，你可能需要修改上述命令中 jar 包的版本号，这取决于你使用的 selenium-server 的版本。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">启动节点</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　通过在命令行执行以下命令，可以你懂一个使用默认设置的节点。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role node &nbsp;-hub http://localhost:4444/grid/register</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　该操作假设中心是使用默认设置启动的。中心用于监听请求使用的默认端口号为 4444，这就是为什么端口 4444 被用于中心 url 中。同时&#8220;localhost&#8221;假定你的节点和中心运行在同一台机器上。对于新手来说，这是最简单的方式。如果要在两台不同的机器上运行中心和节点，只需要将&#8220;localhost&#8221;替换成中心所在机器的 hostname 即可。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　警告： 确保运行中心和节点的机器均已关闭防火墙，否则你将看到一个连接错误。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　配置 Selenium-Grid</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　默认配置</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　JSON 配置文件</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　通过命令行选项配置</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">中心配置</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　通过指定 -role hub 即以默认设置启动中心：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role hub</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">你将看到以下日志输出：</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Jul 19, 2012 10:46:21 AM org.openqa.grid.selenium.GridLauncher main</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　INFO: Launching a selenium grid server</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　2012-07-19 10:46:25.082:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　2012-07-19 10:46:25.151:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　2012-07-19 10:46:25.185:INFO:osjs.AbstractConnector:Started SocketConnector@0.0.0.0:4444</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">指定端口</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　中心默认使用的端口是 4444 。这是一个 TCP/IP 端口，被用于监听客户端，即自动化测试脚本到 Selenium-Grid 中心的连接。如果你电脑上的另一个应用已经占用这个接口，或者你已经启动了一个 Selenium-Server，你将看到以下输出：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　10:56:35.490 WARN - Failed to start: SocketListener0@0.0.0.0:4444</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　如果看到这个信息，你可以关掉在使用端口 4444 的进程，或者告诉 Selenium-Grid 使用一个别的端口来启动中心。-port 选项用于修改中心的端口：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role hub -port 4441</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　即使已经有一个中心运行在这台机器上，只要它们不使用同一个端口，就能正常工作。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　你可能想知道哪个进程使用了 4444 端口，这样你就可以让中心使用这个默认端口。使用以下命令可以查看你机器上所有运行程序使用的端口：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　netstat -a</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Unix/Linux, MacOs 和 Windows 均支持此命令，只是在 Windows 中 -a 参数为必须的。基本上，你需要显示进程 id 和端口。在 Unix 中，你可以通过管道 &#8220;grep&#8221; 输出那些你关心的端口相关的条目。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　节点配置</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　时间参数</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　获取命令行帮助</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Selenium-Server 提供了一个可选项列表，每个选项都有一个简短的描述。目前（2012夏），命令行帮助还有一些奇怪，但是如果你知道如何去找、如何解读信息会对你很有帮助。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Selenium-Server 提供了两种不同的功能，Selenium-RC server 和 Selenium-Grid。它们是两个不同的团队编写的，所以每个功能的命令行帮助被放置在不同的地方。因此，对于新手来说，在初次使用任意一个功能时，帮助都不是那么显而易见。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　如果你仅传递一个 -h 选项，你将看到 Selenium-RC Server 的可选项而不是 Selenium-Grid 的。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -h</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　上述代码将显示 Selenium-RC server 选项。如果你想看到 Selenium-Grid 的命令行帮助，你需要先使用 -hub 或 -node 选项告诉 Selenium-Server 你想看的是关于 Selenium-Grid 的，然后再追加 -h 选项。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role node -h</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　对于这个问题，你还可以给 -role node 传递一个垃圾参数：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　java -jar selenium-server-standalone-2.21.0.jar -role node xx</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　你将先看到 &#8220;INFO...&#8221; 和一个 &#8220;ERROR&#8221;，在其后你将看到 Selenium-Grid 的命令行选项。我们没有列出这个命令的所有输出，因为它实在太长了，这个输出的最初几行看起来如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">Jul 19, 2012 10:10:39 AM org.openqa.grid.selenium.GridLauncher main</div><div style="word-break: break-all; margin: 10px 0px;">INFO: Launching a selenium grid node</div><div style="word-break: break-all; margin: 10px 0px;">org.openqa.grid.common.exception.GridConfigurationException: You need to specify a hub to register to using -hubHost X -hubPort 5555. The specified config was -hubHost null -hubPort 4444</div><div style="word-break: break-all; margin: 10px 0px;">at org.openqa.grid.common.RegistrationRequest.validate(RegistrationRequest.java:610)</div><div style="word-break: break-all; margin: 10px 0px;">at org.openqa.grid.internal.utils.SelfRegisteringRemote.startRemoteServer(SelfRegisteringRemote.java:88)</div><div style="word-break: break-all; margin: 10px 0px;">at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:72)</div><div style="word-break: break-all; margin: 10px 0px;">Error building the config :You need to specify a hub to register to using -hubHost X -hubPort 5555. The specified config was -hubHost null -hubPort 4444</div><div style="word-break: break-all; margin: 10px 0px;">Usage :</div><div style="word-break: break-all; margin: 10px 0px;">-hubConfig:</div><div style="word-break: break-all; margin: 10px 0px;">(hub) a JSON file following grid2 format.</div><div style="word-break: break-all; margin: 10px 0px;">-nodeTimeout:</div><div style="word-break: break-all; margin: 10px 0px;">(node) &lt;XXXX&gt; &nbsp;the timeout in seconds before the hub</div><div style="word-break: break-all; margin: 10px 0px;">automatically ends a test that hasn't had aby activity than XX</div><div style="word-break: break-all; margin: 10px 0px;">sec.The browser will be released for another test to use.This</div><div style="word-break: break-all; margin: 10px 0px;">typically takes care of the client crashes.</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　<strong style="word-break: break-all; line-height: normal !important;">常见错误</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Unable to acess the jarfile</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Unable to access jarfile selenium-server-standalone-2.21.0.jar</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　无论是启动中心还是节点都有可能产生这个错误。这意味着 java 无法找到 selenium-server jar 包。你需要从 selenium-server-XXXX.jar 文件存放在目录运行命令或者指定 jar 包的完整路径。</div></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419567.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-06 10:03 <a href="http://www.blogjava.net/qileilove/archive/2014/11/06/419567.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium IDE的第一个测试用例</title><link>http://www.blogjava.net/qileilove/archive/2014/11/06/419563.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 06 Nov 2014 01:56:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/11/06/419563.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419563.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/11/06/419563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419563.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419563.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">一周时间过去了，断断续续学习<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">selenium</strong></u></a>也有几个小时了；今天细想一下<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">学习</strong></u></a>效率不高的原因在哪，总结出以下几点：</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　1、求&#8220;进&#8221;心切&#8212;&#8212;总想一步到位，搭建好环境，开始动手写用例。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　2、学习深度不够&#8212;&#8212;同样想着快速浏览一遍某大神、高手的日志，教程什么的很立即动手复制，其实很多基础环境不一样，无法全部照搬。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　3、学习时间太少&#8212;&#8212;这个是最为关键的点，统计一下，一周下来，花在学习Selenium上的时间不过3-5小时，而且时间分布在12点到2点之间，效率也最低下。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　两天前弄出来的SELENIUM IDE for firefox已经可以进行录制回放功能，做一些最为简单的单线流程录制。但一直无法将用例转换的JAVA代码编译通过，报错也无法定位与解决，被阻塞了两天时间 。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　Java for selenium 做WEB测试应具有的知识体系，大致如下（自己感受）：</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　1、JAVA基础，与<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">JUnit</strong></u></a>(不了解)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　2、selenium的JAVA API及selenium基本知识（摸不着北）</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　3、<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>基础与WEB前端技术</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　通过分析上述的几点要求后，发现自己在基础上还是非常薄弱，不能一味的追求快；而是需要一边夯实基础、一边开阔视野、一边提升；推动整体向前进步。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;head profile="http://selenium-ide.openqa.org/profiles/test-case"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;link rel="selenium.base" href="http://www.baidu.com/" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;title&gt;hyddd&lt;/title&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/head&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;body&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;table cellpadding="1" cellspacing="1" border="1"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;thead&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;tr&gt;&lt;td rowspan="1" colspan="3"&gt;hyddd&lt;/td&gt;&lt;/tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/thead&gt;&lt;tbody&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;open&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;/&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;click&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;id=kw1&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;type&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;id=kw1&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;hyddd&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;click&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;id=su1&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;td&gt;&lt;/td&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/tr&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/tbody&gt;&lt;/table&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/body&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/html&gt;</div></td></tr></tbody></table></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><div><div id="SL_button" class="ImTranslatorLogo"></div><div id="SL_shadow_translation_result2"></div><div id="SL_shadow_translator"><div id="SL_planshet"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result"></div><div id="SL_bbl_donate" title="Make a small contribution"></div><div id="SL_Balloon_options"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-11-06 09:56 <a href="http://www.blogjava.net/qileilove/archive/2014/11/06/419563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium grid 使用方法</title><link>http://www.blogjava.net/qileilove/archive/2014/10/30/419224.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 30 Oct 2014 03:13:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/10/30/419224.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419224.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/10/30/419224.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419224.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419224.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">代码和selenium driver相同 只是 启动环境方式不同。至少启动一个hub 一个 node 。如需要多个，可以使用端口进行区分。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;"><a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>&nbsp;-jar selenium-server-standalone-x.xx.x.jar -role node -port 5555</div><div style="word-break: break-all; margin: 10px 0px;">java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5556</div><div style="word-break: break-all; margin: 10px 0px;">java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5557</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　代码如下</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);</div><div style="word-break: break-all; margin: 10px 0px;">//test01： 只匹配<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Windows</strong></u></a>下的ie来执行此用例，版本不限；多个版本匹配成功时优先级暂未知</div><div style="word-break: break-all; margin: 10px 0px;">DesiredCapabilities aDesiredcap = DesiredCapabilities();</div><div style="word-break: break-all; margin: 10px 0px;">aDesiredcap.setBrowserName("internet explorer")</div><div style="word-break: break-all; margin: 10px 0px;">aDesiredcap.setVersion("")</div><div style="word-break: break-all; margin: 10px 0px;">aDesiredcap.setPlatform(Platform.WINDOWS)</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);</div><div style="word-break: break-all; margin: 10px 0px;">wd.doSomething()</div><div style="word-break: break-all; margin: 10px 0px;">//test02： 只匹配linix下的firefox的版本为22的浏览器执行用例；</div><div style="word-break: break-all; margin: 10px 0px;">DesiredCapabilities aDesiredcap = DesiredCapabilities("firefox", "22", Platform.LINUX);</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);</div><div style="word-break: break-all; margin: 10px 0px;">wd.doSomething()</div><div style="word-break: break-all; margin: 10px 0px;">//test03： 只匹配MAC下的safari浏览器执行，版本不限</div><div style="word-break: break-all; margin: 10px 0px;">DesiredCapabilities aDesiredcap = DesiredCapabilities.safari();</div><div style="word-break: break-all; margin: 10px 0px;">aDesiredcap.setPlatform(Platform.MAC)</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);</div><div style="word-break: break-all; margin: 10px 0px;">wd.doSomething()</div><div style="word-break: break-all; margin: 10px 0px;">//test04： 只匹配chrome浏览器，任意平台，任意版本</div><div style="word-break: break-all; margin: 10px 0px;">DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();</div><div style="word-break: break-all; margin: 10px 0px;">aDesiredcap.setPlatform(Platform.ANY)</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);</div><div style="word-break: break-all; margin: 10px 0px;">wd.doSomething()</div></td></tr></tbody></table></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419224.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-10-30 11:13 <a href="http://www.blogjava.net/qileilove/archive/2014/10/30/419224.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QTP里的DOM应用</title><link>http://www.blogjava.net/qileilove/archive/2014/10/30/419223.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 30 Oct 2014 03:09:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/10/30/419223.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419223.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/10/30/419223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419223.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419223.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">DOM全称&#8221;Document Object Model&#8221;，字面上叫做&#8221;文档对象模型&#8221;，它是一款主要用于Web Html中的一种独立语言。Html Dom主要通过定义一套标准的对象通道接口，使得我们能够轻松访问并控制Html对象元素，它是一种用于Html和Xml文档的编程接口。DOM的表现方 法是一种树状结构。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　有些时候<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">QTP</strong></u></a>只对标准控件支持比较好，而对特殊的控件无法识别。DOM是一种罪底层的对象操作模型，使用它来控制对象不但速度快，而且可以访问很多QTP无法访问的东西。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">1. 修改控件自身接口</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　QTP本身无法修改控件自身接口属性，但通过DOM我们可以访问并修改自身接口属性</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">2. DOM对象下CurrentStyle对象应用</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　CurrentStyle是一个可以与Html对象元素style sheets进行交互的接口，它可以获取对象元素的字体名，字体大小，颜色，是否可见等，在验证点时有重要作用。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">3. 性能提升</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　DOM执行速度会比QTP对象库的执行速度快好几倍，这是因为DOM是底层对象接口，而QTP首先要把对象封装，然后在脚本运行时调用对象库的对象，最后与页面上的对象进行比对，如果匹配才可控制<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>对象。而DOM是直接找对象进行控制。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">下面的例子是IE对象模型里的DOM应用</strong></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　1. 启动IE的三种常见方法</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　在QTP中启动IE:</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　SystemUtil.Run &#8220;iexplore.exe&#8221;</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　2. 使用WSH启动IE：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Set oShell = CreateObject(&#8220;wscript.shell&#8221;)</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　3. 使用IE COM对象：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Set oIE = CreateObject("InternetExplorer.Application")</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　oIE.Visible = True</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　oIE.Navigate http://www.baidu.com</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　使用第三种方法还可以获得当前窗口的句柄，并通过QTP来定位浏览器：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　ieHwnd = oIE.HWND</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Browser(&#8220;hwnd:=&#8221; &amp; ieHwnd).Close</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　接下来的这个例子就是使用到DOM去操作页面元素了</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　Set oIE = CreateObject("InternetExplorer.Application")</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　oIE.Visible = True</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　oIE.Navigate "http://www.baidu.com"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　'While oIE.Busy</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　'Wend</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　oIE.Document.f.wd.value = "sunyu"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　我把While oIE.Busy:Wend这两句话注释掉了，运行结果如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48997" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059121jKoX.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　程序运行出错了，主要是因为我们没有等待页面加载完，就进行了下一步的填值操作，QTP会找不到这个对象。如果你点击Retry再次运行，那么这次会通过，因为页面已经加载完毕了。所以我们在操作Web对象时，要特别注意需要等待页面加载完毕。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　注：以上这个错误我们会经常遇到，有时候你只需要关掉QTP再重新打开后就不会再遇到这个错误了。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　遍历所有IE对象：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Function EnumIE()</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set EnumIE = CreateObject("Scripting.Dictionary")</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set winShell = CreateObject("<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Shell</strong></u></a>.Application")</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set allWins = winShell.Windows</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　For each win in allWins</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　If instr(1,win.FullName,"iexplore.exe",vbTextCompare) Then</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　EnumIE.Add win.hwnd,win</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　End If</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Next</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　End Function</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　我打开一共两个IE窗口，但是第一个IE窗口里有四个子窗口，如下图：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=48998" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059122SBFy.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　然后调用上面的代码：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set allIE = EnumIE()</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　For each oIE in allIE.Items</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oIE.quit</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Next<br /><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">结果QTP报错了</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=48999" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059123EQyG.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　这是因为在同一个窗口下的四个子窗口使用的是同一个句柄，所以无法加入到Dictionary对象里去。只要对代码稍加修改就可以了：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Function EnumIE()</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set EnumIE = CreateObject("Scripting.Dictionary")</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set winShell = CreateObject("Shell.Application")</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set allWins = winShell.Windows</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　For each win in allWins</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　If instr(1,win.FullName,"iexplore.exe",vbTextCompare) Then</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　If Not EnumIE.Exists(win.hwnd) Then</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　EnumIE.Add win.hwnd,win</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　End If</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　End If</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Next</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　End Function</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　调用的时候，我采用了递归调用，只要有子窗口没有关完，就会继续关。这里用do while的话会多执行一次EnumIE这个函数，大家可以考虑换一种循环方式，我就不多说了。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set allIE = EnumIE()</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Do while allIE.Count&gt;0</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　For each oIE in allIE.Items</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oIE.quit</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Next</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set allIE = EnumIE()</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Loop</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　当然了QTP有自己的方法会很快关闭所有的IE窗口：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　SystemUtil.CloseProcessByName(&#8220;iexplore.exe&#8221;)</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　下面介绍下利用DOM操作测试对象的几种常用方法，还是用百度主页做例子，首先将百度主页加进对象库。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　IE8里会自带F12开发工具，可以方便你看你需要的DOM属性</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=49000" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/10/14982672_2014102410591244iCR.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set oDOM = Browser("百度一下，你就知道").Page("百度一下，你就知道").Object</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　需要注意的是，此处的Object属性目前只支持IE，而对其他的浏览器目前还没有加入支持。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　1. 通过getElementById方法获取定位对象，对其进行操作：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oDOM.getElementById("kw").value = "态度决定测试"</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oDOM.getElementById("su").click</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　2. 通过getElementsByName方法获取定位对象，对其进行操作：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　方法一：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set oEdits = oDOM.getElementsByName("wd")</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　For each oEdit in oEdits</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oEdit.value = "态度决定测试"</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Next</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oDOM.getElementById("su").click</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　方法二：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set oEdits = oDOM.getElementsByName("wd")</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oEdits(0).value = "态度决定测试"</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oDOM.getElementById("su").click</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　通过方法名里Element后面的复数形式也大概可以知道这个方法返回的是一个集合，所以需要遍历集合里的对象获取这个对象。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　3. 通过getElementsByTagName方法获取定位对象，对其进行操作：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Set oEdits = oDOM.getElementsByTagName("INPUT")</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　For each oEdit in oEdits</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　If oEdit.type = "text" Then</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oEdit.value = "态度决定测试"</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　End If</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　Next</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　oDOM.getElementById("su").click</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　用这个方法遍历之后通常要加判断，因为一个页面里可能有很多INPUT标签。<br /><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">4. 利用FORM来获取对象元素，对其进行操作：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　oDOM.f.wd.value = "态度决定测试"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　oDOM.f.su.click</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　5. 访问页面里的Script脚本变量</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　通过DOM可以直接访问到页面中的JS或者VBS中的变量，还是以百度为例，我们用F12进行探测，可以看到k这个变量： k = d.f.wd</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49001" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059125bqq6.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　oDOM.parentWindow.k.value = "态度决定测试"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　oDOM.getElementById("su").click</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　从代码里可以看出，我们只需要通过parentWindow去访问web页面中的变量即可。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　下面我们来说说利用DOM完成QTP无法完成的任务：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　还是百度，假设我们需要验证一些属性，此时我们可以使用CurrentStyle来验证。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set oDOM = Browser("百度一下，你就知道").Page("百度一下，你就知道").Object</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set p = oDOM.f.CurrentStyle</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　msgbox p.color</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　我们可以验证表单的颜色。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　利用DOM还可以提升我们的脚本性能，举个例子，自己构建一个含有100个文本框的HTML页面，每个文本框的name属性都是由text_开头，之后由1到100递增。首先将Page对象加到对象库里去。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49002" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059126nt9V.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　效果图如下：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49003" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059127XzMn.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　接下来我们就可以引入保留对象Services的Transaction属性来验证性能是否有提高。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　QTP描述性编程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Services.StartTransaction "test"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　For i =1 to 100</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Browser("Browser").Page("Page").webEdit("name:=text_"+cstr(i)).Set "hello world"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Next</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Services.EndTransaction "test"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　运行后结果大概用了11.5秒时间填写完一百个webEdit对象。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49004" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059128vA3L.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　DOM操作脚本：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Set oDOM= Browser("Browser").Page("Page").Object</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Services.StartTransaction "test"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　For i =1 to 100</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　oDOM.getElementsByName("text_"+cstr(i))(0).value = "hello world"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Next</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　Services.EndTransaction "test"</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　结果只用了1.8秒时间，效率惊人。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=49005" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410241059129Gr93.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">　　如果文本框更多的话，那么DOM操作对象的优势将进一步显现出来。这对性能的提升会有巨大的帮助。</div></div></div></div></div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-10-30 11:09 <a href="http://www.blogjava.net/qileilove/archive/2014/10/30/419223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium RC 环境搭建（eclipse）</title><link>http://www.blogjava.net/qileilove/archive/2014/10/30/419221.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 30 Oct 2014 03:05:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/10/30/419221.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/419221.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/10/30/419221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/419221.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/419221.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　关于<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;RC的原理，还是Selenium私房菜系列6比较详细。 虽然我只看懂了组成。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　按照上面的步骤，搭建后的工程：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48935" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410211405321TyiZ.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　一个简单的Case，不完整，纯粹为了<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>环境是否搭成功。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">package com.dhy.selenium.test;</div><div style="word-break: break-all; margin: 10px 0px;">import&nbsp;<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>.net.URL;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.By;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebElement;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.firefox.FirefoxDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.remote.RemoteWebDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.remote.DesiredCapabilities;</div><div style="word-break: break-all; margin: 10px 0px;">public class Case1 {</div><div style="word-break: break-all; margin: 10px 0px;">public static void main(String[] args) throws Exception{</div><div style="word-break: break-all; margin: 10px 0px;">// &nbsp; &nbsp; &nbsp; &nbsp;WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),</div><div style="word-break: break-all; margin: 10px 0px;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DesiredCapabilities.firefox());</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver driver = new FirefoxDriver();</div><div style="word-break: break-all; margin: 10px 0px;">driver.get("http://2j.isurveylink.com/s/183/?test_mode=1");</div><div style="word-break: break-all; margin: 10px 0px;">WebElement element = driver.findElement(By.id("start_btn"));</div><div style="word-break: break-all; margin: 10px 0px;">element.click();</div><div style="word-break: break-all; margin: 10px 0px;">try {</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(3000);</div><div style="word-break: break-all; margin: 10px 0px;">} catch (InterruptedException e) {</div><div style="word-break: break-all; margin: 10px 0px;">// TODO Auto-generated catch block</div><div style="word-break: break-all; margin: 10px 0px;">e.printStackTrace();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("Page title is : " + driver.getTitle());</div><div style="word-break: break-all; margin: 10px 0px;">driver.quit();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　这里的语法啊、类啊什么的，需要慢慢研究。</div> <div><div id="SL_button" class="ImTranslatorLogo" style="display: none; background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><div id="SL_shadow_translation_result2" style="display: none;"></div><div id="SL_shadow_translator" style="display: none;"><div id="SL_planshet" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png) #f4f5f5;"><div id="SL_TB"><div id="bubblelogo" class="ImTranslatorLogo" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/imtranslator-s.png);"></div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td class="SL_td" align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td class="SL_td" align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td class="SL_td" width="13%" align="center">&nbsp;</td><td class="SL_td" width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_copy" title="Select text" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_bbl_font_patch" onclick="alert('Not available for dictionary');"></div><div id="SL_bbl_font" title="Font size" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png);"></div></td><td class="SL_td" width="8%" align="center"><div id="SL_TH" title="Translation history" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png);"></div></td><td class="SL_td" width="5%"></td><td class="SL_td" width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png);"></div></td></tr></tbody></table></div></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png);"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" class="SL_options" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" class="SL_options" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" class="SL_options" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" class="SL_options" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png);">Text-to-speech function is limited to 100 characters</div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/419221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-10-30 11:05 <a href="http://www.blogjava.net/qileilove/archive/2014/10/30/419221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual Studio之UI界面测试</title><link>http://www.blogjava.net/qileilove/archive/2014/10/14/418692.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 14 Oct 2014 01:21:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/10/14/418692.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418692.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/10/14/418692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418692.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418692.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">UI界面测试其实就是录制操作路径(Mapping)，然后按照路径还原操作顺序的一个过程。这个方法对于Winform和Webform都同样适用。下面以winform为例，来介绍如何进行录制。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　1.新建一个Coded UI&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Test</strong></u></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48765" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133431my6I.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;" alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　2.然后选择录制。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48766" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133432lhpZ.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;" alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　3.屏幕右下方会出现UIMap.</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48767" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_20141013113343367f3.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;" alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　4.打开一个Winform，使用&#8220;查看UI控件属性&#8221;这个功能可以查看所选控件的属性。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48768" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133434TFMy.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;" alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　5.点击红色的开始录制，然后对被测的Winform程序进行一些操作。操作后暂停录制，然后可以查看所录制的操作过程和操作数据。如下图所示：</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=48769" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133435RcuV.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;" alt="" /><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">6.点击产生代码，系统会自动产生如下所示的操作代码。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=48770" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133436VbMh.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　7.重新打开被测的Winform程序，然后在Test List Editor里面选择刚生成的CodedUITestMethod1方法，执行它。则被测Winform程序会自动执行刚才所录制的所有操作。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px;"><a href="http://www.51testing.com/batch.download.php?aid=48771" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/10/14982672_201410131133437gRpy.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-size: 11.8181819915771px; text-align: left;">　　至此，一个简单的Winform单元测试就完成了。对于Webform的录制过程和Winform一样，需要注意的是在录制之前一定要先把测试的网站打开，不能只打开IE。</div></a></div><img src ="http://www.blogjava.net/qileilove/aggbug/418692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-10-14 09:21 <a href="http://www.blogjava.net/qileilove/archive/2014/10/14/418692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python Selenium的js扩展实现</title><link>http://www.blogjava.net/qileilove/archive/2014/09/30/418413.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 30 Sep 2014 02:03:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/30/418413.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418413.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/30/418413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418413.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418413.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　python写的数据采集，对一般有规律的页面用 urllib2 + BeautifulSoup + 正则就可以搞定。 但是有些页面的内容是通过js生成，或者通过js跳转的，甚至js中还加入几道混淆机制；对这种涉及页面脚本解析的内容，前面的方式便很无力。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　这时我们需要能解析、运行js的引擎&#8212;&#8212;浏览器，而python selenium能提供程序与浏览器的交互接口，再加上phantomjs这个可以后台运行的浏览器，即使用 selenium + phantomjs 便可以解决以上的问题。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　selenium可以操作页面的元素，并且提供执行js脚本的接口。但其调用js脚本后并不能直接返回执行的结果，这样再采集内容的过程中就会受到一些限制。 比如我们想使用页面中的函数进行数据转换，或者获取iframe里的内容，这些js产生数据要传回比较麻烦。</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;">　　所以我便写一个简化js数据回传的扩展 exescript.py</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 11.8181819915771px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">#!/usr/bin/env python</div><div style="word-break: break-all; margin: 10px 0px;"># -*- coding:utf-8 -*-</div><div style="word-break: break-all; margin: 10px 0px;">#</div><div style="word-break: break-all; margin: 10px 0px;"># created by heqingpan</div><div style="word-break: break-all; margin: 10px 0px;">_init_js="""</div><div style="word-break: break-all; margin: 10px 0px;">(function (){</div><div style="word-break: break-all; margin: 10px 0px;">if (window.__e)</div><div style="word-break: break-all; margin: 10px 0px;">{ return;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">var e=document.createElement('div');</div><div style="word-break: break-all; margin: 10px 0px;">e.setAttribute("id","__s_msg");</div><div style="word-break: break-all; margin: 10px 0px;">e.style.display="none";</div><div style="word-break: break-all; margin: 10px 0px;">document.body.appendChild(e);</div><div style="word-break: break-all; margin: 10px 0px;">window.__e=e;</div><div style="word-break: break-all; margin: 10px 0px;">})();</div><div style="word-break: break-all; margin: 10px 0px;">window.__s_set_msg=function(a){</div><div style="word-break: break-all; margin: 10px 0px;">window.__e.setAttribute("msg",a.toString()||"");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">"""</div><div style="word-break: break-all; margin: 10px 0px;">_loadJsFmt="""</div><div style="word-break: break-all; margin: 10px 0px;">var script = document.createElement('script');</div><div style="word-break: break-all; margin: 10px 0px;">script.src = "{0}";</div><div style="word-break: break-all; margin: 10px 0px;">document.body.appendChild(script);</div><div style="word-break: break-all; margin: 10px 0px;">"""</div><div style="word-break: break-all; margin: 10px 0px;">_jquery_cdn="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"</div><div style="word-break: break-all; margin: 10px 0px;">_warpjsfmt="__s_set_msg({0})"</div><div style="word-break: break-all; margin: 10px 0px;">class ExeJs(object):</div><div style="word-break: break-all; margin: 10px 0px;">def __init__(self,driver,trytimes=10):</div><div style="word-break: break-all; margin: 10px 0px;">from time import sleep</div><div style="word-break: break-all; margin: 10px 0px;">self.driver=driver</div><div style="word-break: break-all; margin: 10px 0px;">driver.execute_script(_init_js)</div><div style="word-break: break-all; margin: 10px 0px;">while trytimes &gt;0:</div><div style="word-break: break-all; margin: 10px 0px;">try:</div><div style="word-break: break-all; margin: 10px 0px;">self.msgNode=driver.find_element_by_id('__s_msg')</div><div style="word-break: break-all; margin: 10px 0px;">break</div><div style="word-break: break-all; margin: 10px 0px;">except Exception:</div><div style="word-break: break-all; margin: 10px 0px;">sleep(1)</div><div style="word-break: break-all; margin: 10px 0px;">trytimes -= 1</div><div style="word-break: break-all; margin: 10px 0px;">if self.msgNode is None:</div><div style="word-break: break-all; margin: 10px 0px;">raise Exception()</div><div style="word-break: break-all; margin: 10px 0px;">def exeWrap(self,jsstr):</div><div style="word-break: break-all; margin: 10px 0px;">""" jsstr 执行后有返回值，返回值通过self.getMsg()获取 """</div><div style="word-break: break-all; margin: 10px 0px;">self.driver.execute_script(_warpjsfmt.format(jsstr))</div><div style="word-break: break-all; margin: 10px 0px;">def loadJs(self,path):</div><div style="word-break: break-all; margin: 10px 0px;">self.execute(_loadJsFmt.format(path))</div><div style="word-break: break-all; margin: 10px 0px;">def loadJquery(self,path=_jquery_cdn):</div><div style="word-break: break-all; margin: 10px 0px;">self.loadJs(path)</div><div style="word-break: break-all; margin: 10px 0px;">def execute(self,jsstr):</div><div style="word-break: break-all; margin: 10px 0px;">self.driver.execute_script(jsstr)</div><div style="word-break: break-all; margin: 10px 0px;">def getMsg(self):</div><div style="word-break: break-all; margin: 10px 0px;">return self.msgNode.get_attribute('msg')</div></td></tr></tbody></table><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;">打开ipython上一个例子，获取博客园首页文章title列表</div><div style="word-break: break-all; line-height: 21.6000022888184px; margin: 10px 0px; font-size: 11.8181819915771px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612.727233886719px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">from selenium import webdriver</div><div style="word-break: break-all; margin: 10px 0px;">import exescript</div><div style="word-break: break-all; margin: 10px 0px;">d=webdriver.PhantomJS("phantomjs")</div><div style="word-break: break-all; margin: 10px 0px;">d.get("http://www.cnblogs.com/")</div><div style="word-break: break-all; margin: 10px 0px;">exejs=exescript.ExeJs(d)</div><div style="word-break: break-all; margin: 10px 0px;">exejs.exeWrap('$(".post_item").length')</div><div style="word-break: break-all; margin: 10px 0px;">print exejs.getMsg()</div><div style="word-break: break-all; margin: 10px 0px;">#out:</div><div style="word-break: break-all; margin: 10px 0px;">"""</div><div style="word-break: break-all; margin: 10px 0px;">20</div><div style="word-break: break-all; margin: 10px 0px;">"""</div><div style="word-break: break-all; margin: 10px 0px;">jsstr="""(function(){</div><div style="word-break: break-all; margin: 10px 0px;">var r=[];</div><div style="word-break: break-all; margin: 10px 0px;">$(".post_item").each(function(){</div><div style="word-break: break-all; margin: 10px 0px;">var $this=$(this);</div><div style="word-break: break-all; margin: 10px 0px;">var $h3=$this.find("h3");</div><div style="word-break: break-all; margin: 10px 0px;">r.push($h3.text());</div><div style="word-break: break-all; margin: 10px 0px;">});</div><div style="word-break: break-all; margin: 10px 0px;">return r.join(',');})()"""</div><div style="word-break: break-all; margin: 10px 0px;">exejs.exeWrap(jsstr)</div><div style="word-break: break-all; margin: 10px 0px;">l=exejs.getMsg()</div><div style="word-break: break-all; margin: 10px 0px;">for title in l.split(','):</div><div style="word-break: break-all; margin: 10px 0px;">print title</div><div style="word-break: break-all; margin: 10px 0px;">#out:</div><div style="word-break: break-all; margin: 10px 0px;">"""</div><div style="word-break: break-all; margin: 10px 0px;">mac TeamTalk开发点点滴滴之一&#8212;&#8212;DDLogic框架分解上</div><div style="word-break: break-all; margin: 10px 0px;">The directfb backend was supported together with linux-fb backend in GTK+2.10</div><div style="word-break: break-all; margin: 10px 0px;">Science上发表的超赞聚类算法</div><div style="word-break: break-all; margin: 10px 0px;">功能齐全、效率一流的免费开源数据库导入导出工具（c#开发，支持SQL server、SQLite、ACCESS三种数据 &nbsp;库），每月借此处理数据5G以上</div><div style="word-break: break-all; margin: 10px 0px;">企业级应用框架(三)三层架构之数据访问层的改进以及测试DOM的发布</div><div style="word-break: break-all; margin: 10px 0px;">Unity3D 第一季 00 深入理解U3D开发平台</div><div style="word-break: break-all; margin: 10px 0px;">Welcome to Swift (苹果官方Swift文档初译与注解二十一)---140~147页(第三章--集合类型)</div><div style="word-break: break-all; margin: 10px 0px;">appium简明教程（11）&#8212;&#8212;使用resource id定位</div><div style="word-break: break-all; margin: 10px 0px;">SQL语句汇总(终篇）&#8212;&#8212; 表联接与联接查询</div><div style="word-break: break-all; margin: 10px 0px;">fopen警告处理方式</div><div style="word-break: break-all; margin: 10px 0px;">AndroidWear开发之HelloWorld篇</div><div style="word-break: break-all; margin: 10px 0px;">AMD and CMD are dead之KMD.js版本0.0.2发布</div><div style="word-break: break-all; margin: 10px 0px;">SQL语句汇总(三）&#8212;&#8212;聚合函数、分组、子查询及组合查询</div><div style="word-break: break-all; margin: 10px 0px;">DevExpress GridControl功能总结</div><div style="word-break: break-all; margin: 10px 0px;">ASP.NET之Jquery入门级别</div><div style="word-break: break-all; margin: 10px 0px;">2014年前端面试经历</div><div style="word-break: break-all; margin: 10px 0px;">grunt源码解析：整体运行机制&amp;grunt-cli源码解析</div><div style="word-break: break-all; margin: 10px 0px;">跟用户沟通，问题尽量分析清楚，以及解决问题</div><div style="word-break: break-all; margin: 10px 0px;">ASP.NET之Ajax系列（一）</div><div style="word-break: break-all; margin: 10px 0px;">算法复杂度分析</div><div style="word-break: break-all; margin: 10px 0px;">"""</div></td></tr></tbody></table></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/418413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-30 10:03 <a href="http://www.blogjava.net/qileilove/archive/2014/09/30/418413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SELENIUM教程之REPORTNG结合</title><link>http://www.blogjava.net/qileilove/archive/2014/09/24/418224.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 24 Sep 2014 05:11:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/24/418224.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418224.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/24/418224.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418224.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418224.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;在上一次的selenium教程中我们介绍了如何使用maven自动配置selenium环境以及如何使用Maven来配置TestNG，那么这次的课程主要讲一下ReportNG的配置，在讲之前这块之前先讲讲为什么要讲reportNG，大家在使用TestNG时一定会发现其本身的报告生成不但简陋而且相当的不美观，而ReportNG正是一款为TestNG量身定做的报告生成插件，其报告美观、简约、清...&nbsp;&nbsp;<a href='http://www.blogjava.net/qileilove/archive/2014/09/24/418224.html'>阅读全文</a><img src ="http://www.blogjava.net/qileilove/aggbug/418224.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-24 13:11 <a href="http://www.blogjava.net/qileilove/archive/2014/09/24/418224.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>自动化基础普及之selenium是什么？</title><link>http://www.blogjava.net/qileilove/archive/2014/09/23/418174.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 23 Sep 2014 01:38:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/23/418174.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418174.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/23/418174.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418174.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418174.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;并不像<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">QTP</strong></u></a>那样让人一下子就明白是什么？它是编程人员的最爱，但它却对<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>新手产生了很大的阻碍。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 是啥？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium RC是啥？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Webdriver 又是啥？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　RC 和 Webdriver 是啥关系？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Webdriver 和编程语言啥关系？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 能并行执行脚本嘛？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 能做<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">移动</strong></u></a>端自动化么？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　这里虫师用简单方式，告诉你，他们错综复杂的关系。理顺了它们之间的关系才能真正使用它。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 是什么？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 是<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a><a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;"></strong></u></a><u style="word-break: break-all; line-height: normal !important;"><strong style="word-break: break-all;"><a target="_self" style="word-break: break-all; color: #202859; text-decoration: none;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>工具</strong></u>集，包括IDE、Grid、RC（selenium 1.0）、WebDriver（selenium 2.0）等。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium IDE 是firefox浏览器的一个插件。提供简单的脚本录制、编辑与回放功能。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium Grid 是用来对测试脚步做分布式处理。现在已经集成到selenium&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">server</strong></u></a>&nbsp;中了。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　RC和WebDriver 更多应该把它看成一套规范，在这套规范里定义客户端脚步与浏览器交互的协议。以及元素定位与操作的接口。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　WebDriver是什么？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　对于刚接触selenium自动化测试的同学来说不太容易理解API是什么，它到底和编程语言之是什么关系。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　http://www.w3.org/TR/2013/WD-webdriver-20130117/</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　当初，在刚学selenium （webdriver）的时候花了一个星期来翻译这个文档，后来也没弄明白，它是啥。其实它就是一层基础的协议规范。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　假如说：Webdriver API(接口规范)说，我们要提供一个页面元素id的定位方法。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Ruby</strong></u></a>的webdriver模块是这么实现的：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">require "selenium-webdriver" &nbsp; #导入ruby版的selenium(webdriver)</div><div style="word-break: break-all; margin: 10px 0px;">find_element(:id, "xx") &nbsp; &nbsp;#id定位方法</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　C#的webdriver模块是这么实现的：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">using OpenQA.Selenium;</div><div style="word-break: break-all; margin: 10px 0px;">using OpenQA.Selenium.Firefox; &nbsp;//导入C#版的selenium(webdriver)</div><div style="word-break: break-all; margin: 10px 0px;">FindElement(By.Id("xx")) &nbsp; //id定位方法</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　python的webdriver模块是这么实现的：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">from &nbsp;selenium import webdriver &nbsp; &nbsp;#导入python版的selenium(webdriver)</div><div style="word-break: break-all; margin: 10px 0px;">find_element_by_id("xx") &nbsp; #id定位方法</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Java</strong></u></a>的webdriver模块是这么实现的：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.*;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.firefox.FirefoxDriver;//导入java版的selenium(webdriver)</div><div style="word-break: break-all; margin: 10px 0px;">findElement(By.id("xx")) &nbsp; &nbsp;//id定位方法</div><div style="word-break: break-all; margin: 10px 0px;">Robot Framework + selenium</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　因为Robot Framework 对于底层过于封装，所以，我们看不到语言层面的方法定义。所以，Robot Framework 提供给我们的方法如下：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、导入Robot Framework 版本的selenium（webdriver）</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、使用id方法</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Click element</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Id=xx</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　需要说明的是 webdriver API 只提供了web页面操作的相关规范，比如元素定位方法，浏览器操作，获取web页元素属性等。<br /><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;"><strong style="word-break: break-all; line-height: normal !important;">　Webdriver &nbsp;如何组织和执行用例？</strong></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　对不起，webdriver 不会。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　把写好这些操作页面元素的方法（用例）组织起来执行并输入测试结果，是由编程语言的单元测试框架去完成的。如java 的junit和testng单元测试框架，python 的unittest单元测试框架等。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　Selenium RC 和WebDriver 什么关系？</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　RC和 WebDriver 类似，都可以看做是一套操作web页面的规范。当然，他们的工作原理不一样。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　selenium RC 在浏览器中运行 JavaScript 应用，使用浏览器内置的 JavaScript 翻译器来翻译和执行selenese 命令（selenese 是 selenium 命令集合） 。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　WebDriver 通过原生浏览器支持或者浏览器扩展直接控制浏览器。WebDriver 针对各个浏览器而开发，取代了嵌入到被测 Web 应用中的 JavaScript。与浏览器的紧密集成支持创建更高级的测试，避免了JavaScript 安全模型导致的限制。除了来自浏览器厂商的支持，WebDriver 还利用操作系统级的调用模拟用户输入。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　看样子webdriver 更牛B一些。为了保持向兼容，所以selenium 2.0中，RC 和webdriver 并存，但说起selenium 2.0 一般指的是webdriver 。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　并行与分布式的区别</strong></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　有同学好奇如何并行的执行测试用例，并行要求&#8220;同时&#8221;执行多条用例，这个也是由编程语言的多线程技术实现的。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　你会问Selenium Grid 不是可以实现分布式执行么？ 分布式的概念是写好一条用例可以调用不同的平台执行，如 A电脑上有一个测试用例，可以调用B电脑（linux）的 Firefox浏览器来跑A电脑上的测试用例；也可以调用C电脑（windows）的 Chrome浏览器来跑A电脑上的测试用例。这是分布式的概念。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">Selenium如何能做移动端测试么？</strong></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　这里我们以python 语言为例。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　from selenium import webdriver</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　driver= webdriver.Chrome() &nbsp; #获取浏览器驱动。拿到浏览器驱动driver 才能操作浏览器所打找的页面上的元素。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　我们把驱动展开是这样的</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">from selenium import webdriver</div><div style="word-break: break-all; margin: 10px 0px;">driver = webdriver.Remote(</div><div style="word-break: break-all; margin: 10px 0px;">command_executor='http://127.0.0.1:4444/wd/hub',</div><div style="word-break: break-all; margin: 10px 0px;">desired_capabilities={'platform': 'ANY',</div><div style="word-break: break-all; margin: 10px 0px;">'browserName':chrome,</div><div style="word-break: break-all; margin: 10px 0px;">'version': '',</div><div style="word-break: break-all; margin: 10px 0px;">'javascriptEnabled': True</div><div style="word-break: break-all; margin: 10px 0px;">})</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　驱动里包含了一些参数，代理服务器（URL）平台，浏览器 ,浏览器版本等。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　移动端的自动化测试工具Appium</strong></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　从本质上来讲，appium同样继承了WebDriver &nbsp;API的接口规范。Appium 同样是支持多种编程语言的。这里仍然以python 为例子。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　from appium import webdriver &nbsp;#导入python版的 appium(webdriver)模块</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">#定义驱动的参数</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps = {}</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps['platformName'] = 'Android'</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps['platformVersion'] = '4.2'</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps['deviceName'] = 'Android Emulator'</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps['appPackage'] = 'com.android.calculator2'</div><div style="word-break: break-all; margin: 10px 0px;">desired_caps['appActivity'] = '.Calculator'</div><div style="word-break: break-all; margin: 10px 0px;">driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　这一次因为我们操作的是移动端的安卓。所以我们驱动的参数里就要指定平台是'Android' ,版本是4.2 等信息。拿到驱动后，就可以操作安卓上的APP了。</div></div><img src ="http://www.blogjava.net/qileilove/aggbug/418174.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-23 09:38 <a href="http://www.blogjava.net/qileilove/archive/2014/09/23/418174.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WebDriver + TestNG应用</title><link>http://www.blogjava.net/qileilove/archive/2014/09/19/418089.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Fri, 19 Sep 2014 05:14:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/19/418089.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418089.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/19/418089.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418089.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418089.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;2 最大的更新就是集成了WebDriver。这两者是什么关系呢？如果你搜索WebDriver，第一条结果是Selenium。其实WebDriver和Selenium可以说是在实现UI Automation的竞争对手。Selenium是运行在JavaScript的sandbox里面，所以很容易就支持不同的浏览器；而WebDriver则是直接操作浏览器本身，更接近用户的真实操作，但正因为如此，所以WebDriver在多浏览器/操作系统的支持上就要落后于Selenium。不过从Selenium 2开始，这两个项目合并了，可以继续用原来的Selenium，也可以考虑迁移到WebDriver。我个人认为WebDriver应该是以后的大趋势，还是值得迁移的。至于你信不信，我反正是信了。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　作为一个轻量级的UI Automation框架，需要写一些驱动它的代码，大部分人会选择<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">JUnit</strong></u></a>，因为JUnit是<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">单元测试</strong></u></a>的事实标准；但是我会用<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">TestNG</strong></u></a>。这些UI Automation的东西，它们本身不是单元测试，而且也没有太多单元测试的风格。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　从一段简单的测试开始</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">public class GoogleTest &nbsp;{</div><div style="word-break: break-all; margin: 10px 0px;">@Test</div><div style="word-break: break-all; margin: 10px 0px;">public void search(ITestContext context) {</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver driver = new FirefoxDriver();</div><div style="word-break: break-all; margin: 10px 0px;">driver.get("http://www.google.com");</div><div style="word-break: break-all; margin: 10px 0px;">WebElement element = driver.findElement(By.name("q"));</div><div style="word-break: break-all; margin: 10px 0px;">element.sendKeys("magus");</div><div style="word-break: break-all; margin: 10px 0px;">element.submit();</div><div style="word-break: break-all; margin: 10px 0px;">Assert.assertTrue(driver.getTitle().contains("magus"), "Something wrong with title");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　TestNG应用了Java的Annotations，只需要在测试方法上面打上@Test就可以标示出search是一个测试方法。用TestNG运行测试还需要一个testng.xml的文件，文件名其实可以随便起，没有关系的。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;suite name="Magus demo" verbose="2"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;test name="Search function"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;class name="<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">test</strong></u></a>.GoogleTest"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="search" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/class&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/test&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/suite&gt;</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我想让测试更加灵活，1. 可以配置使用任意支持的浏览器进行测试；2. 配置所有<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Google</strong></u></a>的URL；3. 配置搜索的关键字。修改后的代码：</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">public class GoogleTest &nbsp;{</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver driver;</div><div style="word-break: break-all; margin: 10px 0px;">@Parameters({"browser"})</div><div style="word-break: break-all; margin: 10px 0px;">@BeforeTest</div><div style="word-break: break-all; margin: 10px 0px;">public void setupBrowser(String browser){</div><div style="word-break: break-all; margin: 10px 0px;">if (browser.equals("firefox")){</div><div style="word-break: break-all; margin: 10px 0px;">driver = new FirefoxDriver();</div><div style="word-break: break-all; margin: 10px 0px;">} else {</div><div style="word-break: break-all; margin: 10px 0px;">driver = new ChromeDriver();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">@Parameters({ "url", "keyword" })</div><div style="word-break: break-all; margin: 10px 0px;">@Test</div><div style="word-break: break-all; margin: 10px 0px;">public void search(String url, String keyword, ITestContext context) { &nbsp; &nbsp; &nbsp; &nbsp;driver.get(url);</div><div style="word-break: break-all; margin: 10px 0px;">WebElement element = driver.findElement(By.name("q"));</div><div style="word-break: break-all; margin: 10px 0px;">element.sendKeys(keyword);</div><div style="word-break: break-all; margin: 10px 0px;">element.submit();</div><div style="word-break: break-all; margin: 10px 0px;">Assert.assertTrue(driver.getTitle().contains(keyword), "Something wrong with title"); &nbsp; &nbsp; &nbsp; &nbsp;}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　testng.xml</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;suite name="Magus demo" verbose="2"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;parameter name="browser" value="firefox" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;parameter name="url" value="http://www.google.com" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;parameter name="keyword" value="magus" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;test name="Search function" preserve-order="true"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;class name="test.GoogleTest"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="setupBrowser" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="search" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/class&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/test&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/suite&gt;</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　利用TestNG的@Parameters标签，让测试方法从testng.xml里面读取参数，实现参数化。在testng.xml的配置中，test节点需要增加一个属性的配置： preserve-order=&#8221;true&#8221;。这个preserve-order默认是false，在节点下面的所有方法的执行顺序是无序的。把它设为true以后就能保证在节点下的方法是按照顺序执行的。TestNG的这个功能可以方便我们在testng.xml里面拼装测试。假设我们有很多独立的测试方法，例如</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　navigateCategory</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　addComment</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　addFriend</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　login</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　logout</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　就可以在testng.xml里面拼出不同的测试，例如</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;test name="Add friend" preserve-order="true"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;class name="test.GoogleTest"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="login" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="addFriend" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="logout" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/class&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/test&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;test name="Add comment to category" preserve-order="true"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;class name="test.GoogleTest"&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;methods&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;include name="login" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="navigateCategory" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="addComment" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;include name="logout" /&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/methods&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/class&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/classes&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/test&gt;</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px;">　　TestNG比JUnit更加适合做一些非单元测试的事情，不是说JUnit不好，而是不能把JUnit当成万能的锤子，到处钉钉子。WebDriver的API比Selenium的更加简洁，会是以后的大趋势。</div></div><img src ="http://www.blogjava.net/qileilove/aggbug/418089.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-19 13:14 <a href="http://www.blogjava.net/qileilove/archive/2014/09/19/418089.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium下载百度音乐并验证</title><link>http://www.blogjava.net/qileilove/archive/2014/09/18/418042.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 18 Sep 2014 01:28:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/18/418042.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/418042.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/18/418042.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/418042.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/418042.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">package baidu;</div><div style="word-break: break-all; margin: 10px 0px;">import&nbsp;<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">java</strong></u></a>.io.File;</div><div style="word-break: break-all; margin: 10px 0px;">import java.io.IOException;</div><div style="word-break: break-all; margin: 10px 0px;">import java.util.List;</div><div style="word-break: break-all; margin: 10px 0px;">import org.apache.commons.io.FileUtils;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.By;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.Keys;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.OutputType;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.TakesScreenshot;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebDriver;</div><div style="word-break: break-all; margin: 10px 0px;">//import org.openqa.selenium.WebDriver.Navigation;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.WebElement;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.chrome.ChromeDriver;</div><div style="word-break: break-all; margin: 10px 0px;">import org.openqa.selenium.interactions.Actions;</div><div style="word-break: break-all; margin: 10px 0px;">public class selenium &nbsp;{</div><div style="word-break: break-all; margin: 10px 0px;">public static void snapshot(TakesScreenshot drivername, String filename)</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">// this method will take screen shot ,require two parameters ,one is driver name, another is file name</div><div style="word-break: break-all; margin: 10px 0px;">File scrFile = drivername.getScreenshotAs(OutputType.FILE);</div><div style="word-break: break-all; margin: 10px 0px;">// Now you can do whatever you need to do with it, for example copy somewhere</div><div style="word-break: break-all; margin: 10px 0px;">try {</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("save snapshot path is:E:/"+filename);</div><div style="word-break: break-all; margin: 10px 0px;">FileUtils.copyFile(scrFile, new File("E:\\"+filename));</div><div style="word-break: break-all; margin: 10px 0px;">} catch (IOException e) {</div><div style="word-break: break-all; margin: 10px 0px;">// TODO Auto-generated catch block</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("Can't save screenshot");</div><div style="word-break: break-all; margin: 10px 0px;">e.printStackTrace();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">finally</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("screen shot finished");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">public static void main (String [] args) throws InterruptedException</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">String URL="http://61.135.169.105/";</div><div style="word-break: break-all; margin: 10px 0px;">//avoid Chrome warnning message like "unsupported command-line flag --ignore-certificate-errors. "</div><div style="word-break: break-all; margin: 10px 0px;">ChromeOptions options = new ChromeOptions();</div><div style="word-break: break-all; margin: 10px 0px;">options.addArguments("--test-type");</div><div style="word-break: break-all; margin: 10px 0px;">System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");</div><div style="word-break: break-all; margin: 10px 0px;">WebDriver driver = new ChromeDriver(options);</div><div style="word-break: break-all; margin: 10px 0px;">driver.get(URL);</div><div style="word-break: break-all; margin: 10px 0px;">//max size the browser</div><div style="word-break: break-all; margin: 10px 0px;">driver.manage().window().maximize();</div><div style="word-break: break-all; margin: 10px 0px;">/*</div><div style="word-break: break-all; margin: 10px 0px;">Navigation navigation = driver.navigate();</div><div style="word-break: break-all; margin: 10px 0px;">navigation.to(URL);*/</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(2000);</div><div style="word-break: break-all; margin: 10px 0px;">snapshot((TakesScreenshot)driver,"open_baidu.png");</div><div style="word-break: break-all; margin: 10px 0px;">//WebElement reg=driver.findElement(By.name("tj_reg"));</div><div style="word-break: break-all; margin: 10px 0px;">//reg.click();</div><div style="word-break: break-all; margin: 10px 0px;">// &nbsp; &nbsp;WebElement keyWord = driver.findElement(By.id("kw1"));</div><div style="word-break: break-all; margin: 10px 0px;">//find the element</div><div style="word-break: break-all; margin: 10px 0px;">WebElement keyWord = driver.findElement(By.xpath("//input[@id='kw1']"));</div><div style="word-break: break-all; margin: 10px 0px;">keyWord.clear();</div><div style="word-break: break-all; margin: 10px 0px;">//send key words</div><div style="word-break: break-all; margin: 10px 0px;">keyWord.sendKeys("小<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">苹果</strong></u></a>");</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(3000);</div><div style="word-break: break-all; margin: 10px 0px;">snapshot((TakesScreenshot)driver,"input_keyWord.png");</div><div style="word-break: break-all; margin: 10px 0px;">WebElement submit = driver.findElement(By.id("su1"));</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println(submit.getLocation());</div><div style="word-break: break-all; margin: 10px 0px;">submit.click();</div><div style="word-break: break-all; margin: 10px 0px;">//System.out.println(driver.getWindowHandle());</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">WebElement se=driver.findElement(By.xpath("//*[@id=\"2\"]/div[1]/div[2]/table/tbody/tr/td[5]/span/a")) ;</div><div style="word-break: break-all; margin: 10px 0px;">Actions action = new Actions(driver);</div><div style="word-break: break-all; margin: 10px 0px;">action.clickAndHold(se);</div><div style="word-break: break-all; margin: 10px 0px;">action.sendKeys(Keys.DOWN);</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">List&lt;WebElement&gt; elementList = driver.findElements(By.tagName("herf"));</div><div style="word-break: break-all; margin: 10px 0px;">for(WebElement e:elementList)</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">System.out.print("--&gt;"+e.getText());</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">//se.click();</div><div style="word-break: break-all; margin: 10px 0px;">// System.out.println(driver.getPageSource());</div><div style="word-break: break-all; margin: 10px 0px;">// &nbsp;System.out.println(pageSource);</div><div style="word-break: break-all; margin: 10px 0px;">//WebElement link =driver.findElement(By.xpath(SELENIUM_LINK));</div><div style="word-break: break-all; margin: 10px 0px;">WebElement link =driver.findElement(By.xpath("//*[@id=\"2\"]/div[1]/div[2]/table/tbody/tr/td[5]/span/a"));//By.xpath("//*[@id=\"1\"]/h3/a")); &nbsp; &nbsp; //*[@id="1"]/h3/a</div><div style="word-break: break-all; margin: 10px 0px;">link.click();</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">driver.switchTo().window(driver.getWindowHandles().toArray(new String[0])[1]);</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">WebElement down =driver.findElement(By.xpath("//*[@id=\"128\"]"));//&lt;i class="icon btn-icon-download-small"&gt;&lt;/i&gt;</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">down.click();</div><div style="word-break: break-all; margin: 10px 0px;">snapshot((TakesScreenshot)driver,"down_m.png");</div><div style="word-break: break-all; margin: 10px 0px;">//get page title</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println(driver.getTitle());</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">WebElement userName=driver.findElement(By.id("TANGRAM__PSP_8__userName"));</div><div style="word-break: break-all; margin: 10px 0px;">WebElement password=driver.findElement(By.id("TANGRAM__PSP_8__password"));</div><div style="word-break: break-all; margin: 10px 0px;">WebElement login=driver.findElement(By.id("TANGRAM__PSP_8__submit"));</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(5000);</div><div style="word-break: break-all; margin: 10px 0px;">userName.sendKeys("QAtest");//your baidu userName</div><div style="word-break: break-all; margin: 10px 0px;">password.sendKeys("mypassword");//your baidu password</div><div style="word-break: break-all; margin: 10px 0px;">login.submit();</div><div style="word-break: break-all; margin: 10px 0px;">// &nbsp; &nbsp; navigation.back();</div><div style="word-break: break-all; margin: 10px 0px;">snapshot((TakesScreenshot)driver,"open_bake.png");</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println(driver.getTitle()+"\n"+driver.getCurrentUrl());</div><div style="word-break: break-all; margin: 10px 0px;">Thread.sleep(50000);</div><div style="word-break: break-all; margin: 10px 0px;">File file=new File("C:\\Users\\Young\\Downloads\\小苹果.mp3");</div><div style="word-break: break-all; margin: 10px 0px;">if(file.exists())</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("PASS");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">else</div><div style="word-break: break-all; margin: 10px 0px;">{</div><div style="word-break: break-all; margin: 10px 0px;">System.out.println("FAIL");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">driver.quit();</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　如果出现：unsupported command-line flag --ignore-certificate-errors.</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　//avoid Chrome warnning message like "unsupported command-line flag --ignore-certificate-errors. "</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　ChromeOptions options = new ChromeOptions();</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　options.addArguments("--test-type");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif;">　　WebDriver driver = new ChromeDriver(options);</div><div><table cellspacing="1" border="0" id="SL_tables"><tbody><tr><td align="left" width="20%"><div id="SL_lng_from">English&nbsp;&#187;</div></td><td align="left" width="20%"><select id="SL_lng_to"><option value="af">Afrikaans</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="hy">Armenian</option><option value="az">Azerbaijani</option><option value="eu">Basque</option><option value="bn">Bengali</option><option value="be">Belarusian</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese&nbsp;(Simp)</option><option value="zh-TW">Chinese&nbsp;(Trad)</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="eo">Esperanto</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="ka">Georgian</option><option value="de">German</option><option value="el">Greek</option><option value="gu">Gujarati</option><option value="ht">Haitian&nbsp;Creole</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="is">Icelandic</option><option value="id">Indonesian</option><option value="ga">Irish</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lo">Lao</option><option value="la">Latin</option><option value="lv">Latvian</option><option value="lt">Lithuanian</option><option value="mk">Macedonian</option><option value="ms">Malay</option><option value="mt">Maltese</option><option value="no">Norwegian</option><option value="fa">Persian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sr">Serbian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option selected="" value="es">Spanish</option><option value="sw">Swahili</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="ur">Urdu</option><option value="vi">Vietnamese</option><option value="cy">Welsh</option><option value="yi">Yiddish</option></select></td><td width="13%" align="center">&nbsp;</td><td width="8%" align="center"><div id="SL_TTS_voice" title="Listen to the translation" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/tts-voice.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div></td><td width="8%" align="center"><div id="SL_copy" title="Select text" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/copy_hand.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div></td><td width="8%" align="center"><div id="SL_bbl_font" title="Font size" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/font-off.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div></td><td width="8%" align="center"><div id="SL_TH" title="Translation history" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/history.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div></td><td width="5%"></td><td width="8%" align="right"><div id="SL_pin" title="Pin pup-up bubble" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/pin-off.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div></td></tr></tbody></table></div><div id="SL_shadow_translation_result" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg.png) #ffffff;"></div><div id="SL_bbl_donate" title="Make a small contribution" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/donate2.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div><div id="SL_Balloon_options" style="background: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg3.png) #f4f5f5;"><a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/options-bbl.html" target="_blank" title="Show options">Options</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/history.html" title="Translation history" target="_blank">History</a>&nbsp;:&nbsp;<a href="http://about.imtranslator.net/add-ons/chrome-extension/" target="_blank" title="ImTranslator Help">Help</a>&nbsp;:&nbsp;<a href="chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/feedback.html" title="Feedback" target="_blank">Feedback</a></div><div id="SL_player"></div><div id="SL_alert100" style="background-image: url(chrome-extension://noaijdpnepcgjemiklgfkcfbkokogabh/img/util/bg2.png); background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/418042.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-18 09:28 <a href="http://www.blogjava.net/qileilove/archive/2014/09/18/418042.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>自动化测试—想说爱你不容易</title><link>http://www.blogjava.net/qileilove/archive/2014/09/15/417925.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 15 Sep 2014 01:32:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/09/15/417925.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/417925.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/09/15/417925.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/417925.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/417925.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　正如许多事情都有其两面性一样，<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>方法也是这样。要保证测试方法正确，最简单、最直观地想法就是多写些<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试用例</strong></u></a>，从更多地角度去测试，但这必然增加我们的测试成本。小步快跑要求我们频繁进行测试，假如我们重构的周期是20分钟，但测试却要花掉10分钟，那么这样的成本就实在太大了。假如这种测试还是开发人员手工测试，每天都有对同样的测试反复执行数十遍，那么开发人员估计就要疯掉了。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　你可能立即就想到<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>了。是的，在许多重构的书籍中，大师们都建议我们在重构开始前，首先建立自动化测试机制。但遗憾的是，我经过多年的实践总结出来的经验是，这几乎不可能实现。每次重构，我们面临的都是一个个遗留系统。大多数遗留系统都有一些共同的特征：代码凌乱，没有清晰的接口；代码间耦合度高，相互依赖严重；<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>层、业务层、数据访问层往往没有清晰的界限，代码相互参杂其中。在这样的情况下，编写自动化测试代码是几乎不可完成的任务。当然，这里所说的自动化测试代码，是指那些基于<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">JUnit</strong></u></a>编写的自动化测试程序</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　举一个简单的例子：假如你现在要测试一个开票类，想编写它的测试代码。本来这个开票类并不复杂，业务也很清晰。但是在函数传递参数时，其中一个参数是Web容器中的Request、Response或Session。这下麻烦了，为了测试一个简单的函数，我们必须启动整个Web应用，这是我们不可接受的。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　随后你可能会说了，我们为什么非要传递一个真正地Request、Response或Session呢？我们Mock一个假的嘛！想法不错，但你真正去尝试Mock时你会发现这也是一个不可完成的任务。Request、Response或Session有许多的状态，属性变量中又有对象，又有属性变量。除此还有大量集合变量，集合变量里都有什么对象，天才知道。因此，即使你费尽千辛万苦Mock出来，也可能因某些属性不对而使得测试失败。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　另一个写自动化测试程序比较忌讳的就是访问<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>。比如你这次执行的插入操作成功了，并不意味着下次执行就可以成功。下次执行会报&#8220;主键冲突&#8221;错误，出现这个错误并不是被测程序错了，而是测试程序错了。上次执行一个查询产生的结果集，不一定就是下一次执行同样一个查询产生的结果。查询结果变了，并不意味着被测程序错了，而是测试程序不对。自动化测试程序之所以能够自动化执行，必须要保证测试过程是可以反复执行的，并且不论什么时候执行都有一个确定的结果。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　总之，自动化测试不是银弹，并不是所有代码都适合自动化测试。与Web容器或其它设备驱动相关的代码是不适合自动化测试的，因为我们在测试的时候不希望去启动Web容器或其它设备。因此，我们在做自动化测试程序前，首先应当确保要测试的程序已经与Web容器或其它设备驱动相关的代码充分解耦。一个比较好的办法就是分离出Web层与BUS层，Web层负责从Web容器中获取数据，并打包传递给BUS层，而BUS层则完成真正需要测试的业务逻辑。</div><div style="word-break: break-all; line-height: 21.6000003814697px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　另一个不适合自动化测试的就是要访问数据库的程序，因为它们执行的结果总是与数据库状态有关，无法获得稳定而可以不断复现的结果。所以，我们解决它的最好办法就是将访问数据库的部分Mock掉。如何Mock呢？你不能Mock一个JDBC，也不能Mock一个Hibernate，因为那都过于复杂了，你唯一可以做的就是将DAO层Mock掉。这就要求我们对系统重构的时候，要将数据库访问的代码从业务代码中脱离出来，写入到DAO层。最后，被Mock的DAO层代码并不真正去访问数据库。每当客户程序传入一个参数时，它首先作为测试程序去验证这个参数是否与预期一致，然后返回一个确定的结果。</div><img src ="http://www.blogjava.net/qileilove/aggbug/417925.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-09-15 09:32 <a href="http://www.blogjava.net/qileilove/archive/2014/09/15/417925.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入理解基于Selenium的二次开发</title><link>http://www.blogjava.net/qileilove/archive/2014/08/19/417100.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 19 Aug 2014 05:16:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/08/19/417100.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/417100.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/08/19/417100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/417100.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/417100.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　对于做<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>端<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>的人来说，可能接触selenium比<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">QTP</strong></u></a>还要多，但是我们在做基于selenium的二次开发的时候，经常会说到二次开发是 为了易于维护，很多人可能不懂得维护的价值是什么，和到底要维护什么。今天专门写一篇关于二次开发的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">文章</strong></u></a>，希望能够帮到有需要做二次开发的人。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　二次开发也就是我们常说的封装selenium，或者做框架。但是一个框架要包含丰富的类和方法。要有一套完整的体系来帮助我们进行封装。可以说框架的设 计思想就是整个框架的灵魂，如果设计思想很正确也就意味着这个框架成功了一半，剩下的就是我们怎么样用程序实现这个思想，在开发的过程中我们也许会用到一 些设计模式和引用一些开源框架。这些只是一个开发人员或者程序设计者的基本素质。至于如果把selenium能够有效的封装和一些基本思想，我们来详细的 了解一下。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在这篇文章里面只针对selenium的webdriver来进行讨论，我们不再对rc做任何的解释和说明。我们都知道webdriver的使用过程中， 贯穿始终的就是一个driver， 并且这个driver代表了一个浏览器的当前窗口，我们进行操作的过程中只是进行当前窗口的操作，也就是最这个current window进行的一系列的操作，如果我们需要对打开的新的window来进行操作的话，我们需要switchTo，包括操作frame，当然整个流程下 的操作确实让我们觉得不是很难编写，但是我们编写脚本的过程中需要用到的一些辅助功能可能就会很难的编写，比如最大化浏览器，视角<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">移动</strong></u></a>到操作的元素等等， 这个过程一次编写我们可以做到，但是反复的编写的话肯定是一个让人很头疼的过程，所以这个时候我们要去封装一些常用的方法，我们有了做一个比较完整的框架 的想法，但是我们忽然又意识到了，这样的话，我们需要把driver封装起来，因为整个测试的case都是针对的这个driver，并且只有一个 driver，这样子的话我们不允许创造多个的driver，也就意味着我们要把自己编写的小工具类和driver联系起来，并且我们的测试用例case 类也需要调用这个driver，其实很简单，我们可以用注入的方式来做，把driver当成tools类的一个属性值，然后注入到我们的case类中，也 可以通过set的方法来进行操作。有了这些基础，我们可以防止无限的编写重复的方法，这样我们有了自己的工具类。如果说这就是框架的话，就会显得非常的肤 浅，因为我们写的这些方法根本没有任何逻辑可言，只是把需要的方法统统的堆到了一起，所以这个时候我们需要想想用到某些方法来进行分一下层次。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　Page类和Window类：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　PageObject模式我们都知道，就是把资源都放入到page类里面，然后再编写逻辑类。这样的话就可以无限的复用这些资源，这只是笼统的讲了一下设 计的思想，至于PageObject到底怎么去实现这些设计呢？我们从webDriver的使用开始入手。webdriver是先从定义浏览器开始的。 WebDriver driver = new FirefoxDriver(); 这样我们就定义了一个firefox的浏览器，但是自动化的过程不可能只允许我们把定义浏览器的操作放在框架代码里面，那样的硬编码方式使我们的case 不存在可移植性了，如果进行兼容性测试的话，维护起来对这些case的修改量是比较大的，这种硬编码方式是我们不能够进行大量维护的，所以我们需要把定义 浏览器的过程完全放在case类里面，就是在我们写<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试用例</strong></u></a>的时候再去编写到底用什么浏览器，防止在编写框架的时候硬编码的形式把浏览器写死在了框架里 面。做到多浏览器的可维护性，对于我们进行兼容测试也有一定的帮助，这样的话我们需要对浏览器的选择部分要进行一定的编码设计，来完成浏览器的可选择性。 在我们定义完了浏览器之后，这个时候我们也许觉得就是开始查找元素了，但是在这个driver的基础上我们应该发现其实这个时候driver代表的整个页 面的操作。但是在页面的操作基础上我们应该意识到还有一个级别的操作，那就是window的操作，就是针对浏览器自身的操作。包括一些基本的返回，向前， 最大化，最小化，或者移动到制定元素的位置，调用js等等等，这些方法的级别是出于window级别的，和页面无关的。所以我们应该把这些所有的方法都封 装到单独的一个层次中，我们暂且称之为window包中，刚才的浏览器的选择的所有方法我们放browser包中。这样我们设计出了两个层次。下面的设计 该如何进行呢？我们知道pageObject的思想是把资源都放入到我们定义的page类里面，所以这个时候我们需要思考了，我们如何设计这里的page 类呢？按照pageObject的思想来看，page类应该是我们自己编写的，那样我们的框架是不是就可以放弃编写page类了呢？直接封装一些通用的方 法？显然是不对的，对于页面html源码操作的过程中，我们烦透了这些元素查找的硬编码方式，在一个case里面或者两个case里面反复的调用编写是让 人头疼的一件事情，所以我们可以把所有的单页面看做一个层次，里面和PageObject的思想一样，就是放入了通用的方法，但是它存在的意义不只是这样 简单，因为我们操作的过程中需要涉及到frame。并且页面和页面之间涉及到不同window之间的切换，所以如何协调window和page之间的关系 成为了我们需要注意的难点和重点，我们知道webdriver里面有一个方法叫做getWindowHandlers，这个方法可以获得所有的句柄，我们 想设计这个page类那么意味着我们需要去完美的配合window类，他们之间唯一的关联就是这个方法，所以我们可以设计一个概念，叫做页面集合，在创建 window对象的时候我们就会自动的出现一个页面集合器，它的功能就是管理所有的在操作过程中打开的页面。并且能够指定一个特殊的page，就是当前页 面。也就是webdriver中的driver对象，因为它一直都是针对当前页面编程的。那样我们的window类里面就存在了两个属性，一个收集器，一 个当前页。这样我们在window的级别上就能够完全操作page类了，这样我们在case类设计的时候，只需要通过window类的级别进行编码就可以 了，完全可以把page类当作一种资源来处理，我们所有需要的东西都是通过page来获取的。page类的设计中我们一定要编写通用的方法。比如获取 title等等等，最主要的一点就是要进行frame的处理操作，我们如何把frame完美的结合在page里面呢？我们在普通的webdriver脚本 编写过程中可能反反复复的switchTo的方法让我们很恼火，并且很难让我们理解这些脚本到底是想表达什么意思呢？所以我们需要进行对page进行层次 上的小分级，就是把page类再分为一个frame的类和一个模块的类，因为一个大型页面里面，通用的结构和模块是很多的。我们单独的定义一个模块类，可 以让这些相同的结构复用在里面的方法。定义frame类主要是处理把定位到frame的操作从case类中脱离出来，我们编写到page类里面或者 frame类里面，提供一种方式或者方法来进行frame的定位就可以了，简单实用，并且简化case类的编写，毕竟case类并不是由设计者来编写，尽 量做到最简化。当然我们可以成这整个层次都是page类，放在page包里面。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　Element类：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Element类就是我们常用的driver.findElement（）的那种形式，就是元素类，什么是元素类呢？元素就是我们需要定位的那些东西，我 们在操作过程中很难知道一个findElement到底查找的是什么，因为所有的标签形式都是通过id或者各种各样的定位方式来实现的。这个时候我们需要 把各种各样的findElement都统统的放在一起，造成的脚本难以理解让后续接手的脚本开发人员可能头疼不已，所以我们可以做一些简单的加工。当然我 们还要做的一个最大的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>就是元素查找的封装。Element和Page类如何关联起来。我们知道page和webElement的关联就是一个 driver.findElement的方法。这样就可以在页面上查找元素了。所以我们也在element类中通过这种形式来进行他们之间的关联。我们通 过在element类中添加定位方式的形式来进行元素定位和page的关联，我们只需要在编写自己的page类的过程中直接加入element类就可以 了，element类提供了所有的关于element的方法，比如鼠标事件和键盘事件，还有更重要的元素定位方法。定位的方法在这里不做任何的推荐，因为 每个人的思路不同，实现的方式也不同，我个人比较偏向的做法是做一个xml来进行资源的管理，把所有需要的资源都放入到xml里面，这样我们就可以进行元 素的定位了。并且在后期维护中主要维护xml就可以进行对整个脚本进行维护了，不需要我们大量的重新进行源码的分析和修改了。当然这是设计的优化过程，因 为定位的实现我们还是需要自己来完成的，我们知道元素的定位方式各种各样，我们怎么来进行管理和定位呢？我们可以通过map的方法作为属性值来进行元素的 管理，他的各种定位方法存放在map中，我们需要的时候只需要调一下就可以了。通过观察源码findElement也是通过map的形式来进行元素定位存 储的。我们可以借鉴一下源码的实现方式。当然我们完全封装findElement也是可以的。说到这里可能我们有一个问题比较难以解决，那就是层级定位。 如果我们只是给element类添加定位方式的话，那么findElement提供的一级一级的定位方式我们就无法应用了，所以在element类中我们 必要还要提供findElement的方法进行层级定位。这只是为了把webdriver的所有方法都尽量应用到而已。其实通过xpath的方式我们就可 以基本上定位大多数的元素。剩下的内容就是我们对element内容的扩充了。我们可以把元素的更加具体的抽象出来，比如我们把 select，table，checkbox等等等的各种html标签元素显式的定义出来，在我们定义一个元素的时候我们能够更加清晰的看到这个元素的含 义，我们知道它是一个按钮或者table等等等，这些小元素的操作需要我们自己深入理解和开发，这里不做过多的介绍。<br /><br /><div style="word-break: break-all; margin: 10px 0px;"><strong style="word-break: break-all; line-height: normal !important;">其他类：</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　通过这些层次的分析我们已经出现一个框架的雏形了，然后我们剩下的设计就是基于完善和优化了。在一个自动化过程中case类是非常重要的，我们需要知道 case类运行结束的结果报告和分析，所以case类的运行等等一系列的东西我们都得有统计，这些东西必须要我们提供一些类来实现，不过所幸的是，强大的 junit或者testng完全可以取代我们要去做的工作，他们可以很完美的提供这些功能，我们只需要介入这些开源包就可以了。我们使用QTP的过程中我 们经常会用到参数化，我们自动化的设计都有了，但是没有参数化的功能怎么办？我们应该先想象一下数据提供的方式。testng提供了一种参数化的形式，但 是它是需要在xml里面配置或者硬编码的形式来进行编写。不过它提供了一种dataprovider的方式来进行参数化，它传递参数的形式是 Object[][]，我们可能希望使用参数的时候通过excel表格来完成，这些都是可以实现的，poi包提供了解析excel的功能，非常的强大。我 们可以自己编写解析类来进行参数化的功能编写，具体实现不再过多去说。调用的方式就简单多了，硬性的记住几个注解就可以了。case类的各种运行我们都有 了，还需要一些什么扩展呢？很显然就是日志的扩展。日志的设计也是很有技巧的。我们需要用日志监控某一些方法的话，如果前期没有直接加入日志功能，我们可 以通过spring的方式来进行日志切入操作。但是我们在观察日志的时候我们通常会希望知道到底运行到哪一步了，我们可以想一想，所有的操作都是基于 element或者window的，page的只是一个抽象出来的概念，所以我们只需要把日志加入到每一个element的方法和window的主要方法 里面就可以监控到整个运行的过程，毕竟我们不能够去亲自盯着屏幕一直。这样没个方法不外乎就是运行成功和失败，所以我们可以通过这种方式来进行编码。日志 的实现我们可以通过通过的log4j或者自己编写一个小的日志系统。都是可行的方案。</div><div style="word-break: break-all; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">扩展类：</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　也许我们需要这些系统能够有良好的可移植性，我们可以自己编写类加载器，为以后做整个自动化的测试平台做准备。最主要都是我们做的这些操作可能需要越来简 单，所以我们可能会因为引入注解的方式来提供编码效率，所以我们还需要为注解类做一些辅助的工作。当然这些注解的开发需要我们做足足够的需求研究，并不是 无谓的去开发各种注解。这些注解的应用应该说很广泛，不再多说注解的好处。并且注解还有一点可应用的地方就是放在数据库的操作中，在自动化测试中，其实数 据库的测试也是一个大的难点。在这里我们只讨论前端自动化的设计，不过多的讨论别的东西。</div><div style="word-break: break-all; margin: 10px 0px;">　　前面讲到的这些类的存在形式其实就是在框架里面的一种层次，我们谈论的这些都是基于webdriver的，并且主要基于前端自动化测试的，当然自动化测试 不只包括这些，还包括服务器端，接口自动化，单元自动化等等。我个人的能力水平也是很有限，可能很多地方说到的不是很到位，希望能够通过这篇文章能够给那些希望学习自动化，希望编写小测试框架的童鞋，一点点的启发。</div></div><img src ="http://www.blogjava.net/qileilove/aggbug/417100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-08-19 13:16 <a href="http://www.blogjava.net/qileilove/archive/2014/08/19/417100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Web自动化测试原理</title><link>http://www.blogjava.net/qileilove/archive/2014/08/13/416882.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 13 Aug 2014 01:49:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/08/13/416882.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/416882.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/08/13/416882.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/416882.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/416882.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　目前有很多Web UI自动化<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>框架，如WatiN,Selinimu,WebDriver等，这些框架都可以操作Web中的控件，模拟用户输入，点击等操作，实现Web自动化测试。其实这些工具的原理都一样，都是通过调用IE COM接口和HTMLDOM 对IE浏览器以及WEB测试对象的操作。 本文介绍脱离这些<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>框架，通过AutoIT直接使用IE COM接口结合HTML DOM对IE浏览器以及WEB对象进行自动化测试的方法。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　1.IE常用操作</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　首先新建一个IE COM对象，配置IE窗口属性，模拟用户同时跳转至相应的页面同时进行相应操作。访问页面时，需要等待页面加载完成后再进行操作。这里我们可以使用IE COM的BUSY属性检查浏览器是否处于加载状态，再进行相应的操作。示例代码如下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=47416" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026181mFW6.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">2.利用DOM操作测试对象</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　现在已经会使用IE COM组件来对IE浏览器进行自动化的操作，但是对于浏览器页面中的测试对象IE COM是无法对其进行操作的，这个时候就需要使用HTML DOM来对其进行操作。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">2.1 HTML　DOM简介</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　HTML DOM是HTML Document Object Model（文档对象模型）的缩写，它将网页中的各个元素都看作一个个对象，从而使网页中的元素也可以被计算机语言获取或者编辑。 常用DOM 属性如下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=47418" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026183ILRj.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　className.同一样式规则的元素用相同的类名。可以通过className快速过滤出一组类似的元素。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　document.用于指向包含当前元素的文档对象。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　id.当前元素的标识。如果文档中包含多个相同id的元素，则返回一个数组。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　innerHTML.用于指向当前元素的开始标记和结束标记之间的所有文本和HTML标签。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　innerText.用于指向当前元素的开始标记和结束标记之间的所有文本和HTML标签。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　offsetHeight, offsetWidth.元素的高度和宽度。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　offsetLeft, offsetTop.当前元素相同对于父亲元素的左边位置和顶部位置。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　outerHTML.当前元素的开始标记和结束标记之间的所有文本和HTML标签。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　outerText.当前元素的开始标记和结束标记之间的所有文本，但不包括HTML标签。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　parentElement.当前元素的父亲元素。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sourceIndex.元素在document.all集合中的索引（index）。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　style.元素的样式表单属性。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　tagName.当前元素的标签名。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　title.在IE中，代表元素的tool tip文本</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　常用DOM方法如下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　click().模拟用户对当前元素的鼠标点击。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　contains(element).用于判断当前元素是否包含指定的元素。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　getAttribute(attributeName, caseSensitive).返回当前元素所包含的某个属性，参数attributeName为属性名、caseSensitive表示是否大小写敏感。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　setAttribute(attributeName, value, caseSenstive). 设置当前元素的属性。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　常用DOM 集合如下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　All[].当前元素中包含的所有HTML元素的数组。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　children[].当前元素包含的子元素。<br /><div style="word-break: break-all; margin: 10px 0px;"><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　<strong style="word-break: break-all;">2.2 种方法对比</strong></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　2.2.1getElementByID</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　getElementByID( )方法可根据指定的id属性值得到对象。 首先需要分析页面，在Chome浏览器中选择相应的网页元素点击右键选择"审查元素"（或使用IE Develop Toolbar或者firebug等插件亦可），即可得到页面控件的ID等信息。&nbsp;<a href="http://www.51testing.com/batch.download.php?aid=47419" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026184F7mY.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a>&nbsp;通过getElementByID方法获取百度搜索框及搜索按钮对象，并对其进行输入及点击操作，从而完成搜索操作。示例代码如下：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47420" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026185rwcF.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div></div><div style="word-break: break-all; margin: 10px 0px;">　　2.2.2getElementsByName</div><div style="word-break: break-all; margin: 10px 0px;">　　getElementsByName( )方法可返回带有指定名称的对象的集合。</div><div style="word-break: break-all; margin: 10px 0px;">　　同样获取网页元素name后，即可通过getElementsByName方法获取定位对象，并对其进行操作（与getElementByID返回的单个对象不同，getElementsByName返回的是一个元素的集合，需要通过遍历对象才能对其进行操作）：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47421" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026186Zpod.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　2.2.3getElementsByTagName</div><div style="word-break: break-all; margin: 10px 0px;">　　getElementsByTagName( )方法通过查找整个HTML文档中的任何HTML元素，传回指定名称的元素集合。 因此也可使用getElementsByTagName获取TAG名，通过得到相同类型的元素及在遍历中进行判断控件类型并进行操作：<a href="http://www.51testing.com/batch.download.php?aid=47421" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026186Zpod.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　2.3 利用FORM名来获取对象元素</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　使用FORM名来获取对象元素会大大简化我们的脚本。首先查看百度的搜索框对应的FORM名，得到FORM名为f：&nbsp;</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47423" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026188z0J7.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">通过如下简单的脚本，同样可以达到相同的效果：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47424" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_20140812102618909vb.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;"></div><div style="word-break: break-all; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　2.4 访问Web页面的Script脚本变量</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　通过DOM还可以直接访问Web页面中的JavaScript或者VBScript中的变量。首先打开百度的源文件：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47425" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_2014081210261810teSP.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　可以看到在百度源文件的JavaScript脚本中定义了一个变量为k，并且赋值为d.f.wd（实际上就是百度搜索框对象）。那么可以直接使用parentWindow来访问Web页面Script中的变量k，对百度搜索框进行自动测试：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=47417" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/08/14982672_201408121026182Iv7k.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　3 总结</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　本文主要介绍了利用IE的COM以及HTML DOM来自动化IE浏览器，以及对浏览器的一些控件对象进行自动化的操作，包括IE浏览器常用操作、利用DOM操作测试对象、利用FORM名来获取对象元素、访问Web页面的Script脚本变量等。 直接操作IE COM来实现Web自动化，不仅有助于有助于理解Web页面自动化测试框架的运行原理，还能脱离这些自动化测试框架自己快速建立一个轻量型的自动化测试程序，从而真正的提高测试效率。</div><div style="word-break: break-all; margin: 10px 0px;">原文链接：<span style="word-break: break-all; line-height: 21.59375px;">http://lovesoo.org/web-automation-testing-principle.html</span></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/416882.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-08-13 09:49 <a href="http://www.blogjava.net/qileilove/archive/2014/08/13/416882.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Selenium对浏览器的各种操作</title><link>http://www.blogjava.net/qileilove/archive/2014/07/31/416387.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 31 Jul 2014 01:55:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/31/416387.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/416387.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/31/416387.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/416387.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/416387.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　第一步就是安装<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>这个模块，当然，前提是你的python已经安装好了</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　直接在dos窗口输入</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　pip install selenium完成一键安装</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　然后就可以新建一个py文件，在里面输入</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">from selenium import webdriver</div><div style="word-break: break-all; margin: 10px 0px;">from selenium.common.exceptions import TimeoutException</div><div style="word-break: break-all; margin: 10px 0px;">from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0</div><div style="word-break: break-all; margin: 10px 0px;">from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0</div><div style="word-break: break-all; margin: 10px 0px;"># Create a new instance of the Firefox driver</div><div style="word-break: break-all; margin: 10px 0px;">driver = webdriver.Firefox()</div><div style="word-break: break-all; margin: 10px 0px;"># go to the&nbsp;<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">google</strong></u></a>&nbsp;home page</div><div style="word-break: break-all; margin: 10px 0px;">driver.get("http://www.google.com")</div><div style="word-break: break-all; margin: 10px 0px;"># find the element that's name attribute is q (the google search box)</div><div style="word-break: break-all; margin: 10px 0px;">inputElement = driver.find_element_by_name("q")</div><div style="word-break: break-all; margin: 10px 0px;"># type in the search</div><div style="word-break: break-all; margin: 10px 0px;">inputElement.send_keys("cheese!")</div><div style="word-break: break-all; margin: 10px 0px;"># submit the form (although google automatically searches now without submitting)</div><div style="word-break: break-all; margin: 10px 0px;">inputElement.submit()</div><div style="word-break: break-all; margin: 10px 0px;"># the page is ajaxy so the title is originally this:</div><div style="word-break: break-all; margin: 10px 0px;">print driver.title</div><div style="word-break: break-all; margin: 10px 0px;">try:</div><div style="word-break: break-all; margin: 10px 0px;"># we have to wait for the page to refresh, the last thing that seems to be updated is the title</div><div style="word-break: break-all; margin: 10px 0px;">WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))</div><div style="word-break: break-all; margin: 10px 0px;"># You should see "cheese! - Google Search"</div><div style="word-break: break-all; margin: 10px 0px;">print driver.title</div><div style="word-break: break-all; margin: 10px 0px;">finally:</div><div style="word-break: break-all; margin: 10px 0px;">driver.quit()</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　这样就打开google进行查找cheese!后打印标题并关闭浏览器</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下面介绍各种获取浏览器内的各种元素的方法</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">By ID</div><div style="word-break: break-all; margin: 10px 0px;">&lt;divid="coolestWidgetEvah"&gt;...&lt;/div&gt;</div><div style="word-break: break-all; margin: 10px 0px;">element=driver.find_element_by_id("coolestWidgetEvah")</div><div style="word-break: break-all; margin: 10px 0px;">By Class Name</div><div style="word-break: break-all; margin: 10px 0px;">&lt;divclass="cheese"&gt;&lt;span&gt;Cheddar&lt;/span&gt;&lt;/div&gt;&lt;divclass="cheese"&gt;&lt;span&gt;Gouda&lt;/span&gt;&lt;/div&gt;</div><div style="word-break: break-all; margin: 10px 0px;">cheeses=driver.find_elements_by_class_name("cheese")</div><div style="word-break: break-all; margin: 10px 0px;">By Tag Name</div><div style="word-break: break-all; margin: 10px 0px;">&lt;iframesrc="..."&gt;&lt;/iframe&gt;</div><div style="word-break: break-all; margin: 10px 0px;">frame=driver.find_element_by_tag_name("iframe")</div><div style="word-break: break-all; margin: 10px 0px;">By Name</div><div style="word-break: break-all; margin: 10px 0px;">&lt;inputname="cheese"type="text"/&gt;</div><div style="word-break: break-all; margin: 10px 0px;">cheese=driver.find_element_by_name("cheese")</div><div style="word-break: break-all; margin: 10px 0px;">By Link Text</div><div style="word-break: break-all; margin: 10px 0px;">&lt;a href="http://www.google.com/search?q=cheese"&gt;cheese&lt;/a&gt;&gt;</div><div style="word-break: break-all; margin: 10px 0px;">cheese=driver.find_element_by_link_text("cheese")</div><div style="word-break: break-all; margin: 10px 0px;">By Partial Link Text</div><div style="word-break: break-all; margin: 10px 0px;">&lt;a href="http://www.google.com/search?q=cheese"&gt;search for cheese&lt;/a&gt;</div><div style="word-break: break-all; margin: 10px 0px;">cheese=driver.find_element_by_partial_link_text("cheese")</div><div style="word-break: break-all; margin: 10px 0px;">By CSS</div><div style="word-break: break-all; margin: 10px 0px;">&lt;divid="food"&gt;&lt;spanclass="dairy"&gt;milk&lt;/span&gt;&lt;spanclass="dairy aged"&gt;cheese&lt;/span&gt;&lt;/div&gt;</div><div style="word-break: break-all; margin: 10px 0px;">cheese=driver.find_element_by_css_selector("#food span.dairy.aged")</div><div style="word-break: break-all; margin: 10px 0px;">By XPATH</div><div style="word-break: break-all; margin: 10px 0px;">&lt;inputtype="text"name="example"/&gt;&lt;INPUTtype="text"name="other"/&gt;</div><div style="word-break: break-all; margin: 10px 0px;">inputs=driver.find_elements_by_xpath("//input")</div></td></tr></tbody></table><div style="word-break: break-all; margin: 10px 0px;">　　（相关的XPATH教程具体可以参考W3C的教程进行学习）</div><div style="word-break: break-all; margin: 10px 0px;">　　Using JavaScript</div><div style="word-break: break-all; margin: 10px 0px;">　　这么这是两个例子，例子一需要提前加载jqury的支持</div><div style="word-break: break-all; margin: 10px 0px;">　　element=driver.execute_script("return $('.cheese')[0]")</div><div style="word-break: break-all; margin: 10px 0px;">　　labels=driver.find_elements_by_tag_name("label")inputs=driver.execute_script("var labels = arguments[0], inputs = []; for (var i=0; i &lt; labels.length; i++){"+"inputs.push(document.getElementById(labels[i].getAttribute('for'))); } return inputs;",labels)</div><div style="word-break: break-all; margin: 10px 0px;">　　User Input - Filling In Forms</div><div style="word-break: break-all; margin: 10px 0px;">　　select=driver.find_element_by_tag_name("select")allOptions=select.find_elements_by_tag_name("option")foroptioninallOptions:print"Value is: "+option.get_attribute("value")option.click()</div><div style="word-break: break-all; margin: 10px 0px;">　　有些选择提取的元素是需要进行筛选的如</div><div style="word-break: break-all; margin: 10px 0px;">　　# available since 2.12fromselenium.webdriver.support.uiimportSelectselect=Select(driver.find_element_by_tag_name("select"))select.deselect_all()select.select_by_visible_text("Edam")</div><div style="word-break: break-all; margin: 10px 0px;">　　那么这些form进行如何提交呢？</div><div style="word-break: break-all; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">　　driver.find_element_by_id("submit").click()</div><div style="word-break: break-all; margin: 10px 0px;">　　element.submit()</div><div style="word-break: break-all; margin: 10px 0px;">　　Moving Between Windows and Frames</div><div style="word-break: break-all; margin: 10px 0px;">　　&lt;a href="somewhere.html"target="windowName"&gt;Click here to open a new window&lt;/a&gt;</div><div style="word-break: break-all; margin: 10px 0px;">　　driver.switch_to_window("windowName")</div><div style="word-break: break-all; margin: 10px 0px;">　　driver.switch_to_frame("frameName")</div><div style="word-break: break-all; margin: 10px 0px;">　　driver.switch_to_frame("frameName.0.child")</div></td></tr></tbody></table></div><div style="word-break: break-all; margin: 10px 0px;">　　切换一些弹出来的比如登录框等</div><div style="word-break: break-all; margin: 10px 0px;">　　Popup Dialogs</div><div style="word-break: break-all; margin: 10px 0px;">　　这类的有alerts, confirms, and prompts等</div><div style="word-break: break-all; margin: 10px 0px;">　　alert=driver.switch_to_alert()</div><div style="word-break: break-all; margin: 10px 0px;">　　返回的是一个弹窗的窗体对象</div><div style="word-break: break-all; margin: 10px 0px;">　　Cookies</div><div style="word-break: break-all; margin: 10px 0px;">　　# Go to the correct domaindriver.get("http://www.example.com")# Now set the cookie. Here's one for the entire domain# the cookie name here is 'key' and its value is 'value'driver.add_cookie({'name':'key','value':'value','path':'/'})# additional keys that can be passed in are:# 'domain' -&gt; String,# 'secure' -&gt; Boolean,# 'expiry' -&gt; Milliseconds since the Epoch it should expire.# And now output all the available cookies for the current URLforcookieindriver.get_cookies():print"%s -&gt; %s"%(cookie['name'],cookie['value'])# You can delete cookies in 2 ways# By namedriver.delete_cookie("CookieName")# Or all of themdriver.delete_all_cookies()</div><div style="word-break: break-all; margin: 10px 0px;">　　Changing the User Agent</div><div style="word-break: break-all; margin: 10px 0px;">　　profile=webdriver.FirefoxProfile()profile.set_preference("general.useragent.override","some UA string")driver=webdriver.Firefox(profile)</div><div style="word-break: break-all; margin: 10px 0px;">　　Drag And Drop</div><div style="word-break: break-all; margin: 10px 0px;">fromselenium.webdriver.common.action_chainsimportActionChainselement=driver.find_element_by_name("source")target=driver.find_element_by_name("target")ActionChains(driver).drag_and_drop(element,target).perform()</div><div style="word-break: break-all; margin: 10px 0px;">　　具体的详细用法可以参考官方文档：http://docs.seleniumhq.org/docs/03_webdriver.jsp</div></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; height: 21px; position: relative; width: 627.1875px; background-color: #ffffff;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/416387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-31 09:55 <a href="http://www.blogjava.net/qileilove/archive/2014/07/31/416387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>《我所知道的软件测试自动化》—关键字驱动的过去和未来</title><link>http://www.blogjava.net/qileilove/archive/2014/07/31/416385.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 31 Jul 2014 01:36:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/31/416385.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/416385.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/31/416385.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/416385.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/416385.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">鉴于这个系列写的内容是希望帮助&#8220;大多数2-3年<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>经验、急切盼望提升自身能力的 tester找到捅破&#8216;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>自动化&#8217;窗户纸的办法&#8221;，所以木有高深内容，高手们请直接飘过，呵呵。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1.<strong style="word-break: break-all; line-height: normal !important;">&#8220;关键字驱动&#8221;的由来</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　说到&#8220;关键字驱动&#8221;和&#8220;测试自动化&#8221;，就不能不提到 Mosley Daniel 的《<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">软件测试</strong></u></a>自动化》一书，这本书03年引入国内，04年市面上开始有卖，书中有两个相信能吸引到很多 tester 的话题：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　（1）脚本应该录制还是编写？&#8212;&#8212;想知道答案的自己下载电子书看吧：）</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　（2）&#8220;数据驱动&#8221;和&#8220;关键字驱动&#8221;。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　彼时的我，刚刚经历了一次不成功的自动化实践，虽然<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Rational</strong></u></a>&nbsp;Robot 提供了类似UI库管理，数据池管理之类的强大功能，但是痛苦依然。对测试自动化理解的不够深入，不知道该如何应对RAD模式下UI和业务快速调整，以及对C/S下非标准控件的识别等问题，导致了无法快速维护脚本、replay 次数不够，回放通过率不够，最后的结果是ROI无法满足要求，自动化项目宣告结束。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　带着很多疑问的我原本想从那本书中找到些答案，遗憾的是那时功力实在太差，居然没有看懂，唯一留下印象的就是作者在80年代就开始探索自动化回归的技术，并且在90年代已经尝试了&#8220;数据驱动&#8221;和&#8220;关键字驱动&#8221;的技术，想来当时 Robot framework 之类的都还没有出现，所以我相信&#8220;关键字驱动&#8221;的技术源自这书的作者和他的朋友们。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　<strong style="word-break: break-all; line-height: normal !important;">　2. 从&#8220;数据驱动&#8221;到&#8220;关键字驱动&#8221;</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　所谓的数据驱动，原本没有什么特别的，无非就是把hard code 在脚本中的数据参数化出来，之所以算是Robot、WinRunner甚至<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">QTP</strong></u></a>时代测试工具的卖点，其实主要是因为那个年代大多数system tester 不懂开发，总需要有个功能来帮助自己完成参数抽取、数据维护、自动替换之类的功能。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　而关键字驱动，则进一步在技术上把 tester 分成了完全不懂技术的和懂点技术的，前者只能根据格式填写一下 excel 表格，后者对工具/框架内置的所谓关键字库进行增补或二次开发。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　找些例子来看看吧。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　（1）简单的数据驱动。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　如下面代码，定义了一个class并实例化了几个对象，用来存放不同的用户登录信息；而在负责完成登录操作的 do_login_as() 方法中，把 send_keys 原来向表单中填充的数据参数化，根据每次调用 do_login_as() 方法时传入的不同对象来实现用不同帐号登录的效果&#8212;&#8212;虽然我对以&#8220;登录&#8221;为样例介绍<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>脚本深恶痛绝，不过这里为了表述简单，还是用了。（下面的代码只是一个示例，不是直接用来运行的。）</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46920" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_2014071411054010aay.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　其实数据驱动本来也没有什么技术含量，写过代码的谁还不知道什么是变量啊？不过在早期的商业工具中，的确把这个作为了一个卖点，毕竟10年前的测试工具设计思路也与现在不同。早期的工具始终都假设&#8221;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">系统测试</strong></u></a>工程师不懂开发&#8220;，所以他们在开发测试脚本时需要借助类似录制回放+编辑调试的模式；另外，对于数据驱动所需要的测试数据，最好也是通过工具内置的data pool 管理，通过表格编辑，甚至读取 csv、excel 文件之类的。如果我们依照这个思路去实现自己的测试框架，那肯定是商业工具很有价值，毕竟自己实现data pool管理、外部数据文件读取之类的功能，代码量也不小，要处理好那些数据格式和内容校验之类的，貌似跟我们所需要完成的自动化也没啥太大关系。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　可问题在于，为什么一定要有data pool+外部数据文件来实现&#8221;数据驱动&#8220;呢？</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　（2）传统的&#8220;关键字驱动&#8221;</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　还是先用个例子来看看传统的&#8220;关键字驱动&#8221;长什么样子。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46921" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407141105402qTZP.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　上面是一个&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;0.x 时代Core模式下（什么是selenium的core模式和RC模式请自行google，不过话说现在已经全民webdriver时代了，不知道也就不知道吧）的例子（QTP的实现效果也类似），简单说就是第一行是&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">test</strong></u></a>&nbsp;case name，下面3列开始进入正题，第一列表示你想干啥，第二列是被操作对象是谁，第三列是你对它干了啥。06年刚刚开始尝试<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>测试自动化的时候，我们一度认为这是一个比之前的测试工具要智能的多的东东，不过在尝试了很长一段时间之后，还是发现了这种模式下的问题，又逐渐转回了编写脚本的方式。<br /><div style="word-break: break-all; margin: 10px 0px;">对比上面的第一个脚本，可以看出关键字驱动进一步屏蔽了底层的实现细节，例如，你只需要clickAndWait那个btnG，而不需要知道btnG到底是个啥，以及它在哪里，你只需要填写表格。等你把一个个 test case 变成了一个个表格，把一个个step变成了一行行表格中的内容，基本上你的自动化测试就搞完了。&#8212;&#8212;真的是这样吗？</div><div style="word-break: break-all; margin: 10px 0px;">　　现在回想一下，关键字驱动之所以会出现，可能初衷还是为了降低自动化实施的门槛&#8212;&#8212;因为tester都不太懂开发嘛，所以开发能力强的人把框架实现出来，原来那些只会写excel的 system tester填写表格就可以了。也许现在还有很多公司会倾向于这个方案，美其名曰&#8220;分工协作，人尽其能&#8221;。不过关于这个问题，暂时先不展开讨论，先看看这种传统的关键字驱动模式会遇到什么问题。</div><div style="word-break: break-all; margin: 10px 0px;">　　首先，页面对象的识别问题。这是任何一种基于UI实现回归测试自动化的框架都会遇到的问题。在C/S时代，就已经出现了很多定制化UI组件难以被工具识别的问题，可好歹总逃不出windows的手心。到了web时代，前端实现技术百花齐放，而前端代码的编写也更是一个开发人员一个习惯，如果缺少统一的编码规范，对于那些没有使用id或者name之类属性的页面对象，传统的关键字驱动框架就没有例子中看起来那么美好了。当然，有人说xpath可以解决一切问题。嗯，xpath是很强，但是一个没有开发经验的tester想掌握它其实也不会比学会一点基本的编码技术容易多少；另外，xpath并不是万能的，在实际中还是有些它处理不了的情况。下面再给个例子（如果tester看不懂这个例子，估计学会xpath也有点困难）：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46922" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407141105403sKHI.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　上面这个图中是一个表格，id列（第一列）和需求名称列（第二列）下显示的内容，都是可以点击的超链接，最后的&#8220;操作&#8221;一列中的一个个小图标也各自指向一个链接（分别是&#8220;变更&#8221;、&#8220;评审&#8221;、&#8220;编辑&#8221;、&#8220;建用例&#8221;），通过查看第一行记录的html代码，我们发现：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46923" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_2014071411054046Gfh.thumb.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　假如想要编辑一条记录，没有可利用的id或name属性，唯一可用的是link；</div><div style="word-break: break-all; margin: 10px 0px;">　　link指向的url中包含了这条记录的ID信息，因为这里是第一行记录的代码，所以都是341，而后面的每一行记录的代码都是各自的ID。</div><div style="word-break: break-all; margin: 10px 0px;">　　上面这个例子是企业应用中常见的场景，关键问题在于数据记录ID是一个不可控因素，而数据记录的title/name之类的是可控的，为了提高test case的可维护性和相互独立，我们肯定不会依赖ID去模拟页面操作，而是根据title/name之类取回ID信息，再拼装回所需要操作的链接。这种情况下，xpath恐怕也搞不定了。（如果这里再涉及到要在几个iframe之间跳来跳去，恐怕写脚本的人就要崩溃了。）</div><div style="word-break: break-all; margin: 10px 0px;">　　当然，有人会说关键字驱动框架一般也可以定义function来实现类似的操作啊。唉，都到了编写自定义function的地步了，干嘛还非要纠缠在关键字驱动上啊。</div><div style="word-break: break-all; margin: 10px 0px;">　　第二，脚本的可维护性问题。如一开始的例子，传统的关键字驱动是一种纯&#8220;面向过程&#8221;的脚本组织方式（就像C/pascal），表格中填写的是一个操作序列。如果多个test case 都涉及到某个页面，基本上就会在多个case中都看到类似 clickAndWait btnG这样的内容，而一旦页面中btnG改名叫buttonG了，或者 clickAndWait btnG与verifyTextPresent 之间增加了一个 clickAndWait XXX的step，那基本上每个case都需要修改。</div><div style="word-break: break-all; margin: 10px 0px;">　　嗯，问题来了，当你的脚本数量从1增长到100、1000的时候，当UI的变动无法避免的时候，当你发现100个case回归执行只有90个通过，执行失败的10个需要逐个检查错误日志和查看截图，再挨个修改的时候，当下次回归测试又发生这种问题的时候&#8212;&#8212;基本上这就是一个死循环了。如果解决不了根本问题，前期投资可以舍弃了，别纠结了。</div><div style="word-break: break-all; margin: 10px 0px;">　　当然，有人说关键字驱动已经进化了，可以跟最新的webdriver结合起来，提升关键字的封装层次，解决这个可维护性的问题。好吧，这个问题等下再详细说。</div><div style="word-break: break-all; margin: 10px 0px;">　　第三，脚本的可扩展性问题。在大规模实施自动化的过程中，脚本一般都会简单的是一行行的browser.find_elmenet_by_id(xxxx).click() 这样的模式，根据各种条件来判断执行的分支，进行各种异常处理，第三方类库/包的调用，主机环境的访问，诸如此类，这些对于所有的3GL/4GL来说其实都很容易实现，但对于传统的关键字驱动来说，嗯，也可以实现，大概是下面这个样子【摘自robot framework（此robot非rational robot）】：<br /><div style="word-break: break-all; margin: 10px 0px;">　下面是一个在 keyword 表格里面实现的 FOR 循环：</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46924" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_20140714110540580c4.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46925" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407141105406uIog.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46926" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407141105407cakX.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　有人可能会说&#8220;你看，关键字驱动框架也可以扩展的很强大啊！&#8221;。是，在programming 的世界中，没有什么不能做的，不过都弄到这个份儿上了，学习这一套东西跟学习一个标准的编程语言还有什么差别吗？先不说这样的框架越扩展越难维护，可靠性也就越差，单单这些关键字的用途被局限在自己的框架中，你所积累的知识和经验无法重用到其他测试代码的编写中这一个理由，就应该彻底放弃这种方式了。</div><div style="word-break: break-all; margin: 10px 0px;">　　如果要说的直白一些，传统的关键字驱动框架的时代在前几年就已经开始远去（是had been，不是have been），我们感谢上一代tester的努力探索和实践，但最终历史证明这是一个不算成功的尝试，一个框架如果不具备开放性，一切都自给自足，那么有一天这也会成为限制自己发展的最大原因。<br /><div style="word-break: break-all; margin: 10px 0px;">　　（3）穿马甲的&#8220;关键字驱动&#8221;</div><div style="word-break: break-all; margin: 10px 0px;">　　时代在进步，关键字驱动也在进步，这个领域中的代表 robot framework（此robot非rational robot） 也在进步，于是，test case 变成了下面这个样子。</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46927" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407141105408qK5l.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　依旧不变的是&#8220;表格&#8221;，改变的是填写方式&#8212;&#8212;其实这背后的，是关键字定义终于被开放出来，tester可以自己定义keyword然后&#8220;注册&#8221;到框架中，而那些依然没有学会基本编程技能的tester，继续用这些keyword重复上个时代的事情&#8212;&#8212;填写表格。</div><div style="word-break: break-all; margin: 10px 0px;">　　其实相对于最初对关键字驱动的定义，这个真的已经不是关键字驱动了，如果非说它是，那么只能说上个时代的关键字驱动中，test case 表格的每行都是一个页面操作，而&#8220;新的&#8221;关键字驱动中，test case 的每行都已经是一个完整的业务操作，以上面的&#8220;Create Valid User&#8221; step 为例，robot framework希望的实现方式是tester通过python等4GL实现一个同名的function，这个function接受两个参数，分别是&#8220;fred&#8221;和&#8220;P4ssw0rd&#8221;，再把这个function注册到robot framework中。而&#8220;Create Valid User&#8221;内部的实现，可以类似于一开始&#8220;数据驱动&#8221;中的那个例子，充分利用4GL的特性和已有的其他第三方组件（例如webdriver），来实现各种复杂的基于UI的操作，这样也就解决了刚刚&#8220;传统的关键字驱动&#8221;所遇到的问题。</div><div style="word-break: break-all; margin: 10px 0px;">　　最后，当完成了这个function的开发并在robot framework中注册后，做手工测试的system tester就可以很容易的把原本excel中的一个个case转变为自动化脚本了。</div><div style="word-break: break-all; margin: 10px 0px;">　　其实这个思路有它的优点，例如：通过分工协作降低实施门槛，可以一开始就编写符合robot所需格式的manual test case，等到keyword开完全了以后这些case就可以直接导入执行了；不再自给自足，而是保持一定的开放，并利用其他第三方组件的特性。这样很大程度上解决了自动化项目实施遇到的人员能力问题和可维护性、可扩展性的问题。</div><div style="word-break: break-all; margin: 10px 0px;">　　另外，新的关键字驱动还有一个更加先进的&#8220;近亲&#8221;BDD作为参照，很容易把它的一些实践也一起融合进来。</div><div style="word-break: break-all; margin: 10px 0px;">　　一切看起来都很美好，不过问题也还是有。</div><div style="word-break: break-all; margin: 10px 0px;">　　表格化的test case毕竟不同于编写代码，调试就变成了一个问题，如果写错了关键字的一个字母，要及时发现并定位到问题就不那么容易。当然，可以再开发一个web平台，让编写case的人仅能从一个list中选择已经定义好的keyword，不过这个成本恐怕就不是一般研发团队能承受的了。</div><div style="word-break: break-all; margin: 10px 0px;">　　作为一个软件，易用性和复杂度总是成反比的，当框架提供了方便的表格化编写case功能时，也相对的增加了底层的复杂度（虽然没看过robot framework的代码，但是相信底层代码的分层也应该比较复杂），对于想要真的掌握框架的团队来说，无形中增加了一道门槛。另外，复杂度与可扩展性也是成反比的，就像我可以用木头做一辆车，也可以把木头车拆了做些别的东西，但是我没法把一辆汽车拆了弄成别的东西&#8212;&#8212;前两年广东美院那位把解放卡车拆了做成关公像的牛人除外。当然，最终实施自动化时到底如何进行框架选型，就要团队自己在易用性/复杂度/可扩展性上进行评估了。</div><div style="word-break: break-all; margin: 10px 0px;">　　把excel里面的manual test case通过新的关键字驱动直接变成可执行的脚本是最好的方法吗？这似乎只是一个传统system test 的惯性思维在作怪，为什么没看过开发人员把unit test 也写到一个个表格里面？为什么manual test case 就一定要先写在excel里面，而不是一开始就是代码？</div><div style="word-break: break-all; margin: 10px 0px;">　　如果仅仅是考虑把 step组装起来，再把case组织成suite执行，其实代码实现上可以说毫无技术含量，但是对于一个没有开发经验的tester来说，这毕竟是一个跟coding简单亲密接触的机会，可以让tester从低难度的代码开始培养兴趣和信息。而keyword，无论新的还是旧的，却剥夺了这个机会；当tester希望学习框架的时候，会发现表格的层面跟下层框架之间的不是楼梯，而是一道沟。</div><div style="word-break: break-all; margin: 10px 0px;">　<strong style="word-break: break-all; line-height: normal !important;">　3. &#8220;关键字驱动&#8221;的未来</strong></div><div style="word-break: break-all; margin: 10px 0px;">　　我们如今所处的环境总是在变化着，今天与10年前相比，最大的变化就是测试行业获得了极大的发展，大多数企业都认可了测试工作的重要性，并且开始思考如何提升测试工作自身的质量和效率，而且不同规模的企业都在探索着合适自己的研发流程和技术；而tester们的技术能力也在不断增强，至少能写代码的人比5年前多了很多。当然，还要感谢开源世界带来的众多框架、组件，让自动化的门槛不断降低。</div><div style="word-break: break-all; margin: 10px 0px;">　　就像传统的关键字驱动已经远去一样，新的关键字驱动未来会如何，大家讨论吧。:-)</div></div></div></div><img src ="http://www.blogjava.net/qileilove/aggbug/416385.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-31 09:36 <a href="http://www.blogjava.net/qileilove/archive/2014/07/31/416385.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu下搭建Robotframework+Selenium环境</title><link>http://www.blogjava.net/qileilove/archive/2014/07/28/416244.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 28 Jul 2014 02:08:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/28/416244.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/416244.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/28/416244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/416244.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/416244.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">最近已经从<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Windows</strong></u></a>系统转到了Ubuntukylin下面，所以<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>工具也需要重新安装，今天就和大家分享下安装过程。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我使用的环境：Ubuntu Kylin 14.04 64位系统。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　开始了吧,首先还是要安装<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Python</strong></u></a>，这里我用的是Python2.7,这个可以去官网下载，安装过程这里就不再赘述了。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">我采用的是在线安装：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、安装pip，</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sudo apt-get install python-pip</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、安装robotframework，</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sudo pip install robotframework</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3、安装selenium2library，</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sudo pip install robotframework-selenium2library</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　4、安装Wxpython ,</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5、安装ride，</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　sudo pip install robotframework-ride</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　6、打开ride</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在终端里面输入</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　ride.py</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　7、关于RFS的使用，请参考http://blog.csdn.net/xc5683/article/details/10017915</div><img src ="http://www.blogjava.net/qileilove/aggbug/416244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-28 10:08 <a href="http://www.blogjava.net/qileilove/archive/2014/07/28/416244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>初试selenium用python做自动化测试</title><link>http://www.blogjava.net/qileilove/archive/2014/07/21/416030.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Mon, 21 Jul 2014 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/21/416030.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/416030.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/21/416030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/416030.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/416030.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　搭建平台windows</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">准备工具如下：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　-------------------------------------------------------------</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下载<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">python</strong></u></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　http://python.org/getit/</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下载setuptools 【python 的基础包工具】</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　http://pypi.python.org/pypi/setuptools</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下载pip 【python 的安装包管理工具】</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　https://pypi.python.org/pypi/pip</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1、python 的安装，这个不解释，exe 文件运行安装即可，既然你选择python，相信你</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　是熟悉python 的，我安装目录C:\Python27</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2、setuptools 的安装也非常简单，同样是exe 文件，默认会找到python 的安装路径，</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　将安装到C:\Python27\Lib\site-packages 目录下</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3、安装pip ，我默认解压在了C:\pip-1.3.1 目录下</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　4、打开命令提示符（开始---cmd 回车）进入C:\pip-1.3.1目录下输入：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　C:\pip-1.3.1 &gt; python setup.py install</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　（如果提示python 不是内部或外部命令！别急，去配置一下环境变量吧）</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　5、再切换到C:\Python27\Scripts 目录下输入：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　C:\Python27\Scripts &gt; easy_install pip</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　6、安装selenium，（下载地址： https://pypi.python.org/pypi/selenium ）</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　如果是联网状态的话，可以直接在C:\Python27\Scripts 下输入命令安装：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　C:\Python27\Scripts &gt; pip install -U selenium</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　7. 下载解压，你会得到一个chromedriver.exe 文件，把这个文件放到</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　chrome 的安装目录下...\Google\Chrome\Application\ ,然后设置path 环境变量，把</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　chrome 的安装目录（我的：C:\Program Files\Google\Chrome\Application）</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　然后<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">#encoding: utf-8</div><div style="word-break: break-all; margin: 10px 0px;">import os</div><div style="word-break: break-all; margin: 10px 0px;">from selenium import webdriver</div><div style="word-break: break-all; margin: 10px 0px;">from selenium.webdriver.common.keys import Keys</div><div style="word-break: break-all; margin: 10px 0px;">chormedriver = "C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chromedriver.exe"</div><div style="word-break: break-all; margin: 10px 0px;">#打开IE浏览器</div><div style="word-break: break-all; margin: 10px 0px;">#iedriver = "C:\Program Files\Internet Explorer\IEDriverServer.exe"</div><div style="word-break: break-all; margin: 10px 0px;">#os.environ["webdriver.ie.driver"] = iedriver</div><div style="word-break: break-all; margin: 10px 0px;">#打开<a target="_self" style="word-break: break-all; color: #202859;"><u style="word-break: break-all;"><strong style="word-break: break-all;">谷歌</strong></u></a>浏览器</div><div style="word-break: break-all; margin: 10px 0px;">os.environ["webdriver.chrome.driver"]= chormedriver</div><div style="word-break: break-all; margin: 10px 0px;">browser = webdriver.Ie(chormedriver)</div><div style="word-break: break-all; margin: 10px 0px;">browser.maximize_window()</div><div style="word-break: break-all; margin: 10px 0px;">browser.get("http://www.51.la/")</div><div style="word-break: break-all; margin: 10px 0px;">#assert "Python" in driver.title</div><div style="word-break: break-all; margin: 10px 0px;">elem = browser.find_element_by_id("uname") &nbsp;#根据id定位到节点</div><div style="word-break: break-all; margin: 10px 0px;">elem.send_keys("xxxx") &nbsp;#向文本框添加内容</div><div style="word-break: break-all; margin: 10px 0px;">elem = browser.find_element_by_id("upass") &nbsp;#同上</div><div style="word-break: break-all; margin: 10px 0px;">elem.send_keys("xxxxx") &nbsp; #同上</div><div style="word-break: break-all; margin: 10px 0px;">browser.find_element_by_class_name("btlogin").click() &nbsp;#点击提交按钮</div><div style="word-break: break-all; margin: 10px 0px;">browser.find_element_by_link_text("查看统计报表").click()</div><div style="word-break: break-all; margin: 10px 0px;">browser.find_element_by_link_text("访问明细").click()</div><div style="word-break: break-all; margin: 10px 0px;">browser.find_element_by_link_text("下载当前报表").click()</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　方法详见API，重点在节点的定位上，有多种定位方法。</div><img src ="http://www.blogjava.net/qileilove/aggbug/416030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-21 09:43 <a href="http://www.blogjava.net/qileilove/archive/2014/07/21/416030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在Maven中运行TestNG测试</title><link>http://www.blogjava.net/qileilove/archive/2014/07/15/415814.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 15 Jul 2014 02:20:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/15/415814.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/415814.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/15/415814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/415814.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/415814.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">在pom.xml中加入这段代码就可以直接运行<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">TestNG</strong></u></a>的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">&lt;pluginRepositories&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;pluginRepository&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;id&gt;apache.snapshots&lt;/id&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;url&gt;</div><div style="word-break: break-all; margin: 10px 0px;">http://people.apache.org/repo/m2-snapshot-repository/</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/url&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/pluginRepository&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/pluginRepositories&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/dependencies&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;dependency&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;groupId&gt;org.testng&lt;/groupId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;artifactId&gt;testng&lt;/artifactId&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;version&gt;5.5&lt;/version&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;scope&gt;test&lt;/scope&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;classifier&gt;jdk15&lt;/classifier&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/dependency&gt;</div><div style="word-break: break-all; margin: 10px 0px;">&lt;/dependencies&gt;</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　经测试这种方法可以正常运行。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　其他几种方法：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　其他的方法没有测试过，因为现在只是简单的用例还没有涉及太多。以后再试。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　参考这个吧。http://maven.apache.org/plugins/maven-surefire-plugin/testng.html</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; height: 21px; position: relative; width: 627.1875px; background-color: #ffffff;"></div><img src ="http://www.blogjava.net/qileilove/aggbug/415814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-15 10:20 <a href="http://www.blogjava.net/qileilove/archive/2014/07/15/415814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java for Selenium(webdriver) 环境搭建</title><link>http://www.blogjava.net/qileilove/archive/2014/07/15/415811.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 15 Jul 2014 02:16:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/15/415811.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/415811.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/15/415811.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/415811.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/415811.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　开发环境</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1. jdk1.7</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2. Eclipse</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3. selenium(selenium-java-2.42.2.zip)</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　将下载下来的 selenium-java-2.42.2.zip 解压, 解压后文件目录：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46880" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407101106431QQSE.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　建立&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Java</strong></u></a>&nbsp;Project 项目</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　1. 将上面加压出来的文件复制到新建的项目目录下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46881" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407101106432WwI7.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　2. 添加build path，项目目录右键 &gt;&gt; Build Path &gt;&gt; config build path &gt;&gt; Java Build Path &gt;&gt; Libraries &gt;&gt; Add JARs</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　把libs文件夹下的jar包全部添加上，再添加selenium-java-2.42.2和selenium-java-2.42.2-srcs</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46882" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_20140710110643315Uz.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　3、添加完之后目录结构如下图，多了Referenced Libraries,这里就是上面那一步添加进去的jar包</div><img src ="http://www.blogjava.net/qileilove/aggbug/415811.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-15 10:16 <a href="http://www.blogjava.net/qileilove/archive/2014/07/15/415811.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>互联网业务测试团队如果快速构建轻量级的自动化</title><link>http://www.blogjava.net/qileilove/archive/2014/07/10/415676.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Thu, 10 Jul 2014 11:23:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/10/415676.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/415676.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/10/415676.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/415676.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/415676.html</trackback:ping><description><![CDATA[<h1><div style="word-break: break-all; float: left; width: 640px; border: 1px solid #c5d4e5; margin-bottom: 10px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; line-height: normal; background-color: #ffffff;"><div id="articlebody" style="word-break: break-all; width: 627.1875px; margin: 0px auto; overflow: hidden; line-height: 1.8em; font-size: 1em;"><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;"><br /><br /><br />　做<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>，自动化是一个绕不开的主题，而且也是非常值得去做的事情，无论是对测试质量和效率的提升，还是对人的能力的锻炼，都是非常的有帮助。就目前个人观察到的情况，一些负责基础性组件测试的团队，比如底层平台、SDK等，或者是负责功能通用性高的产品，比如防火墙、邮件系统等，都可以做到比较高的自动化率，而且<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>开发的过程通常也没有那么纠结。相比而言，强应用层业务相关的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试团队</strong></u></a>，通常在自动化方面的开展要困难很多。我这里说的是比较全面的功能的自动化，不是指写几个简单的脚步覆盖几个功能，大的思路是接口层面，不涉及UI的，而且可以制作大规模的用例。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;"><strong style="word-break: break-all; line-height: normal !important;">　　主要有几个问题：</strong></div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　1. 首要的问题是版本的节奏，<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">互联网</strong></u></a>的产品版本的节奏非常快，一个20多人的测试团队一周发布上百个功能特性是一件很普通的事情。团队成员有非常多的精力消耗在这些功能版本上，需要快速的理解业务，构建测试环境，bug验证回归，以及发布上线等等，留给业务测试同学构建自动化用例的时间非常少。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　2. 功能非常的庞杂，而且有负责的业务流程，难以标准化。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　3. 说到自动化，大家会想到自动化框架，需要有一个比较好的自动化框架。自己开发或者维护过框架的同学可能都深有体会，这绝不是一件容易的事情，其<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">工作</strong></u></a>量和持续的时间往往会超出我们的预期。我们是否有足够的测试开发人力能做自己的框架，以及业务能否承受这样的等待时间？</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　互联网行业的变化很快，线上功能变化按天算，业务调整和组织架构调整按月看，做一个大的框架如果在部门层面还有可能，到了业务测试团队来说比较奢侈。很多方案是环境和需求逼出来的，细想下来，有两条路，一是看部门的框架，二是有没有轻量级的方案，可以快速的应用。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　这里结合我们自己的一些实践来看看，也是一点浅显的经验。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　部门有一些平台，但是有一些局限，主要是针对HTTP协议，另外对数据的准备支持不太好，也不支持DB的数据检查等功能，另外就是不太方面去定制和扩展，相比而言更适合外网的监控，评估下来准备想想别的办法。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　很多时候，过去的成功经验往往会让我们想复用，所以一开始的时候准备参照在以前公司做过的keyword driven的框架，把功能点封装成一个个的步骤，然后通过配置文件来构造用例，实现自由的组合和数据驱动。这条路验证过，而且看起来对现在的业务来说也没有什么问题，能走通，但是就目前团队的情况来看，开发一个这样的框架的代价无法承受。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　考虑了很久，于是有了现在更轻量点的做法，写出来给那些测试开发资源比较少的业务测试为主的团队参考。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　如果想要快速，但是又功能丰富，最好的办法就是抱一条粗腿，这里我们选的是JMeter。从2.2版本到最近的2.11，一直在关注和使用，发现JMeter的进步很快，版本活跃程度也很高，另外，它早就超出了一个HTTP性能测试工具的范畴，自动化测试其实是它另一个很大的主打，官方文档也提到。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">选中JMeter简单来说有几点：</strong></div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　1. 接口大部分HTTP协议，而JMeter对HTTP支持非常全面，毕竟是做这个出身的。如果有些接口不是呢？我们的做法是用写adapter转换，这里不详述，所以写用例这边还是按HTTP协议走。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　2. 对数据提取和断言非常多的支持。还可以支持直连DB，可能需要补充额外的驱动jar包，但是没有技术障碍。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　3. 可以图形界面，极大的方便了用例制作和调试。以前的经验，我们做了命令行的功能点，后面为了大规模制作用例，还开发过<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>&nbsp;console，现在完全没有必要，这一部分也省掉了。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　4. 可以命令行执行，这就意味着可以方面的被粘合到我们的脚本里面。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　5. 输入和输出都是文本，jmx和存成的csv都是文本，极大的方便了脚本的处理和结果的parse。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　还有更多细节的点不多说了，有了这些基本可行性就很高了。想要独自开发上面这些功能得很大的代价，这也是轻量级能做到的主要原因。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;">　　有了上面这些基本的骨架有了，但是要想想怎么整合成可复用和扩展的用例。</div><div style="word-break: break-all; line-height: 1.8em !important; margin: 10px 0px;"><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><strong style="word-break: break-all;">　　基本的思路如下：</strong></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　1. 用例的分层，为了更好的复用和管理。CGI是最小的粒度，对应一个HTTP请求，完成一个很细节的操作。Function是一个对外有逻辑意义的历史，比如下订单，审核订单。TestCase是一个成品，TestSuite是一个用例的集合。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407011122341Us5m.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　每个子系统的目录组织如下：</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46689" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407011122342N4ZS.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　这里有个小的tricky的地方，为了部署的时候更灵活，希望脚本里面互相引用的文件是相对的路径，但是JMeter支持不太好，默认的根目录是bin，所以简单的做法是把整个自动化用例的目录copy到JMeter的bin下面。<span style="line-height: 1.8em; font-size: 1em;">　2. 因为我们有多个系统，对应多个测试小组，大家各有专注，而我们电商的业务又是一个长链条。function层就是我们复用的基础，里面再包含对CGI层接口的调用。这里有点JMeter的技术细节，2.10开始建议用TestFragment来组织，而TestFragment是不能直接执行的，只是些积木，到了TestCase层面再用ThreadGroup现场组，才可以执行。</span></div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46690" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407011122343ndhW.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　下面是一个完整的TestCase，include了本系统和其他系统的一些function座位步骤。用例细节其实还有很多需要打磨的地方，比如命名规范，执行起来不容易。</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46691" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_2014070111223447c85.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; margin: 10px 0px;">　　3. 自动化的报告，每次执行完了之后自动的发邮件报告出来。</div><div style="word-break: break-all; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46692" target="_blank" style="word-break: break-all; color: #45a2fc; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407011122345my2A.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　为了更好的定位问题，需要把每个接口执行的细节也暴露出来，点击详情可以看到调用的情况，包括request和response的数据。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: center;"><a href="http://www.51testing.com/batch.download.php?aid=46693" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407011122346cl2w.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　<strong style="word-break: break-all; line-height: normal !important;">除了好处，也有一些不方便的地方：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　1. JMeter在include其他的jmx脚本后，不能直接在界面显示加载的内容，所以看不到被include的脚本里面的步骤，调试的时候不方便。不过好在JMeter可以一套binary启多个，并着看。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　2. 最后的结果报告里面，不能控制展示的粒度，是直接摊开成CGI层面的步骤，显得比较杂。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　<strong style="word-break: break-all; line-height: normal !important;">目前我们执行的情况</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　1. 目前覆盖了200多个CGI接口，以及100多个功能点，初步有4个系统挂接到了自动部署后的执行。用例还在进一步的扩展中，框架不需要改动。JMeter本身的稳定性还是不错的。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　2. 整个过程，不算制作用例的时间，我们实际投入的测试开发的人力合起来不到一个人月。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　3. 大部分业务测试同学都参与到了用例的制作，提升了对业务逻辑的理解，并且对部分同学来说，也补了HTTP协议等基础知识的课，实际动手比听听培训效果要好。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　从实际的效果和投入来说还是比较满意的。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　<strong style="word-break: break-all; line-height: normal !important;">　除了技术层面，自动化执行起来有几个核心的要点：</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　1. 一定要强挂钩到测试和发布的环节。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　这一点看起来没那么重要，但是如果不希望自动化成为花瓶，就必须要这样做。像互联网产品这样快的节奏跑起来，任何花哨的环节会逐渐被洗掉，因为人员的配比和版本的数量，不是必做的东西慢慢就坚持不下来。所以自动化如果要能发挥效果，目前来看最合适的点是在每次自动部署后快速的刷一遍，在手工测试开始之前。而且如果要人工去点，这事儿时间长了也不靠谱，一定要把这个过程也自动化，版本在测试环境部署好了之后，自动化自动跑完，这就是强的挂钩。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　2. 报告也是要自动的，并且邮件抄送给相关的开发，测试和团队的负责人。我们现在的做法是跑完了脚本解析后自动的发邮件报告。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　3. 非100%成功的都要跟进。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　宁愿少而精，这个也类似broken window理论，如果能容忍一个用例失败，就会有2个，3个，也会让自动化慢慢失去意义。目前的做法是只要有失败，对应系统的负责同学要邮件reply all跟进原因。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　4. 关注用例的细节</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　团队的负责人要去看用例的质量，而不只是用例的数量和执行情况，比如断言做到什么程度，哪些是写死的哪些参数化了，功能之间的复用情况。其实这个和所有的事情一样，如果真的重要，就应该要跳进去关注细节。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　其实说起来上面没有什么高深的地方，道理也浅显，可能是工作久了会变得更加务实，最怕做了没有用的东西。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　1. 关于技术含量的问题，不纠结。当然，有能力和精力做到技术含量很好。但是没有技术含量但是有价值 &gt; 有技术含量效果不好。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　2. 尽可能的复用好的组件，核心的引擎不一定要自己做，特别是业务测试团队。用开源组件，自己开发特点需求，并把它们粘合起来。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;">　　以上粗略的整理，希望给那些想要做功能自动化，但是又受限于非常快得功能版本节奏，也没有大量测试开发人力的业务测试团队一点参考。</div></a></div></div><br /><br /><br /><br /><br /><div style="word-break: break-all; margin: 10px 0px; height: 21px; position: relative; width: 627.1875px; line-height: 1.8em !important;"><span marginr8"="" style="word-break: break-all; float: left; margin-right: 8px; line-height: normal !important;"><iframe frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?url=http%3A%2F%2Fwww.51testing.com%2Fhtml%2F81%2Fn-863381.html&amp;appkey=&amp;type=5" width="103" height="24" style="word-break: break-all;"></iframe></span><span style="word-break: break-all; float: left; line-height: normal !important;"><a href="http://www.jiathis.com/share/" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; display: block;"><img src="http://www.jiathis.com/code/images/jiathis2.gif" width="125" height="21" border="0" id="jiathis_a" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></span><span style="word-break: break-all; text-align: right; height: 28px; line-height: normal !important; float: right; position: relative; background: url(http://www.51testing.com/images/dotline_h.gif) 50% 0% repeat-x;"><div style="word-break: break-all; float: right; margin: 10px 0px;"><span style="word-break: break-all; float: left; margin-right: 0px; padding: 0px 5px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: solid none solid solid; border-top-color: #cee3ea; border-bottom-color: #90aab4; border-left-color: #cee3ea; color: #009900; background: #f5fbff;">3</span><span style="word-break: break-all; float: left; margin-right: 3px; padding: 0px 5px; border-width: 1px; border-style: solid; border-color: #cee3ea #90aab4 #90aab4 #cee3ea; color: #009900; background: #f5fbff;">1/3</span><span style="word-break: break-all; float: left; margin-right: 3px; padding: 0px 5px; border-width: 1px; border-style: solid; border-color: #00aa00 #006600 #006600 #00aa00; color: #ffffff; font-weight: bold; background: #ff9900;">1</span><a href="http://www.51testing.com/?action-viewnews-itemid-863381-page-2" style="word-break: break-all; color: #202859; text-decoration: none; float: left; display: inline; margin-right: 3px; padding: 0px 5px; border-width: 1px; border-style: solid; border-color: #cee3ea #90aab4 #90aab4 #cee3ea; background: #f5fbff;">2</a><a href="http://www.51testing.com/?action-viewnews-itemid-863381-page-3" style="word-break: break-all; color: #202859; text-decoration: none; float: left; display: inline; margin-right: 3px; padding: 0px 5px; border-width: 1px; border-style: solid; border-color: #cee3ea #90aab4 #90aab4 #cee3ea; background: #f5fbff;">3</a><a href="http://www.51testing.com/?action-viewnews-itemid-863381-page-2" style="word-break: break-all; color: #202859; text-decoration: none; float: left; display: inline; margin-right: 3px; padding: 0px 5px; border-width: 1px; border-style: solid; border-color: #cee3ea #90aab4 #90aab4 #cee3ea; background: #f5fbff;">&gt;</a><div><br /><br /><br /><br /><br /><br /></div></div></span></div></div></div></h1><img src ="http://www.blogjava.net/qileilove/aggbug/415676.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-10 19:23 <a href="http://www.blogjava.net/qileilove/archive/2014/07/10/415676.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用Selenium WebDriver+Grid2实现浏览器端性能测试</title><link>http://www.blogjava.net/qileilove/archive/2014/07/09/415627.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Wed, 09 Jul 2014 07:59:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/09/415627.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/415627.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/09/415627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/415627.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/415627.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">在&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Web</strong></u></a>&nbsp;2.0 应用中，页面装载时间和浏览器渲染时间将成为决定性能的关键因素。我们在<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>过程中不仅需要手动触发<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">性能测试</strong></u></a>工具，而且需要模仿不同的用户行为，包括不同的浏览器、不同的网络条件和不同的使用习惯。在这种情况下我们需要新的方法与工具来覆盖特别是浏览器端的性能测试。用&nbsp;<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;WebDriver + Grid2 可以解决浏览器端性能测试中的自动化和并发性问题。本文介绍了这种新的测试框架和脚本的开发过程，并结合案例给出了具体的代码和结果分析。使用 Selenium WebDriver+Grid2 可以将已有的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">自动化测试</strong></u></a>资源为性能测试服务，将测试人员从繁杂的手动测试中解放出来，专注于结果分析和问题解决。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我们需要新的方法与工具来覆盖浏览器端的性能测试</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在浏览器端的性能测试中遇到的一些问题</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　在传统的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">互联网</strong></u></a>应用中，由于浏览器端的时间消耗比较有限，并且页面装载时间也比较简单且有限，所以在对传统互联网应用的响应时间分析中，我们通常忽略页面装载时间和浏览器渲染时间，而着重分析服务器响应时间。而在 Web 2.0 应用中，页面装载时间和浏览器渲染时间将成为决定性能的关键因素，所以我们需要新的方法与工具来覆盖特别是客户端的性能：浏览器响应时间。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我们使用一些工具来帮助我们测试浏览器端的性能；比如说 DummyNet 可以模拟不同网络带宽和延迟，以便我们分析不同网络情况下的的网页性能；HttpWatch 可以分别记录每个请求的服务器端响应时间、页面装载时间、浏览器渲染时间；DynaTrace AJAX 是一种详细的底层工具，它不仅可以显示所有请求和文件在网络中的传输时间，还会记录浏览器 render、CPU 消耗、JavaScript 解析和运行的详细情况。我们使用这些工具的时候大多是手动触发，为了得到数据和分析报告，必须将用户案例在不同的浏览器上手动实现，并且在某一时刻打开或关闭工具和保存结果。过多的手动操作使我们很难专注于数据分析和发现问题。所以我们需要解决以下问题：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　需要有工具在模仿用户使用 web 应用程序的同时自动触发这些工具，生成分析数据。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　可以同时模仿不同的用户行为，包括不同的浏览器，网络条件和使用习惯。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　下面的章节将介绍如何利用自动化工具 Selenium 来搭建测试网页浏览器端性能的测试框架，实现浏览器端自动测试和并行测试。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">浏览器端性能测试框架中用到的技术</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　我们的测试框架主要采用了以下技术：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">Selenium WebDriver</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium 是针对 Web 应用的测试框架，支持多种浏览器和多种编程语。WebDriver 通过原生浏览器支持或者浏览器扩展直接控制浏览器。它提供了一个更为简单，一致的编程接口并且解决了在 Selenium-RC API 遇到的问题。Selenium WebDriver 更好的支持了动态网页。它的目标是为现代的网页程序测试提供设计良好的面向对象的 API。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">Selenium Grid2</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　Selenium Grid 允许用户将测试案例分布在几台机器上并行执行。用户可以在一个集中控制点控制不同的环境。在不同的浏览器 / 系统组合上面更为容易的运行测试案例。允许用户更多的利用虚拟资源减少了维护测试环境的成本。Selenium Grid2 很好的支持了 WebDriver。利用原有的 WebDriver 脚本和 Grid 技术就可以将不同的<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试用例</strong></u></a>分布在不同的机器或虚机上，在特定的浏览器版本上运行，自动地启动关闭分析工具，统一地保存测试结果。Selenium Grid2 的机制如图 1，启动一个中央节点（Hub），然后启动多个远程控制节点（rc），启动 rc 时告知 Hub 的位置，这样这些 rc 就可以注册到 Hub 上，测试程序与 Hub 通讯，当测试被并发地发给 Hub 时，Hub 会自动将这些测试命令分发给已经注册的 rc，rc 接到命令后执行测试。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　<strong style="word-break: break-all; line-height: normal !important;">TestNG</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　本测试系统还使用 TestNG 工具来辅助配置自动测试。TestNG 是测试 Java 应用程序的框架之一。TestNG 以其灵活性和参数化成为定义 Selenium 的驱动验收测试的首选。它通过一些语义注释来传递测试的参数，定义测试脚本的顺序并配置运行时的性能。用户可以通过配置来生成各式测试报告，十分方便。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;">　　图 1. Selenium Grid2 的机制</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; text-align: center; background-color: #ffffff;"><a href="http://www.51testing.com/batch.download.php?aid=46849" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023481uLWX.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　<strong style="word-break: break-all; line-height: normal !important;">Ant</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　在框架中我们使用 Ant 来构建版本 , 然后部署到测试环境中去 , 再然后执行测试脚本到生成发送测试报告 .</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　<strong style="word-break: break-all; line-height: normal !important;">浏览器端性能测试框架的实现</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　<strong style="word-break: break-all; line-height: normal !important;">Selenium WebDriver 编写测试脚本</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　利用 Selenium WebDriver 为动作执行和页面跳转进行设计。Selenium WebDriver 可以模拟用户上网的行为，添加计时代码用以测算用户某个动作执行的时间或是页面跳转需要的时间。以用户登录为例，在输入用户名和密码之后开始用 startTrans 函数开始计时，在点击提交按钮页面跳转之后用 endTrans 函数结束计时。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;">　　清单 1. 在 Selenium 中添加计时代码</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333;"><a href="http://www.51testing.com/batch.download.php?aid=46850" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023482FFCm.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; text-align: left;"><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　利用 DummyNet 模拟不同网络条件下用户的案例执行。带宽模拟与控制是性能测试的一个常规需求。很多时候我们必须能够提供可变的带宽、上行和下行速率，从而获得这些条件下性能的表现。开源工具 DummyNet 是一款优秀的网络控制工具，它通过重载本机的网卡驱动，提供给开放人员命令行接口去模拟带宽可变利用。调用 DummyNet 的命令后执行 Selenium 脚本可以设置网络带宽和延迟。以下命令限制从源地址到目的地址的流量带宽 2Mb, 延迟 300ms。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　ipfw add pipe 2 ip from %sourceip% &nbsp;to %targetip% out proto ip</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　ipfw pipe 2 config delay 300ms bw 2Mbit/s</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　利用 HttpWatch 和 DynaTrace AJAX 为特定的页面请求记录时间。HttpWatch 和 DynaTrace AJAX 是两款强大的网页数据分析工具。它们通常集成在浏览器的工具栏。以往我们通过手动打开这些工具在浏览页面的同时收集所需的分析数据。在新的框架中 Selenium 脚本可以调用它们的接口驱动浏览器从会话中启动分析工具并收集保存性能信息。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　<strong style="word-break: break-all;">清单 2. Selenium 脚本调用 DynaTrace AJAX 接口</strong></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px; text-align: center;"><a href="http://www.51testing.com/batch.download.php?aid=46851" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023483EXfO.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;"><strong style="word-break: break-all;">　　Selenium Grid2 集中控制测试环境</strong></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　步骤一：启动中央节点（Hub）。Hub 会接收测试请求并将它们分布在正确的节点上。启动 Hub 的默认端口为 4444，也可以通过参数指定端口。打开地址：http://localhost:4444/grid/console，通过页面可以观察 Hub 的状态。启动命令如下 :</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　java -jar selenium-server-standalone-2.14.0.jar -role hub</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　步骤二：配置和启动远程控制节点（rc）。远程节点是您需要测试的测试机所在的物理机或虚拟机。启动节点时需要传入 Hub 的 IP 地址和端口号。默认情况下，节点的端口为 5555，每个节点可以启动 11 个浏览器，包括 5 个 firefox、5 个 chrome 和 1 个 ie 浏览器。最多有 5 个并行的测试案例。用户也可以通过参数指定端口和浏览器，以下命令将会启动 Linux 远程节点上的三个 firefox 浏览器进行并行测试，它们指向在另一台机器的 Hub 节点。</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　java -jar selenium-server-standalone-2.14.0.jar -role node \</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　-hub http://remotehost:4444/grid/register \</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　-browser browserName=firefox,version=3.6,maxInstances=3,\</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　platform=LINUX</div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　<strong style="word-break: break-all;">Selenium WebDriver 和 Grid2 并发执行测试用例</strong></div><div style="word-break: break-all; line-height: normal !important; margin: 10px 0px;">　　TestNG 可以很方便的加载在已经开发好的 Selenium WebDriver 测试案例，测试用例中的参数通过 @Parameters 传递。在测试中我们需要将同一个测试案例发送到不同的节点或是浏览器上执行。所以我们从已有的 Selenium 脚本中选出案例后用 @Test 标注并加入节点的 IP、端口和浏览器类型参数。<br /><br /><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;"><strong style="word-break: break-all; line-height: normal !important;">　清单 3. 将 TestNG 加载在已有的 Selenium 测试脚本</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　@Test</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　@Parameters({"seleniumHost", "seleniumPort", "bs"})</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　public void sitenav(String Host,String Port,String browser)</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　TestNG 要求将所有要运行的测试用例都记录在一个叫 testng.xml 的文件中，然后根据该文件中的测试用例顺序依次执行测试。通过 suit 标签的属性可以指定 method、tests 或是 classes 的并发执行。我们在 testng.xml 中将测试的并行粒度设为 Test, 用参数传入不同的 IP 地址、端口号、浏览器名称，形成不同的测试案例，以便在不同节点上的不同浏览器中并行执行。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">清单 4. testng.xml 中有关并行测试案例的配置</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46852" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023484R4g7.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　最后用 Ant 从命令行运行 TestNG 类。用户通过命令行启动 Ant，读取目标文件 build.xml 来获得项目的参数，例如目标定义、类路径、引入的文件等。Ant 通过读取 TestNG 的配置文件 testng.xml 来获取参数，将 Java 代码编译成 TestNG 类，并且根据配置文件中传入的参数和顺序来执行这些类。以下是在 Ant 的 build.xml 里面如何正确配置 TestNG。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">清单 5. Build.xml 里配置 TestNG</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46853" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023485kkrs.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">应用示例</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　IBM Connections 3 是 IBM 专门为满足企业业务需求而设计的一款社交软件。我们用它作为目标程序来测试其浏览器端的性能。用 Selenium WebDriver 编写脚本模拟用户依次浏览主页、登陆、个人资料、博客等主要页面。我们将同样的脚本在不同网络环境、不同操作系统、不同浏览器中并行执行，并且记录页面的响应时间，完整下载时间，对不同浏览器，不同网络条件下的页面响应时间加以比较。测试过程如下：</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　选取几台测试机作为测试节点，测试机器上具有我们所需要的操作系统、浏览器类型、测试分析工具，选取一台测试机作为 Hub。配置和启动 Hub 和测试节点。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　准备不同类型的测试案例 Test1.....TestN。根据操作系统、浏览器和所需的测试工具，在 testng.xml 中将测试脚本分配给相对应的测试节点 Node1.......NodeN 形成不同的测试案例。图 2 是测试节点配置和测试案例的分布图。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　编辑 build.xml 文件。执行 ant 命令。通过网页观察 Hub 的状态和测试节点的执行情况。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　测试执行完，从各节点和 Hub 上收集测试数据加以整理和分析。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　测试数据从几个方面获得。有关测试环境的数据将会直接从配置文件获取，简单的页面响应时间会由 Selenium 脚本获取。浏览器响应时间分解和网页分析数据将会由 HTTPWACTH 等辅助测试工具获得。图 3 是由部分测试数据经过汇总整理后形成的表格。从表格中可以看到同一个页面请求在不同配置的测试机上的响应时间，如果该机器加载了性能分析工具，还可以通过抓取 HTTPWACTH 分析结果进一步得到响应时间分解。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;"><a href="http://www.51testing.com/batch.download.php?aid=46854" target="_blank" style="word-break: break-all; color: #202859; text-decoration: none; line-height: normal !important;"><img src="http://www.51testing.com/attachments/2014/07/14982672_201407091023486tvzS.jpg" border="0" style="word-break: break-all; list-style: none outside none; margin: 0px; padding: 0px; border: none; max-width: 500px;"  alt="" /></a></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　<strong style="word-break: break-all; line-height: normal !important;">小结</strong></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px;">　　利用 Selenium WebDriver 和 Grid2 可以将已有的自动化测试脚本为性能测试服务，并发、自动地执行测试案例节省了时间和人力，使测试人员能够将精力集中在数据分析和性能调优上。灵活的配置测试环境，包括网络环境、操作系统和浏览器类型，可以在短时间内得出不同情况下目标程序的客户端性能数据，方便比较和发现问题。</div></div></div></a></div><img src ="http://www.blogjava.net/qileilove/aggbug/415627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-09 15:59 <a href="http://www.blogjava.net/qileilove/archive/2014/07/09/415627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用WebDriver过程中遇到的那些问题</title><link>http://www.blogjava.net/qileilove/archive/2014/07/08/415589.html</link><dc:creator>顺其自然EVO</dc:creator><author>顺其自然EVO</author><pubDate>Tue, 08 Jul 2014 06:00:00 GMT</pubDate><guid>http://www.blogjava.net/qileilove/archive/2014/07/08/415589.html</guid><wfw:comment>http://www.blogjava.net/qileilove/comments/415589.html</wfw:comment><comments>http://www.blogjava.net/qileilove/archive/2014/07/08/415589.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qileilove/comments/commentRss/415589.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qileilove/services/trackbacks/415589.html</trackback:ping><description><![CDATA[<div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　在做<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">web</strong></u></a>项目的自动化端到端<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">测试</strong></u></a>时主要使用的是<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Selenium</strong></u></a>&nbsp;WebDriver来驱动浏览器。Selenium WebDriver的优点是支持的语言多，支持的浏览器多。主流的浏览器Chrome、Firefox、IE等都支持，<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">手机</strong></u></a>上的浏览器<a target="_self" style="word-break: break-all; color: #202859; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">Android</strong></u></a>、IPhone等也支持，甚至还支持PhantomJS（由于PhantomJS跑测试时并不需要渲染元素，所以执行速度快）。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　但是我在使用Selenium WebDriver时，遇到了很多坑。这些问题，有的是因为Selenium WebDriver与浏览器不同版本之间兼容性的问题，有的是Selenium WebDriver本身的bug，当然也不乏自己对Selenium WebDriver某些功能理解不透彻。我花时间总结了一下，分享给大家，希望大家以后遇到问题可以避过这些坑，少走弯路。另外也总结了一些使用WebDriver的比较好的实践，也一并分享给大家。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　WebDriver每次启动一个Firefox的实例时，会生成一个匿名的profile，并不会使用当前Firefox的profile。这点一定要注意。比如如果访问被测试的web服务需要通过代理，你想直接设置Firefox的代理是行不通的，因为WebDriver启动的Firefox实例并不会使用你这个profile，正确的做法是通过FirefoxProfile来设置。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">public WebDriver create() {</div><div style="word-break: break-all; margin: 10px 0px;">FirefoxProfile firefoxProfile = new FirefoxProfile();</div><div style="word-break: break-all; margin: 10px 0px;">firefoxProfile.setPreference("network.proxy.type",1);</div><div style="word-break: break-all; margin: 10px 0px;">firefoxProfile.setPreference("network.proxy.http",yourProxy);</div><div style="word-break: break-all; margin: 10px 0px;">firefoxProfile.setPreference("network.proxy.http_port",yourPort);</div><div style="word-break: break-all; margin: 10px 0px;">firefoxProfile.setPreference("network.proxy.no_proxies_on","");</div><div style="word-break: break-all; margin: 10px 0px;">return new FirefoxDriver(firefoxProfile);</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　通过FirefoProfile也可以设置Firefox其它各种配置。如果要默认给Firefox安装插件的话，可以将插件放置到Firefox安装目录下的默认的plugin文件夹中，这样即使是使用一个全新的profile也可以应用此plugin。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　使用WebDriver点击界面上Button元素时，如果当前Button元素被界面上其他元素遮住了，或没出现在界面中（比如Button在页面底部，但是屏幕只能显示页面上半部分），使用默认的WebElement.Click()可能会触发不了Click事件。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　修正方案是找到该页面元素后直接发送一条Click的JavaScript指令。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　((JavascriptExecutor)webDriver).executeScript("arguments[0].click();", webElement);</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">　　当进行了一些操作发生页面跳转时，最好加一个Wait方法等待page load完成再进行后续操作。方法是在某个时间段内判断document.readyState是不是complete。</div><div style="word-break: break-all; line-height: 21.600000381469727px; margin: 10px 0px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">protected Function&lt;WebDriver, Boolean&gt; isPageLoaded() {</div><div style="word-break: break-all; margin: 10px 0px;">return new Function&lt;WebDriver, Boolean&gt;() {</div><div style="word-break: break-all; margin: 10px 0px;">@Override</div><div style="word-break: break-all; margin: 10px 0px;">public Boolean apply(WebDriver driver) {</div><div style="word-break: break-all; margin: 10px 0px;">return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">};</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">public void waitForPageLoad() {</div><div style="word-break: break-all; margin: 10px 0px;">WebDriverWait wait = new WebDriverWait(webDriver, 30);</div><div style="word-break: break-all; margin: 10px 0px;">wait.until(isPageLoaded());</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table><div style="word-break: break-all; margin: 10px 0px;">如果页面有Ajax操作，需要写一个Wait方法等待Ajax操作完成。方式与上一条中的基本相同。比如一个Ajax操作是用于向DropDownList中填充数据，则写一个方法判断该DropDownList中元素是否多余0个。</div><div style="word-break: break-all; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">private Function&lt;WebDriver, Boolean&gt; haveMoreThanOneOption(final By element) {</div><div style="word-break: break-all; margin: 10px 0px;">return new Function&lt;WebDriver, Boolean&gt;() {</div><div style="word-break: break-all; margin: 10px 0px;">@Override</div><div style="word-break: break-all; margin: 10px 0px;">public Boolean apply(WebDriver driver) {</div><div style="word-break: break-all; margin: 10px 0px;">WebElement webElement = driver.findElement(element);</div><div style="word-break: break-all; margin: 10px 0px;">if (webElement == null) {</div><div style="word-break: break-all; margin: 10px 0px;">return false;</div><div style="word-break: break-all; margin: 10px 0px;">} else {</div><div style="word-break: break-all; margin: 10px 0px;">int size = webElement.findElements(By.tagName("option")).size();</div><div style="word-break: break-all; margin: 10px 0px;">return size &gt;= 1;</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">};</div><div style="word-break: break-all; margin: 10px 0px;">}</div><div style="word-break: break-all; margin: 10px 0px;">public void waitForDropDownListLoaded() {</div><div style="word-break: break-all; margin: 10px 0px;">WebDriverWait wait = new WebDriverWait(webDriver, 30);</div><div style="word-break: break-all; margin: 10px 0px;">wait.until(isPageLoaded());</div><div style="word-break: break-all; margin: 10px 0px;">}</div></td></tr></tbody></table></div><div style="word-break: break-all; margin: 10px 0px;">　　以此类推，我们可以判断某个元素是否呈现、某个class是否append成功等一系列方法来判断ajax是否执行完成。</div><div style="word-break: break-all; margin: 10px 0px;">　　如果网站使用了JQuery的动画效果，我们在运行测试的时候其实可以disable JQuery的animation，一方面可以加快测试的速度，另一方面可以加强测试的稳定性（如果启用了Animation，使用WebDriver驱动浏览器时可能会出现一些无法预料的异常）。</div><div style="word-break: break-all; margin: 10px 0px;">　　((JavascriptExecutor)driver).executeScript("jQuery.fx.off=true");</div><div style="word-break: break-all; margin: 10px 0px;">　　由于WebDriver要驱动浏览器，所以测试运行的时间比较长，我们可以并行跑测试以节省时间。如果你使用的是maven构建工具，可以配置surefire plugin时，在configruation节点加入以下配置。</div><div style="word-break: break-all; margin: 10px 0px;">　　&lt;parallel&gt;classes&lt;/parallel&gt;</div><div style="word-break: break-all; margin: 10px 0px;">　　&lt;threadCount&gt;3&lt;/threadCount&gt;</div><div style="word-break: break-all; margin: 10px 0px;">　　&lt;perCoreThreadCount&gt;false&lt;/perCoreThreadCount&gt;</div><div style="word-break: break-all; margin: 10px 0px;">　　当测试fail的时候，如果当前使用的WebDriver实现了TakesScreenshot接口，我们就可以调用相应的方法截下当前浏览器呈现的web页面，这样有利于快速定位出错的原因。</div><div style="word-break: break-all; margin: 10px 0px;"><table align="center" style="word-break: break-all; border-style: solid; border-color: #999999; width: 612px; font-size: 12px; background-color: #dddddd;"><tbody style="word-break: break-all;"><tr style="word-break: break-all;"><td style="word-break: break-all;"><div style="word-break: break-all; margin: 10px 0px;">　　public void getScreenShot() {</div><div style="word-break: break-all; margin: 10px 0px;">　　if (webDriver instanceof TakesScreenshot) {</div><div style="word-break: break-all; margin: 10px 0px;">　　TakesScreenshot screenshotTaker = (TakesScreenshot) webDriver;</div><div style="word-break: break-all; margin: 10px 0px;">　　File file = screenshotTaker.getScreenshotAs(savePath);</div><div style="word-break: break-all; margin: 10px 0px;">　　}</div><div style="word-break: break-all; margin: 10px 0px;">　　}</div></td></tr></tbody></table></div><div style="word-break: break-all; margin: 10px 0px;">　　如果页面弹出了浏览器自带的警告框（使用JavaScript的Alert方法），Selenium WebDriver在点选次警告框时会偶发性失败。具体原因还未查明。解决方案是尽量不使用Alert方法的警告框，而是自己实现模式窗口（比如Jquery UI的模式窗口）来实现警告框效果。这样即保证了测试的稳定性，另外我们自己可以控制警告框的样式，给用户带来更好的体验。</div><div style="word-break: break-all; margin: 10px 0px;">　　经常更新Selenium的版本。注意经常上Selenium的官网看是否发布了新的版本，新的版本都修复了那些bug，如果包含你遇到的bug，就可以升级到目前的版本。</div></div><img src ="http://www.blogjava.net/qileilove/aggbug/415589.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qileilove/" target="_blank">顺其自然EVO</a> 2014-07-08 14:00 <a href="http://www.blogjava.net/qileilove/archive/2014/07/08/415589.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>