[英]Get browser for logging in Watir?
I want to show which browser is being used in a series of tests, ie, whether the browser is Chrome or Firefox. 我想显示在一系列测试中使用的浏览器,即浏览器是Chrome还是Firefox。
I have: 我有:
def initialize(browser)
@browser = browser
$log.info("\n"+"#{browser}"+" Browser initialized")
end
It returns Watir: 它返回Watir:
<Watir::Browser:0x24553a5d286c4da2 url="https://url" title="page name">
Are there any ideas how to get it to return the browser name instead? 有没有想法如何让它返回浏览器名称?
Watir API中也有方法,它也适用于watir-classic:
browser.name # => chrome
You can do it by directly accessing the underlying selenium-webdriver functionality: 您可以通过直接访问底层的selenium-webdriver功能来实现:
browser.driver.capabilities[:browser_name]
#=> 'chrome'
Easier solution is to do (from http://watirwebdriver.com/determining-which-browser/ ): 更容易的解决方案(来自http://watirwebdriver.com/determining-which-browser/ ):
browser.driver.browser
#=> :chrome
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.