`
lilingjay
  • 浏览: 8392 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Is there an alternative to watir::ie.attach for watir-webdriver since attach is

 
阅读更多

原文链接 http://stackoverflow.com/questions/5796059/is-there-an-alternative-to-watirie-attach-for-watir-webdriver-since-attach-is

Question:

I have a website which is only rendered in Webkit enabled browser (Google Chrome, Safari). I am using Google Chrome since I am on Windows 7.

I am using Watir-WebDriver to automate the same.

Issue: When I click on a button on the browser window, is launches another window and post click content is rendered in the new browser window. I need a way to be able to Identify this new browser window, in-order to be able to proceed with my testing. I have been reading on various forums, but not getting any certain answer/solution.

Q: Is there an alternative to watir::ie.attach for watir-webdriver since attach is not supported on Watir-Webdriver

Sample code:

require "rubygems"

require "watir-webdriver"


require "selenium-webdriver"

b = Watir::Browser.new(:chrome)

website = "http://xyz.com"

#a new browser is launched and the website is opened

b.goto(website)

#this opens a new browser window

b.link(:xpath,"/html/body/div/ul/li/a").click

#there is a button called "MAP" on the new browser window

b.link(:id,"btn_MAP")

#this gives an error, unknown link

Answers:
A1:"window" method is the alternative for ie.attach. Webdriver can handle the window opened by itself with window method.
b.link(:href,/server\/getPage/).click
b.window(:url,/server\/getPage/i).use do
  b.link(:id,"btn_MAP").click
end

you can handle popped up windows in the window method block. If you want to keep handling popped up window, use it without block, like window(:url,/foobar/).use

see also: http://groups.google.com/group/watir-general/browse_thread/thread/232df221602d4cfb

 

A2: Thanks a lot for all your help it lead me to use something like the following and it worked!

b.link(:xpath,"/html/body/div/ul/li/a").click

c = b.window(:url,"http:\/\/server\/getPage\/67\/1354")

c.use

b.link(:id,"btn_MAP").click

 

 

分享到:
评论

相关推荐

    WATIR-WEBDRIVER自动化学习指导

    ### WATIR-WEBDRIVER自动化学习指导 #### 一、简介 WATIR-WEBDRIVER是一款基于Ruby语言的Web自动化测试框架,它能够帮助开发者和测试工程师编写高效的自动化测试脚本。WATIR(Web Application Testing In Ruby)与...

    linux环境下watir-webdriver离线安装包

    在Linux环境下进行自动化测试时,Watir-Webdriver是一个非常有用的工具。它是一个Ruby库,允许用户使用Ruby语言控制浏览器,进行网页元素的交互和测试。Watir是“Web Application Testing in Ruby”的缩写,而...

    watir安装所需要的gem包

    对于"watir安装所需要的gem包",主要涉及的Gem包有`watir-webdriver`和`selenium-webdriver`。`watir-webdriver`是Watir的一个版本,它使用Selenium WebDriver作为后端,与浏览器进行通信。而`selenium-webdriver`则...

    watir-1.5.2.gem

    开源自动化测试工具组合:Ruby+Watir安装 安装准备: 1. 工具安装包准备: Ruby官方下载地址:http://www.ruby-lang.org/zh_cn/downloads/,稳定版本Ruby 1.8.6 Watir下载地址:...

    watir-1.6.5.gem

    开源自动化测试工具组合:Ruby+Watir安装 安装准备: 1. 工具安装包准备: Ruby官方下载地址:http://www.ruby-lang.org/zh_cn/downloads/,稳定版本Ruby 1.8.6 Watir下载地址:...

    ruby 2.00 selenium webdriver,watir webdriver 备份打包

    Ruby 2.00、Selenium WebDriver 和 Watir WebDriver 是自动化测试领域中广泛使用的工具,尤其在Web应用程序的测试中。下面将详细讲解这三个概念及其相互关系。 Ruby 2.00 是Ruby编程语言的一个版本,发布于2013年,...

    ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份

    ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份,设置环境变量后可使用(未测试)

    ruby+watir安装包,安装步骤

    2.本地安装watir-1.4.1.gem,执行gem install watir-1.4.1.gem -l 3.本地安装rubygems-update-1.3.4.gem,执行 gem install rubygems-update-1.3.4.gem 4.更新rubygems,执行update_rubygems (这一步先忽略,有影响...

    Watir测试框架介绍

    expect(@browser.title).to include('Watir - Ruby Gem for Web Automation') end end ``` 这个例子展示了如何使用RSpec编写一个测试用例,其中包含了测试前后的浏览器初始化和关闭,以及预期结果的验证。 ### *...

    ruby watir介绍文档

    browser = Watir::Browser.new :chrome, driver: Selenium::WebDriver.for(:chrome) ``` #### 六、最佳实践 - **保持代码整洁**:遵循良好的编程习惯,如使用有意义的变量名、注释等。 - **测试数据分离**:将...

    watir-bonus-1.5.1.1230.zip

    **标题:“Watir-Bonus-1.5.1.1230.zip”** 这个压缩包包含的是Watir的扩展版本1.5.1的1230次更新,名为“Bonus”。Watir(Web Application Testing in Ruby)是一个开源的Ruby库,用于自动化浏览器操作,它使得...

    ruby and watir 安装指南

    Successfully installed watir-1.6.5 ``` #### 其他注意事项 - 如果安装过程中出现文档生成错误,如找不到 README 文件等,可以忽略这些错误继续进行。 - 确保安装了正确的 `activesupport` 版本,避免使用较新...

    ruby watir教程

    ### Ruby Watir 教程详解 #### 一、Ruby Watir 概述 **Ruby Watir** 是一种用于网页自动化测试的工具库,它能够模拟用户在浏览器中的操作行为,如点击按钮、填写表单等,非常适合进行功能测试、回归测试和系统测试...

    watir-webdriver谷歌浏览器驱动

    ChromeDriver 是一款以 Google Chrome 为环境测试网站的工具,现已实现对开源的 WebDriver 通路协议的支持,因此可以轻松与现有的 WebDriver 测试工具相整合。不熟悉 WebDriver 的用户可以参考 2009 年的项目发布...

    Watir-Webdriver最新安装文件(全)

    压缩包中包含目前2013/01/19最新的安装文件,有rubyinstaller-1.9.2-p136、DevKit-tdm-32-4.5.1-20101214-1400-sfx、rubygems-1.8.24、watir-4.0.2、watir-webdriver-0.6.2等文件,并附上简略安装说明。

    Watir自动化测试的实践代码

    4. Watir+Cucumber示例项目:https://github.com/watir/watir-webdriver-example 通过实践和不断学习,你将能够熟练掌握Watir,编写出高效且易于维护的自动化测试脚本,提升你的软件测试能力。

    watir-rails:添加对Watir(http

    安装将此代码添加到您的Gemfile中: group :test do gem "watir-rails"end用法就像您在请求/集成测试中一如既往地使用Watir: browser = Watir :: Browser . newbrowser . goto home_pathbrowser . text_field ( ...

Global site tag (gtag.js) - Google Analytics