﻿<?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操作、Pro