我正在嘗試設定 Selenium 來測驗我的電子應用程式。到目前為止,我有來自 Electron 檔案的代碼,但是,這只會打開 HTML 檔案,而不是我的實際應用程式。這是我的代碼:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'chromeOptions': {
// Here is the path to your Electron binary.
binary: '../../node_modules/electron/dist/electron.exe'
}
})
.forBrowser('chrome')
.build();
const current_path = path.join(__dirname, "../../dist/public/index.html");
driver.get('file://' current_path);
我怎樣才能讓它打開我的應用程式?
幾天來我一直試圖弄清楚這一點,所有其他文章和 stackoverflow 帖子要么指向 Spectron(現已棄用),要么沒有解釋如何打開我自己的應用程式而不是其他網站。
編輯:我發現添加"args": ['--app=PATH_TO_PROJECT_DIR')]chromeOptions 物件并將名稱更改為"goog:chromeOptions",使其打開到正確的檔案路徑,但是,現在我收到以下錯誤:
WebDriverError: unknown error: no chrome binary at ../../node_modules/electron/dist/electron.exe
改回“chromeOptions”會阻止它打開應用程式目錄,但會打開一個空白的 chrome 視窗。
uj5u.com熱心網友回復:
解決方案是:
- 替換
'../../node_modules/electron/dist/electron.exe'為path.join(__dirname, '../../node_modules/electron/dist/electron.exe') - 更改
chromeOptions為goog:chromeOptions - 添加
"args": [path.join(__dirname, '../../')]到 goog:chromeOptions 物件。
作業代碼:
import * as path from "path";
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
// The "9515" is the port opened by ChromeDriver.
.usingServer('http://localhost:9515')
.withCapabilities({
'goog:chromeOptions': {
// Here is the path to your Electron binary.
"binary": path.join(__dirname, '../../node_modules/electron/dist/electron.exe'),
"args": ['--app=' path.join(__dirname, "../../")]
}
})
.forBrowser('chrome')
.build();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475365.html
