使用Python+Selenium进行基于electronin的应用程序测试

2024-06-28 20:05:51 发布

您现在位置:Python中文网/ 问答频道 /正文

有很多关于使用Spectron测试使用电子构建的应用程序的文档。在

由于我有很多用Python编写的实用程序,我想知道是否有任何方法可以使用pythonsium来测试电子版内置的应用程序。在

从一些在线资源中,我发现一些人能够做到这一点(尽管不是我目前使用的最新版本)。 我可以用下面的代码启动应用程序,但是网络驱动程序.Chrome()是一个阻塞调用,我从未获得驱动程序实例:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/home/username/electron_test/node_modules/electron/dist/electron"

options.add_argument("--app=/home/username/electron_test/")
driver = webdriver.Chrome(chrome_options=options)

谢谢。在


Tags: 方法文档test实用程序应用程序home驱动程序电子
1条回答
网友
1楼 · 发布于 2024-06-28 20:05:51
    from selenium import webdriver

    # Start the web driver
    web_driver_path = os.path.join(
        os.environ["ProgramFiles(x86)"],
        "chromedriver-v3.1.9-win32-x64",
        "chromedriver.exe")
    service = webdriver.chrome.service.Service(web_driver_path)
    service.start()

    # start the app
    self.web_driver = webdriver.remote.webdriver.WebDriver(
        command_executor=service.service_url,
        desired_capabilities={
            'browserName': 'chrome',
            'goog:chromeOptions': {
                'args': [],
                'binary': PATH_TO_BINARY_APP,
                'extensions': [],
                'windowTypes': ['webview']},
            'platform': 'ANY',
            'version': ''},
        browser_profile=None,
        proxy=None,
        keep_alive=False)

首先需要为webdriver创建一个服务实例。之后,打开带有服务url的电子应用程序,这样他们就可以互相连接了。在

一定要使用正确的网络驱动程序版本匹配你的电子版本。在

仅供参考:当你在应用程序中使用类似webviews的东西时,你会喜欢“windowTypes”这一行。我花了几个小时才弄明白。在

相关问题 更多 >