通过Robot Framework/Selenium将asar文件加载到Electron中



我有一个Electron应用程序打包为app.asar文件。当用Electron打开它时,它运行良好,我需要找到一种通过Robot Framework对它进行测试的方法。

问题是,虽然我可以通过Robot启动Electron应用程序,但我找不到将app.asar文件传递给它的方法。该应用程序和Electron都位于完全不同的位置。

基于我能找到的唯一一个提到Electron和Robot Framework的非常简洁的来源,我做出了以下内容:

vars.py:

binary_location = {"chromeOptions": {"binary": "C:/path/to/electron/electron.exe"}}

ElectronTest.txt

*** Settings ***
Library           Selenium2Library
Library           OperatingSystem
Variables         vars.py
*** Variables ***
${Delay}          1s
${executor}       http://localhost:9515
*** Test Cases ***
Foo
    Set Selenium Speed    ${Delay}
    Create Webdriver    Remote    desired_capabilities=${binary_location}    command_executor=${executor}
    Wait Until Page Contains Element    css=.workspace
    [Teardown]    Close All Browsers
*** Keywords ***
Set Environment Variable
    webdriver.chrome.driver    ./chromedriver.exe

这启动了Electron,但给了我以下错误:

提供的应用程序不是有效的电子应用程序,请阅读上的文档如何编写:https://github.com/atom/electron/tree/master/docs

错误:找不到模块"C:\path\to\ElectronTest:data"

考虑到我实际上并没有通过应用程序,这是有道理的,尽管我不知道它为什么在Robot Framework文件夹中寻找应用程序

我还尝试用我的应用程序的路径替换执行器,例如:

${executor}      file://C:/path/to/my/app/dist/app.asar

在这种情况下,我从Robot Framework中得到以下错误:

URLError:urlopen错误[Error3]系统找不到路径指定:u'path\to\my\app\dist\app.asar\session'

不知道为什么它会尝试访问"app.asar\session"。

我猜我在某个地方丢失了一个参数,但无论我怎么搜索和尝试,我都找不到任何方法来解决这个问题。

有没有办法通过Robot Framework将.asar文件传递给Electron

您链接的指令假设您已将电子应用程序打包到.exe中。尚不清楚您是否完成了第一步,但错误消息表明您没有("提供的应用程序不是有效的电子应用程序")。

如果没有,您可能想阅读电子文档中的[Application Distribution][1]。完成后,您将创建一个自定义.exe,其中包括您的asar文件和任何其他文件。必须从robot开始的是this.exe的路径,而不是您下载的electron.exe

最新更新