2017-10-16 113 views
2

如何在Serenity託管的Chrome驅動程序中設置Nexus 5視圖的移動模擬?在Chrome驅動程序的serenity.properties文件中設置設備名稱

我試圖要通過此鏈接: https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/

這解釋了鍍鉻設置首選項。

Chrome preferences 
You can also provide more advanced options using the setExperimentalOption() method: 

Map<String, Object> chromePrefs = new HashMap<String, Object>(); 
chromePrefs.put("download.default_directory", downLoadDirectory); 
chromePrefs.put("profile.default_content_settings.popups", 0); 
chromePrefs.put("pdfjs.disabled", true); 
ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("prefs", chromePrefs); 

In Serenity, you would pass these using properties prefixed with the chrome_preferences prefix, e.g. 

chrome_preferences.download.default_directory = /my/download/directory 
chrome_preferences.profile_default_content_settings.popups = 0 
chrome_preferences.pdfjs.disabled=true 

由此,我嘗試設置mobileEmulation作爲

chrome.capabilities.mobile_emulation.device_name= Google Nexus 5 chrome.options.mobileEmulation.deviceName= Google Nexus 5

和其他一些邏輯變種,但沒有一個成功的。

回答

0

我發現最好的方式來幫助我在這個問題上創建一個自定義WebDriver。我不得不創建一個擴展DriverSource的類。然後將其鏈接到Serenity屬性文件。這會給我我需要的司機。

http://www.thucydides.info/docs/serenity/#_custom_webdriver_implementations

您可以通過實現 DriverSource界面添加自定義的webdriver提供商。首先,你需要設置以下系統 特性(例如,在你的serenity.properties文件):

webdriver.driver = provided 
webdriver.provided.type = mydriver 
webdriver.provided.mydriver = com.acme.MyPhantomJSDriver 
thucydides.driver.capabilities = mydriver 

您的自定義驅動程序必須實現DriverSource界面,如圖所示 這裏:

public class MyPhantomJSDriver implements DriverSource { 

    @Override 
    public WebDriver newDriver() { 
     try { 
      DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); 
      // Add 
      return new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), 

功能); (IOException e){ }拋出新的錯誤(e); }}

 @Override 
    public boolean takesScreenshots() { 
     return true; 
    } 
} 

此驅動程序現在就截圖正常。