Setting the download path in Chrome using Serenity.properties file

4,702 views
Skip to first unread message

harshad...@gmail.com

unread,
May 2, 2016, 4:17:11 AM5/2/16
to Serenity BDD Users Group
Does anyone have any idea how to pass the Chrome download path location through serenity.properties.
I have gone through WebDriverFactory.java in Serenity core jar.But there is no method where its sets the setExperimentalOptions() method of ChromeOptions class.
Please help.

s...@samwarwick.com

unread,
Jun 28, 2016, 10:17:00 PM6/28/16
to Serenity BDD Users Group
Hi,

I have a similar requirement to use setExperimentalOptions() since I need to enable/disable location services in Chrome and prevent the pop message from appearing. I can achieve this in native Selenium but I cannot determine how to do it from Serenity. 

Here is the sample Selenium code:

DesiredCapabilities capability = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> profile = new HashMap<String, Object>();
Map<String, Object> contentSettings = new HashMap<String, Object>();
contentSettings.put("geolocation", 1); // 1=location services on, 2=location services off
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
options.setExperimentalOption("prefs", prefs);
capability.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("<my url>"), capability);                                          
System.out.println("location: " + driver.findElement(By.id("locationname")).getText());     

Any suggestions?

Thanks!
Sam

Harry King

unread,
Jun 29, 2016, 4:44:14 AM6/29/16
to Serenity BDD Users Group
Hi Sam,

The easiest way to implement custom options for Chrome would be to write a custom driver.  This is easier than it sounds, as you have already written most of the code!  See here in the docs:

Harshad Sane

unread,
Jun 29, 2016, 5:18:55 AM6/29/16
to Harry King, Serenity BDD Users Group

Hi Harry,

Implementing custom webdriver has some issues. It opens two instances of Chrome and also the screenshots for tests are blank.

Regards,
Harshad

--
You received this message because you are subscribed to a topic in the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thucydides-users/jPUL9h3IWC4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s...@samwarwick.com

unread,
Jun 30, 2016, 12:16:32 AM6/30/16
to Serenity BDD Users Group
Hi Harry,

Thanks for the tip. I have got the custom driver working ok and not experienced the multiple instance issue reported by Harshad. 
However, one challenge still remains: how can I configure my custom driver with the other Serenity/browser properties that can be provided at run time e.g. chrome.switches, browserstack.* etc? ie. all the stuff that the WebDriverFactory seems to take care of.

thanks
Sam

Harry King

unread,
Jul 1, 2016, 3:35:37 AM7/1/16
to Serenity BDD Users Group
@Hardshad:

Are you ovveriding the takesScreenshot method?  Also, I'm using JBehave and not getting two browsers launched.  Which test framework are you using?  Is it JUnit? (the trick here is to annotate your driver with a @Managed)
  @Override
    public boolean takesScreenshots() {
        return true;
    }

@Sam if you need to change which chrome command line switches or browserstack creds at runtime, look at using System.getProperty("property.name", "default.value") as part of your custom driver code.  You can then use -Dproperty.name=nondefault to override the default value.

Harshad Sane

unread,
Jul 1, 2016, 3:39:41 AM7/1/16
to Harry King, Serenity BDD Users Group

Hi Harry,
I am also using the serenity jbehave framework.
And I haven't override the screenshot method.

Regards
Harshad

--

Harry King

unread,
Jul 1, 2016, 3:59:57 AM7/1/16
to Serenity BDD Users Group, hazme...@gmail.com
Hi Harshad,

Would you mind sharing the code for your custom driver?  

Kind regards,
Harry

80Vikram

unread,
Feb 9, 2018, 9:57:52 AM2/9/18
to Serenity BDD Users Group
Hi Harry,

Please let me know if you get this resolved ?

I've similar requirement + I would like to control which type of cookie to enable/ disable ( current website, 3rd party )

https://stackoverflow.com/questions/48667852/how-to-change-allow-sites-to-save-and-read-cookie-data-recommended-and-or-bloc

Thanks & Regards,
Vikram

Harry King

unread,
Feb 9, 2018, 3:37:52 PM2/9/18
to Serenity BDD Users Group
Hi Vikram,

You should be able to set the properties you want using a provided driver:

I'm using it in my suite to set some settings and install a custom addon.

Kind regards,
Harry

80Vikram

unread,
Feb 13, 2018, 8:46:39 AM2/13/18
to Serenity BDD Users Group
Hi Harry,

Wrt article

https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/

I can run my web analytics script as below by blocking 3rd party cookies


mvn -e clean install -Dcucumber.options="src/test/resources/features/dummy.feature" -Dchrome_preferences.profile.block_third_party_cookies="true"

or putting last parameter in serenity.properties file

But I didn't understand in which scenario one should use custom driver ?

Please clarify

Thanks & Regards,
Vikram

Harry King

unread,
Feb 15, 2018, 6:06:03 AM2/15/18
to Serenity BDD Users Group
switch (BROWSER) {
    case NEXUS_5:
        realDevice = checkForRealDevice();
        capabilities.merge(chrome());
        if(realDevice) {
            capabilities.merge(realDeviceCapabilities());
            driver = new ChromeDriver(capabilities);
        } else {
            capabilities.merge(softwareChromeCapabilities(true));
            driver = useRemote ? new RemoteWebDriver(capabilities) : new ChromeDriver(capabilities);
            closeExtraTab(driver);
        }
        break;
    case FIREFOX

The above example will attempt to run the text on an Android phone if one is connected to the machine, else falling back to a mobile emulated view.  The emulated view can have ad-block installed, which causes an extra tab to be opened which I discard.  In both cases, I attach a software proxy to assert analytics are working, and if the window can be resized, I have different behaviour for devices and browsers.
Reply all
Reply to author
Forward
0 new messages