如何使用Google Chrome浏览器在Robot Framework中进行测试?

问题描述 投票:0回答:1

最近Google Chrome推出了用于测试的Chrome浏览器,专门用于自动化。如何触发Chrome浏览器在robot框架中进行测试?

了解更多信息:https://googlechromelabs.github.io/chrome-for-testing/ 从 Chrome 114 版本开始,我们将不得不使用 Chrome 浏览器进行测试。 有人可以帮忙吗?

另外,浏览器在测试后自动关闭,我没有任何拆卸或关闭浏览器关键字。

有什么办法可以解决这个问题吗?

python automation robotframework browser-automation
1个回答
0
投票
  1. 下载“Chrome 用于测试”并解压。 例如。到
    C:\opt\chrome_for_testing\chrome-win64
  2. 匹配的 chromedriver.exe 应在系统“路径”中可用
  3. RobotFramework中使用(下面的命令是一行!):
open browser    browser=Chrome 
     options=binary_location=r"C:\\opt\\chrome_for_testing\\chrome-win64\\chrome.exe"
  1. Python
  2. 中使用
    from robot.libraries.BuiltIn import BuiltIn
        
    def start_chrome_for_testing_example():
        from selenium.webdriver.chrome.options import Options
        from selenium.webdriver.chrome.service import Service
        from selenium import webdriver
    
        opts = Options()
        opts.add_argument("--no-sandbox")
        opts.add_argument("--start-maximized")
    
        opts.binary_location = r'C:\opt\chrome_for_testing\chrome-win64\chrome.exe'
        chromedriver = r"C:\opt\chrome_for_testing\chromedriver-win64\chromedriver.exe"
        browser = webdriver.Chrome(options=opts, service=Service(chromedriver))
    
        selenium_library = BuiltIn().get_library_instance("SeleniumLibrary")
        selenium_library._drivers.register(browser, 'chrome')```
© www.soinside.com 2019 - 2024. All rights reserved.