問題描述
所以我們的應用程序在啟用 CORS 的情況下在生產環境中工作.
So our application works in production with a CORS enabled.
我有一個未在本地啟用 CORS 的項目.有沒有辦法禁用量角器的網絡安全?有沒有辦法給 selenium 實例添加參數?
I have a project that isn't CORS enabled locally. Is there a way to disable web security for protractor? Is there a way for me to add arguments to the selenium instance ?
我們正在尋找基于配置的解決方案.我們的本地開發機器完全鎖定了我們可以安裝的內容.那么這可能嗎?
We're looking for a configuration based solution. Our local development machines are pretty locked down on what we can install. So is this possible?
我嘗試的是設置 chrome 選項:https://github.com/angular/protractor/issues/175
What i have tried is setting chrome options: https://github.com/angular/protractor/issues/175
但這似乎只用于 chrome 擴展.
But that appears to only be used for chrome extensions.
推薦答案
還有args
在 chromeOptions
中,您可以在其中提供 --disable-web-security
和 --user-data-dir
參數.
There is also args
inside chromeOptions
, where you can provide the --disable-web-security
and --user-data-dir
arguments.
如果您在本地運行測試,請確保提供配置文件位置 用于 --user-data-dir
,否則 Chrome 將使用默認配置文件并在當前瀏覽器會話中加載頁面(與所有擴展程序和設置一起運行).
If you are running the tests locally, make sure to supply a profile location for the --user-data-dir
, otherwise Chrome will use the default profile and load the page in the current browser session (running with all of your extensions and settings).
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--disable-web-security', '--user-data-dir=~/.e2e-chrome-profile']
}
},
這篇關于protractor - 啟動 chrome 以禁用 cors 的網絡安全的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!