为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

潇潇雨雨 2021-09-25 10:05:39
有很多关于使用 Spectron 测试使用 Electron 构建的应用程序的文档。由于我有很多用 Python 编写的实用程序,我想知道是否有任何方法可以使用 Python-Selenium 来测试使用 Electron 构建的应用程序。从一些在线资源中,我发现一些人能够做到(虽然不是我目前使用的最新版本)。我能够使用下面的代码启动应用程序,但调用 webdriver.Chrome() 是一个阻塞调用,我从来没有得到驱动程序实例:from selenium import webdriveroptions = 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)谢谢。
查看完整描述

2 回答

?
蓝山帝景

TA贡献1843条经验 获得超7个赞

    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 打开电子应用程序,以便它们可以相互连接。


请务必使用与您的电子版本匹配的正确 Web 驱动程序版本。


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


查看完整回答
反对 回复 2021-09-25
  • 2 回答
  • 0 关注
  • 666 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信