在 serenity.properties 文件中为 chrome 驱动程序设置设备名称
Setting device name in serenity.properties file for chrome driver
如何在 Serenity 管理的 chrome 驱动程序中为 Nexus 5 视图设置移动仿真?
我试过这个 link:
https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/
其中解释了 chrome 的设置首选项。
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
和其他一些逻辑变体,但其中 none 成功了。
我找到的帮助我解决此问题的最佳方法是创建自定义 WebDriver。
我必须创建一个扩展 DriverSource 的 class。然后 link 它到 Serenity Properties 文件。这将为我提供所需的驱动程序。
http://www.thucydides.info/docs/serenity/#_custom_webdriver_implementations
You can add your own custom WebDriver provider by implementing the
DriverSource interface. First, you need to set up the following system
properties (e.g. in your serenity.properties file):
webdriver.driver = provided
webdriver.provided.type = mydriver
webdriver.provided.mydriver = com.acme.MyPhantomJSDriver
thucydides.driver.capabilities = mydriver
Your custom driver must implement the DriverSource interface, as shown
here:
public class MyPhantomJSDriver implements DriverSource {
@Override
public WebDriver newDriver() {
try {
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
// Add
return new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
capabilities);
}
catch (IOException e) {
throw new Error(e);
}
}
@Override
public boolean takesScreenshots() {
return true;
}
}
This driver will now take screenshots normally.
如何在 Serenity 管理的 chrome 驱动程序中为 Nexus 5 视图设置移动仿真?
我试过这个 link: https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/
其中解释了 chrome 的设置首选项。
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
和其他一些逻辑变体,但其中 none 成功了。
我找到的帮助我解决此问题的最佳方法是创建自定义 WebDriver。
我必须创建一个扩展 DriverSource 的 class。然后 link 它到 Serenity Properties 文件。这将为我提供所需的驱动程序。
http://www.thucydides.info/docs/serenity/#_custom_webdriver_implementations
You can add your own custom WebDriver provider by implementing the DriverSource interface. First, you need to set up the following system properties (e.g. in your serenity.properties file):
webdriver.driver = provided webdriver.provided.type = mydriver webdriver.provided.mydriver = com.acme.MyPhantomJSDriver thucydides.driver.capabilities = mydriver
Your custom driver must implement the DriverSource interface, as shown here:
public class MyPhantomJSDriver implements DriverSource { @Override public WebDriver newDriver() { try { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); // Add return new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
capabilities); } catch (IOException e) { throw new Error(e); } }
@Override public boolean takesScreenshots() { return true; } }
This driver will now take screenshots normally.