3

Trying to update our code to Selenium 3.x, and I keep running into an error being thrown when I'm trying to run our tests:

error: cannot access MutableCapabilities

This same code used to work as far as running the tests, and I'm not really sure where or why it's coming up with such a strange error. I can't seem to find anything that anyone has written up before, so I'm hoping that the stackoverflow community can help me with this one.

Here's the code that is generating this error:

package com.iacapps.ste.ta.helpers;

import com.google.common.base.Strings;
import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;

public class CustomCapabilities extends DefaultCapabilitiesBuilder
{
  private static final Logger logger = LoggerFactory.getLogger(DefaultCapabilitiesBuilder.class);

  private static final String SAUCE_TUNNEL_PROPERTY = "sauceTunnel";
  private static final String SAUCE_ENABLED_PROPERTY = "enableSauceConnect";
  private static final String TUNNEL_CAPABILITY = "tunnelIdentifier";
  private static final String ACCEPT_ALL_SSL_CAPABILITY = "acceptSslCerts";
  private static final String CHROME_SWITCHES = "chrome.switches";
  private static final String CHROME_IGNORE_SSL = "--ignore-certificate-errors";
  private static final String FIREFOX_ACCEPT_BAD_CERTS_CAPABILITY = "acceptInsecureCerts";

  @Override
  public DesiredCapabilities getCapabilities(DesiredCapabilities capabilities)
  {
    String sauceEnabledValue = System.getProperty(SAUCE_ENABLED_PROPERTY);
    String tunnelIdValue = System.getProperty(SAUCE_TUNNEL_PROPERTY);
    //This will just prevent the warning being printed when sauceconnect isn't enabled.
    if (!Strings.isNullOrEmpty(sauceEnabledValue) && Boolean.valueOf(sauceEnabledValue))
    {
      if (Strings.isNullOrEmpty(tunnelIdValue))
      {
        logger.warn("{} not set", SAUCE_TUNNEL_PROPERTY);
      }
      else
      {
        capabilities.setCapability(TUNNEL_CAPABILITY, tunnelIdValue);
      }
    }
    //There's a reason for this charlie foxtrot.  I don't always get to know what browser driver I'm
    //talking to.
    //Per selenium docs: "Whether the session should accept all SSL certs by default."
    //The DOWNSIDE: this seems to work with newer browser drivers, but it may not work with old ones.
    capabilities.setCapability(ACCEPT_ALL_SSL_CAPABILITY, true);
    //This *supposedly* works with some versions of IE.
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    //This *supposedly* works with some chrome versions.

    capabilities.setCapability(CHROME_SWITCHES, Collections.singletonList(CHROME_IGNORE_SSL));
    //Oh my god please work you STUPID FIREFOX
    //http://stackoverflow.com/a/40788935
    //https://bugzilla.mozilla.org/show_bug.cgi?id=1103196
    //Should work with firefox > v51
    capabilities.setCapability(FIREFOX_ACCEPT_BAD_CERTS_CAPABILITY,true);
    //When in doubt SET EVERYTHING!
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(false);
    capabilities.setCapability(FirefoxDriver.PROFILE,profile);
    capabilities.setCapability(FirefoxDriver.MARIONETTE,false);
    return capabilities;
  }
}
Teresa
  • 91
  • 2
  • 7
  • What exactly this class is intended for? How do you use it? Do you really need to extend `DefaultCapabilitiesBuilder` to create a custom set of capabilities? – Serhii Korol Sep 27 '17 at 19:22
  • I need to append a browser mob proxy proxy information to the tests. As well as if I'm using saucelabs for tests, I need to put in the sauce connect proxy information. – Teresa Sep 27 '17 at 19:35
  • That's fine. But I don't see any reason of using `DefaultCapabilitiesBuilder` here. You can do the same with a common java method, which returns `DesiredCapabilities`. That's why I'm asking you to show a code, where this class is used. – Serhii Korol Sep 27 '17 at 19:39
  • @SergeyKorol - This builder is injected via a JVM argument or via service loaders. – Krishnan Mahadevan Sep 29 '17 at 07:02
  • 1
    See [here](http://paypal.github.io/SeLion/html/documentation.html#additional-selenium-caps) (or) [1](https://github.com/paypal/SeLion/blob/develop/client/src/main/java/com/paypal/selion/internal/platform/grid/browsercapabilities/WebDriverFactory.java#L85) > [2](https://github.com/paypal/SeLion/blob/develop/client/src/main/java/com/paypal/selion/internal/platform/grid/browsercapabilities/UserCapabilitiesBuilder.java#L37-L39) > [3](https://github.com/paypal/SeLion/blob/develop/client/src/main/java/com/paypal/selion/internal/platform/grid/browsercapabilities/CapabilitiesHelper.java#L53-L63) – Krishnan Mahadevan Sep 29 '17 at 07:03
  • @Teresa - My guess is that you have a messed up CLASSPATH wherein something is bringing in an older selenium-api jar. Some details [here](https://github.com/SeleniumHQ/selenium/issues/3771) – Krishnan Mahadevan Sep 29 '17 at 07:04
  • @KrishnanMahadevan ah, it's a custom framework. Haven't noticed `selion` import. My bad. – Serhii Korol Sep 29 '17 at 07:13
  • @SergeyKorol - No worries. I was involved in building that framework. So I know its internals :) – Krishnan Mahadevan Sep 29 '17 at 07:18
  • So we're importing from the DefaultCapabilities builder in selion. https://github.com/paypal/SeLion/blob/develop/client/src/main/java/com/paypal/selion/platform/grid/browsercapabilities/DefaultCapabilitiesBuilder.java – Teresa Sep 29 '17 at 15:29

2 Answers2

3

Alright, turns out that my issue was because of a few dependencies in maven that got me all wrapped around the axle. I'm posting in hopes that if someone else runs into this issue that they can look here and figure out what's going on.

So for me, the following artifacts were not on the correct, matching version of selenium:

  • selenium-support
  • selenium-java
  • selenium-api

Once I corrected these to be the same version of selenium that I'm running (3.5.3) I was able to successfully get firefox opening without the exception I was getting before.

acdcjunior
  • 132,397
  • 37
  • 331
  • 304
Teresa
  • 91
  • 2
  • 7
1

I've been having this problem, my solution was adding/updating the pom.xml

 <!-- SELENIUM DEPENDENCIES ( WORKING VERSION )-->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.53.1</version>
    </dependency>
Kambaa
  • 467
  • 3
  • 8