我需要使用PhantomJS爲使用https的站點運行量角器測試。這是一個開發環境,證書是自簽名的,PhantomJS不承認。我用--ignore-ssl-errors標誌啓動PhantomJS,它應該使它接受無效的證書,但這不起作用。在CLI:通過HTTPS的PhantomJS
phantomjs --webdriver=localhost:4444 --web-security=false --ignore-ssl-errors=true --ssl-protocol=any
儘管這些設置,webdriver的的acceptSslCerts屬性仍設置爲false。從日誌:
Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
在相關GhostDriver回購問題(https://github.com/detro/ghostdriver/pull/388)下面的代碼所示:
const capabilities = webdriver.Capabilities.phantomjs(); capabilities.set(webdriver.Capability.ACCEPT_SSL_CERTS, true); capabilities.set(webdriver.Capability.SECURE_SSL, false); capabilities.set('phantomjs.cli.args', ['--web-security=no', '--ssl-protocol=any', '--ignore-ssl-errors=yes']); const driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome(), capabilities).build();
我試着在protractor.conf.js設置此:
capabilities: { browserName: 'phantomjs', 'webdriver.Capability.ACCEPT_SSL_CERTS': true, 'webdriver.Capability.SECURE_SSL': false }
但這沒有效果。
有沒有人想過如何在https模式下運行PhatomJS?