从桌面应用程序切换到现有 chrome 浏览器
Switching to existing chrome browser from desktop application
我正在尝试控制现有的 chrome 浏览器,并希望使用相同的浏览器进行自动化,使用 selenium 和 Karate。
这是一个实际场景:
我从桌面上单击一个超级link,它在chrome 浏览器中打开。现在我需要在同一浏览器中 运行 我的自动化脚本。
我有以下代码,在此之前,我使用此 link https://harith-sankalpa.medium.com/connect-selenium-driver-to-an-existing-chrome-browser-instance-41435b67affd
在调试模式下启动 chrome 浏览器
* def startUrl = "https://google.com"
* def browser = "chrome"
* def type = "chromedriver"
* def executable = "C:/chromedriver/" + type + ".exe"
* def driverConfig = { type: #(type), showDriverLog: true, start:false, executable: #
(executable), webDriverSession: { desiredCapabilities: { browserName: #
(browser),goog:chromeOptions": { debuggerAddress: 127.0.0.1:9223 } } } }
* configure driver = driverConfig
Given driver startUrl
* waitFor('input[name=q]')
And input('input[name=q]', 'Youtube')
任何人都可以确认如何完成吗?我是空手道新手-UI
仅当 Chrome 实例已使用 remote-debugging enabled 启动时,才能控制现有 Chrome 实例以使用空手道 UI
在命令行中,这通常是通过添加以下选项来完成的:--remote-debugging-port=9222
。
我知道一个团队使用空手道 UI 来实现自动化 CEF (Chromium Embedded Framework) used in a desktop application. In this case, the developers of the desktop app made an environment variable drive the enabling of this debug mode。例如如果 OS 环境变量 ENABLE_CHROME_DEBUG
的值等于 true
,则将通过 SDK / API.
以编程方式启用 CEF 远程调试
所以你必须想出一些类似的方法。如果桌面应用程序正在创建 Chrome 的新实例,也应该可以启用远程调试 - 您应该与开发团队合作,为了可测试性而使其“可切换”。
完成后,空手道可以通过远程调试协议“附加”到现有的 Chrome 实例。参考文档:https://github.com/intuit/karate/tree/master/karate-core#configure-driver
并记下 attach
配置键:
optional, only for type: 'chrome' and start: false when you want to attach to an existing page in a Chrome DevTools session, uses a "contains" match against the URL
因此,如果您知道要附加到的浏览器中已打开的 URL(即使它是 about:blank
),您现在可以继续进行测试。您将只需要 configure driver
数据中的这些键:
type: 'chrome'
start: false
attach: 'some/url'
- 由于这是“包含”匹配项,因此可以省略 http
或 https
部分
port: 9222
- 如果不同 ,请将其更改为使用实际端口
和executable
等不需要。
当您结合使用桌面和浏览器测试时,请注意一些怪癖:https://github.com/intuit/karate/issues/1549#issuecomment-821265333
我正在尝试控制现有的 chrome 浏览器,并希望使用相同的浏览器进行自动化,使用 selenium 和 Karate。
这是一个实际场景:
我从桌面上单击一个超级link,它在chrome 浏览器中打开。现在我需要在同一浏览器中 运行 我的自动化脚本。
我有以下代码,在此之前,我使用此 link https://harith-sankalpa.medium.com/connect-selenium-driver-to-an-existing-chrome-browser-instance-41435b67affd
在调试模式下启动 chrome 浏览器* def startUrl = "https://google.com"
* def browser = "chrome"
* def type = "chromedriver"
* def executable = "C:/chromedriver/" + type + ".exe"
* def driverConfig = { type: #(type), showDriverLog: true, start:false, executable: #
(executable), webDriverSession: { desiredCapabilities: { browserName: #
(browser),goog:chromeOptions": { debuggerAddress: 127.0.0.1:9223 } } } }
* configure driver = driverConfig
Given driver startUrl
* waitFor('input[name=q]')
And input('input[name=q]', 'Youtube')
任何人都可以确认如何完成吗?我是空手道新手-UI
仅当 Chrome 实例已使用 remote-debugging enabled 启动时,才能控制现有 Chrome 实例以使用空手道 UI
在命令行中,这通常是通过添加以下选项来完成的:--remote-debugging-port=9222
。
我知道一个团队使用空手道 UI 来实现自动化 CEF (Chromium Embedded Framework) used in a desktop application. In this case, the developers of the desktop app made an environment variable drive the enabling of this debug mode。例如如果 OS 环境变量 ENABLE_CHROME_DEBUG
的值等于 true
,则将通过 SDK / API.
所以你必须想出一些类似的方法。如果桌面应用程序正在创建 Chrome 的新实例,也应该可以启用远程调试 - 您应该与开发团队合作,为了可测试性而使其“可切换”。
完成后,空手道可以通过远程调试协议“附加”到现有的 Chrome 实例。参考文档:https://github.com/intuit/karate/tree/master/karate-core#configure-driver
并记下 attach
配置键:
optional, only for type: 'chrome' and start: false when you want to attach to an existing page in a Chrome DevTools session, uses a "contains" match against the URL
因此,如果您知道要附加到的浏览器中已打开的 URL(即使它是 about:blank
),您现在可以继续进行测试。您将只需要 configure driver
数据中的这些键:
type: 'chrome'
start: false
attach: 'some/url'
- 由于这是“包含”匹配项,因此可以省略http
或https
部分port: 9222
- 如果不同 ,请将其更改为使用实际端口
和executable
等不需要。
当您结合使用桌面和浏览器测试时,请注意一些怪癖:https://github.com/intuit/karate/issues/1549#issuecomment-821265333