使用 python + selenium 进行测试时如何包含电子二进制文件

How do you include electron binary while using python + selenium for testing

我正在使用 python 和 selenium 来测试电子应用程序。但是,当应用程序通过 selenium 打开时,它似乎缺少电子,因为所有 i18n 替换都没有发生。如果我手动打开应用程序,那么一切正常。我们推测 electron 以某种方式没有正确加载。有谁知道如何以某种方式将电子二进制文件添加到 chrome 驱动程序选项?这是我下面的

from selenium import webdriver as app
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:/Users/eeee/AppData/Local/Programs/folder/app.exe"
caps = app.DesiredCapabilities.CHROME
caps['goog:chromeOptions'] = {'binary': "./node_modules/.bin/electron"}

driver = app.Chrome(desired_capabilities=caps, options=options)  # start

time.sleep(5)

driver.quit()

我发现这与 windows 系统上工作目录发生变化有关。

因此您需要将当前工作目录设置为exe所在的同一文件夹。您可以使用 Popen 或在 selenium 中进行一些工作,但它在 selenium

中不是原生的

我用 slack 测试过:

app_path=\AppData\Local\slack\app-4.20.0\slack.exe
app_cwd=\AppData\Local\slack\app-4.20.0