Connecting selenium driver to CEF desktop application

雨燕双飞 提交于 2020-03-05 03:14:32

问题


I want to use Selenium WebDriver to run automated tests in a CEF window that is embedded in an application. When i run application with debug console enabled, and then i start my test i'm getting following error:

SessionNotCreatedException: Message: session not created from unknown error: unhandled inspector error: ("code":-32601, "message":"'Target.setAutoAtach' wasn't found")

How can I fix this error? Or there is another way to connect to CEF desktop application?

My C# code:

Cef.Initialize(new CefSettings
{
    RemoteDebuggingPort = 55555,
    Locale = ResourcesController.GetResource("Locale"),
    LogSeverity = LogSeverity.Disable
});
ChromeBrowser = new ChromiumWebBrowser(mainHtml)
{
    Dock = DockStyle.Fill,
    BrowserSettings = new BrowserSettings
    {
        FileAccessFromFileUrls = CefState.Enabled,
        UniversalAccessFromFileUrls = CefState.Enabled,
    },
    MenuHandler = new CustomContextMenuHandler()
};

And automation test in python:

import unittest
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import os

CEF_PORT = "55555"
DEBUGGER_ADDRESS = "localhost:{}".format(CEF_PORT)
CHROMEDRIVER_PATH = "C:\chromedriver\chromedriver.exe"
os.environ["PATH"] += os.pathsep + r'C:\chromedriver'

class LoginTest(unittest.TestCase):
    window_handle_main = None

    def setUp(cls):
        options = webdriver.ChromeOptions()
        options.debugger_address = DEBUGGER_ADDRESS

    def test_button_login_click(self):
        WebDriverWait(self.instance, 5).until(ec.presence_of_element_located((By.ID, "btnLogin")))
        self.instance.find_element_by_id("btnLogin").click()

    def tearDown(self):
        self.instance.close()

if __name__ == "__main__":
    unittest.main()

I'm using latest version of chromedriver (2.43).

来源:https://stackoverflow.com/questions/53214188/connecting-selenium-driver-to-cef-desktop-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!