随笔分类 -  Watir

Web automation in Ruby
摘要:Watir使用过程中,经常遇到的弹出框分为几类:1. Alert2. Confirm3. Prompt4. File selectWatir 处理弹出框,有很多方法,可以应用 AutoIt来处理,也可以通过 RAutomation来处理。AutoIt的局限性是无法跨平台,所以在Watir 4.0中被... 阅读全文
posted @ 2014-04-17 16:50 chenpassion 阅读(785) 评论(0) 推荐(0)
摘要:RAutomation的用法require "rautomation"# 通过匹配部分标题来获取窗口window = RAutomation::Window.new(:title => /part of the title/i)window.exists? # => truewindow.title... 阅读全文
posted @ 2014-03-13 17:49 chenpassion 阅读(542) 评论(0) 推荐(0)
摘要:公司的官方主页要优化搜索任务,一共有110个独立页面,开发工程师做了以下工作:1. 为所有这些页面的每个图片添加了alt;2. 为页面上的每个标题添加了面包屑;3. 为网站最重要的标题设置H1标签,而且是唯一的;4. 对Title,Meta进行了优化,任何一个页面,都有独特的Title和Meta;现在需要我来测试效果,看一切是否按照计划进行,如果依靠手动测试,以上4个任务的任何一个,都可能要耗费我一天时间。而如果使用Watir,半天就可以完成所有的测试并且立刻就能让开发修复存在的bug。Watir的测试代码是如此简单,以至于即使一个入门级的Watir使用者,都可以完全掌握。require &# 阅读全文
posted @ 2013-09-27 17:50 chenpassion 阅读(529) 评论(0) 推荐(0)
摘要:require 'win32ole'ai = WIN32OLE.new("AutoItX3.Control")ai.RunWait("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255") 阅读全文
posted @ 2013-08-16 17:02 chenpassion 阅读(384) 评论(0) 推荐(0)
摘要:假设我书写了很多测试用例,测试用例中都有:require 'test/unit'后来我想把很多这样的测试用例组织在一起运行,我使用了两个require:require 'test/unit'require 'test/unit/ui/console/testrunner'于是我运行如下用例集合:include Test::Unit::UI::Console testcases = [TC_AddPeople] testcases.each{|testcase| TestRunner.run(testcase)}我得到的错误提示如下:Loaded 阅读全文
posted @ 2013-08-16 17:01 chenpassion 阅读(313) 评论(0) 推荐(0)
摘要:Similar Threads1. WIN32OLE - failed to create WIN32OLE2. WIN32OLE#[] and WIN32OLE#[]= method in Ruby 1.9 (or later)For example, excel = WIN32OLE.excel("Excel.Application") excel["Visible"] = trueis NG.Instead, You must write excel = WIN32OLE.excel("Excel.Application") e 阅读全文
posted @ 2013-08-16 16:57 chenpassion 阅读(391) 评论(0) 推荐(0)
摘要:如果安装了搜狗,Watir::Browser.new并不一定能打开新的IE浏览器。这种情况下,必须卸载搜狗浏览器,当然,attach,find方法还是可以用的 阅读全文
posted @ 2013-08-16 16:55 chenpassion 阅读(198) 评论(0) 推荐(0)
摘要:Watir-WebDriver对于已经打开的浏览器,没有办法进行Attach操作。但是对于自动化操作浏览器过程中点击某链接,打开的新浏览器,是能够定位到的。require 'watir-webdriver'def attach_browser(browser, how, url) browser.driver.switch_to.window(browser.driver.window_handles[0]) browser.window(how, /#{url}/).useendie2 = Watir::Browser.new :chromeie2.goto("ht 阅读全文
posted @ 2013-08-16 16:53 chenpassion 阅读(648) 评论(0) 推荐(0)
摘要:#Suppose we will access an SVN netrequire 'watir-webdriver'b = Watir::Browser.new :chromeb.goto 'https://admin:password@yourwebsite.com'#Firefox Deal with Certification:profile = Selenium::WebDriver::Firefox::Profile.new profile.assume_untrusted_certificate_issuer = falseb = Watir::B 阅读全文
posted @ 2013-08-16 16:51 chenpassion 阅读(274) 评论(0) 推荐(0)
摘要:Watir对富文本编辑,一般可以采用b.frame().document.body.innerText = "Value you want to insert"但是Watir-WebDriver不支持这种方法。不过有两种方法可以通过Watir-WebDriver向所见即所得编辑器(应该指的是富文本编辑器)中输入文字:定位编辑器所在的iFrame,然后使用.send_keys方法(缺点是浏览器必须在前台运行)在浏览器上执行javascript,通过js脚本去设置编辑器的值。#CKEditorrequire 'watir-webdriver'b = Watir: 阅读全文
posted @ 2013-08-16 16:50 chenpassion 阅读(439) 评论(0) 推荐(0)
摘要:以下代码支持Firefox,IE,Chromerequire 'watir-webdriver'#require "watir-webdriver/extensions/alerts"b = Watir::Browser.new :chromeb.goto("http://192.168.10.110:ab/PersonInfo.aspx")b.text_field(:id, "txtName").set("w3")b.text_field(:id, "txtPwd").set( 阅读全文
posted @ 2013-08-16 16:49 chenpassion 阅读(372) 评论(0) 推荐(0)
摘要:特别声明:该报表框架不是我搭建的。 阅读全文
posted @ 2013-08-16 16:47 chenpassion 阅读(172) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2013-08-16 16:46 chenpassion 阅读(178) 评论(0) 推荐(0)
摘要:我在群空间,总是看到很多Watir新手,反复的问:我对元素的定位怎么又出错?我该从哪里着手啊?我给一个我认为最简单方便的学习方法。1. Ruby语法基础要入门,网上有一个不到2M的帮助文档,从头到尾仔细瞅瞅,每个语句自己手动执行一下,Ruby就能入门了;2. 进入安装好的Ruby,Watir的目录:D:\Ruby193\lib\ruby\gems\1.9.1\gems\watir-classic-3.0.0,把该文件夹导出到eclipse或者Netbeans项目中,就这些Example一个个执行下去,之后基本上就是Watir入门了。 阅读全文
posted @ 2013-08-16 16:42 chenpassion 阅读(213) 评论(0) 推荐(0)
摘要:以下是一个很经典的把Watir与AutoIt连接在一起的实例。如果我们对AutoIT了解的更多,处理类似的问题会更加简单。以下实例会判断页面上是否有某“删除”链接,一旦有该链接,就点击,然后点击弹出的警告框上的“确定”按钮,直到页面上不再有“删除”链接为止。require 'watir'require 'win32ole'class WindowHelper def initialize( ) @autoit = WIN32OLE.new('AutoItX3.Control') end def push_alert_button() @autoi 阅读全文
posted @ 2013-08-16 16:41 chenpassion 阅读(533) 评论(0) 推荐(0)
摘要:对于Ruby 1.8版本,以管理员身份运行命令行窗口,输入Regsvr32 AutoItX3.dll路径即可。对于1.9 版本,路径与1.8版本是不同的,我们可以进入Ruby安装目录下,搜索AutoItX3.dll,搜索到之后,找到相应路径,然后以管理员身份运行命令行窗口,输入:regsvr32 D:\Ruby193\lib\ruby\gems\1.9.1\gems\rautomation-0.7.2\ext\AutoItX\AutoItX3.dll回车即可。 阅读全文
posted @ 2013-08-16 16:38 chenpassion 阅读(624) 评论(0) 推荐(0)
摘要:为了提高自己的工作效率,我曾经对Watir进行了系统性的学习,比起学习C++,Java等始终不得门,Watir还是学进去了,能够完整搭建出一个自己很容易理解的自动化架构。之后我想继续在自动化测试方明提高自己,就把Ruby语言从头到尾走了一遍,还是有些收获的,虽然现在脑海里面也记不起来多少东西,但是就自动化测试这一方面来说,还是很有自信的。Watir,Ruby能够很大程度上提高测试效率,这点是毋庸置疑的,印象深刻的是,以下场景下,Watir和Ruby帮了我的忙。场景1:重现一些难以重现的Bug公司产品有一个功能,用户可以在google地图上画一条路线,然后可以在这条路线上跑步健身,从而进行一些统 阅读全文
posted @ 2013-08-16 16:36 chenpassion 阅读(358) 评论(0) 推荐(0)
摘要:b =Watir::IE.newb.goto'http://www.google.com/'txt =b.element_by_xpath("//*[@name='q']")txt.value= 'Richard Lawrence'btn =b.element_by_xpath("//*[@name='btnG']")btn.click@b.elements_by_xpath("//div[@class='UserServiceValues']").eac 阅读全文
posted @ 2013-08-16 16:32 chenpassion 阅读(472) 评论(0) 推荐(0)
摘要:def save_file(filepath) ai =WIN32OLE.new("AutoItX3.Control") ai.WinWait("FileDownload", "", 2) ai.ControlFocus("FileDownload", "", "&Save") sleep 1 ai.ControlClick("FileDownload", "", "&Save", "lef 阅读全文
posted @ 2013-08-16 16:27 chenpassion 阅读(294) 评论(0) 推荐(0)
摘要:require 'watir'module Watir class Element def top_edge assert_exists assert_enabled ole_object.getBoundingClientRect.top.to_i end def top_edge_absolute top_edge + page_container.document.parentWindow.screenTop.to_i end def left... 阅读全文
posted @ 2013-08-16 16:26 chenpassion 阅读(551) 评论(0) 推荐(0)