如何判断浏览器类型(IE、FF、Chrome等)
我正在将 Watir / FireWatir 脚本切换为使用 watir-webdriver,并且需要 watir-webdriver 中的一种方法来确定当前正在执行测试的浏览器类型(IE、FF、Chrome)。
使用 Watir / FireWatir 查看浏览器的类将返回“Watir::IE”或“FireWatir:Firefox”。使用该代码可以分支以执行浏览器特定的代码。
在 watir-webdriver 中,浏览器的类始终是“Watir::Browser”,在运行 IE、Firefox 或 Chrome 时不会发生变化。
有谁知道 Ruby 中使用 watir-web-driver 来识别浏览器类型(即 IE、Firefox、Chrome)的方法?
例如:使用 Watir / Firewatir 定义方法:
def is_ie?()
return self.class.to_s == "Watir::IE"
end
def is_firefox?()
return self.class.to_s == "FireWatir::Firefox"
end
然后像这样调用它们...
if(browser.is_ie?)
# run the IE specific code
end
if(browser.is_firefox?)
# run the firefox specific code
end
提前致谢,
乔
I'm in the process of switching my Watir / FireWatir scripts over to use watir-webdriver and need a means in watir-webdriver to determine which type of browser the test is currently being executed against, (IE, FF, Chrome).
With Watir / FireWatir looking at the class of the browser would return either "Watir::IE" or "FireWatir:Firefox". Using that the code could be branched to execute browser specific code.
In watir-webdriver, the class of the browser is always "Watir::Browser", it doesn't vary when running IE, Firefox, or Chrome.
Does anyone know of a way in Ruby with watir-web-driver to identify the browser's type (i.e. IE, Firefox, Chrome)?
For example: With Watir / Firewatir define methods:
def is_ie?()
return self.class.to_s == "Watir::IE"
end
def is_firefox?()
return self.class.to_s == "FireWatir::Firefox"
end
Then invoke them like this...
if(browser.is_ie?)
# run the IE specific code
end
if(browser.is_firefox?)
# run the firefox specific code
end
Thanks in advance,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
browser.driver.browser #=> :火狐浏览器
Try
browser.driver.browser #=> :firefox
谢谢,这正是我所需要的!
由于我正在将一些脚本移植到 Watir-WebDriver,而一些脚本仍需要在 Watir / Firewatir 下运行,因此我已更新 mt 方法如下,将其发布以防其他人处于相同情况。
def is_chrome?()
结束
def is_firefox?()
结束
def is_ie?()
结束
def is_webdriver?()
结束
Thanks that is just what I needed!
As I'm in a transition with some scripts ported over to Watir-WebDriver and some still needing to run under Watir / Firewatir I've updated mt method as follows, posting them in case someone else is in the same situation.
def is_chrome?()
end
def is_firefox?()
end
def is_ie?()
end
def is_webdriver?()
end