试图将我们的代码更新到Selenium 3.x,当我试图运行我们的测试时,我总是遇到一个抛出的错误:
error: cannot access MutableCapabilities同样的代码过去在运行测试时也是有效的,我真的不确定它会在哪里或者为什么会出现这样一个奇怪的错误。我似乎找不到任何人之前写过的东西,所以我希望stackoverflow社区能帮助我解决这个问题。
以下是生成此错误的代码:
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;
}
}发布于 2017-09-30 04:09:30
好吧,事实证明,我的问题是因为maven中的一些依赖项让我完全被轴缠住了。我发帖是希望如果其他人遇到这个问题,他们可以看看这里,弄清楚是怎么回事。
因此,对我来说,以下工件不是在正确的、匹配的selenium版本上:
selenium-supportselenium-javaselenium-api一旦我将它们更正为与我正在运行的selenium版本(3.5.3)相同的版本,我就能够成功地打开firefox,而不会出现之前得到的异常。
发布于 2018-03-07 19:30:18
我一直有这个问题,我的解决方案是添加/更新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>https://stackoverflow.com/questions/46455229
复制相似问题