2

How do I set the mobile emulation for Nexus 5 view in Serenity managed chrome driver?

I tried going through this link: https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/

Which explain setting preferences for 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

From this, I tried setting the mobileEmulation as

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

and a few other logical variants, but none of them succeeded.

Ashray
  • 171
  • 1
  • 7

1 Answers1

0

The best way I found to help me in this issue it to create a custom WebDriver.

I had to create a class which extends DriverSource. And then link it to the Serenity Properties file. This will give me the driver I need.

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.

Ashray
  • 171
  • 1
  • 7
  • I am facing a similar issue, able to launch the Chrome browser but it's asking to log in to the google account, so manually I have logged in to the google account but when I start the execution I am still getting the loogin page, is there any way to skip this page? – user3538483 Jun 05 '18 at 10:21