Electron在使用Selenium ChromeDriver时无法访问用户数据目录

Electron在使用Selenium ChromeDriver时无法访问用户数据目录,selenium,electron,selenium-chromedriver,robotframework,Selenium,Electron,Selenium Chromedriver,Robotframework,我正在使用Selenium和Robot框架来运行一个电子应用程序。该应用程序构建为从用户数据目录读取配置文件。据我所知,这是这个文件应该存储的位置 electron主进程读取配置文件: const localConfigFile = path.join(app.getPath('userData'), 'config.json'); const localConfig = fs.existsSync(localConfigFile) ? require(localConfigFile) : {}

我正在使用Selenium和Robot框架来运行一个电子应用程序。该应用程序构建为从用户数据目录读取配置文件。据我所知,这是这个文件应该存储的位置

electron主进程读取配置文件:

const localConfigFile = path.join(app.getPath('userData'), 'config.json');
const localConfig = fs.existsSync(localConfigFile) ? require(localConfigFile) : {};
构建的生产版本工作正常,可以按预期读取文件,但当使用SeleniumLibrary从Robot启动时,不会读取文件。这让我相信这是机器人、硒或铬驱动的问题

Robot使用SeleniumLibrary创建Web驱动程序:

Create Webdriver    Remote    desired_capabilities=${starting_parameters}    command_executor=http://127.0.0.1:9515
其中,启动参数仅为:

{ "chromeOptions": {"binary": <binary_location> }}

我通过使用Spectron和记录Electron主控制台发现了问题。总的来说,我建议使用Spectron而不是Robot来测试电子应用程序

问题是,用户数据目录与默认目录不同。当通过Chromedriver运行应用程序时,用户数据目录更改为/tmp/somethingsomething,因此自然找不到~/.config/app name下的文件

我的解决方案是使用Electron的应用程序数据目录:

app.getPath('appData')

默认情况下,这是用户数据目录的上一个目录,但在运行Chromedriver时保持不变。

遇到了相同的问题。最后,将Chromedriver的user data dir参数更改为Electron的userDataDir解决了这个问题

options.add_参数('--user data dir='+str(app_config_path()))

app.getPath('appData')