2017-06-22 43 views
3

根據this issue,ChromeDriver-2.26 +中提供了Chrome DevTools的網絡調節功能。我怎樣才能在我們的量角器配置文件中指定這個?量角器:啓用網絡啓用網絡調節功能

基於四處搜索,我已經嘗試了配置文件中的幾件事情的變體。我已經爲chromeOptions添加了networkConnectionEnabled屬性和prefs塊,如下所示。 (請注意,我並沒有在同一時間做這兩個動作。)

multiCapabilities: [ 
    { 
     'browserName': 'chrome', 
     'platform': 'ANY', 
     'networkConnectionEnabled': {'type': 'GPRS'}, 
     'chromeOptions': { 
      args: [ 
       '--lang=en', 
       '--window-size=1280,1024' 
      ], 
      prefs: { 
       'net.throttling_enabled': 'true,50,20' 
      } 
     } 
    } 
], 

我根據我發現here(線1983)試圖第二個選項。這些都不會改變量角器運行的行爲,當我手動測試並設置限制觸發器時,在我的代碼中會出現一定的條件。

編輯:也嘗試添加像這樣underchromeOptions:mobileEmulation:{networkConnectionEnabled: true, networkThrottle: '2G'}

+0

如果我沒有記錯,只有當移動仿真被激活時,節流纔可用。 –

+0

@FlorentB。我嘗試過類似的東西(請參閱編輯),但仍然不確定是否將其設置正確。 – eflat

+0

網絡調節現在從設備模式分離,並且能夠始終運行。 – Garbee

回答

1

根據changelog的API在Chrome操縱網絡仿真是在硒3.4.0添加。它們可用於Protract 5.2.0或更新版本。

網絡條件可被配置爲類似於下面:

browser.driver.setNetworkConditions({ 
    offline: false, 
    latency: 5, // Additional latency (ms). 
    download_throughput: 500 * 1024, // Maximal aggregated download throughput. 
    upload_throughput: 500 * 1024 // Maximal aggregated upload throughput. 
}); 

此代碼應被放置在裏面protractor.conf.js功能onPrepare