当前位置: 首页 > 知识库问答 >
问题:

JavaSelenium:错误:无法访问MutableCapables

傅旺
2023-03-14

正在尝试将代码更新为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;
  }
}

共有2个答案

赵浩邈
2023-03-14

我一直遇到这个问题,我的解决方案是添加/更新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>
微生俊捷
2023-03-14

好吧,原来我的问题是因为maven中的一些依赖项让我完全被轴缠住了。我发帖是希望如果其他人遇到这个问题,他们可以在这里查看并弄清楚发生了什么。

因此,对我来说,以下工件不在selenium的正确匹配版本上:

  • 硒-支持
  • 硒-java
  • 硒-api

一旦我将这些更正为我正在运行的相同版本的selenium(3.5.3),我就能够成功地打开Firefox,而不会像之前那样出现异常。

 类似资料:
  • 遥不可及!更改:false,msg:SSH错误:无法将数据发送到远程主机。确保可以通过ssh访问此主机,“不可访问”:true 主持人: ansible.cfg 我正在使用executeshell运行Jenkins的剧本`

  • 我正在通过 Windows(10) 启动时的批处理文件启动我的应用程序。这是我在批处理文件中的内容 - 当windows启动时,我得到了 无法访问文件.jar 然而,问题是在这个错误消息之后,应用程序仍然在启动中,并且运行良好。正在访问jar但我仍然无法访问jar错误的原因是什么,如何避免它?找不到这个特定案例的任何答案。

  • 我面临着这个问题;我知道这个问题已经出现了,我已经尝试了上面提到的解决方案,因此用我的配置和代码问了这个问题。 之前的脚本正在运行,但现在没有,所以我试着制作一个基本的开放浏览器脚本。 Selenium WebDriver的最新版本:http://selenium-release.storage.googleapis.com/3.5/selenium-java-3.5.0.zip ChromeDr

  • 我已经从JMeter插件管理器下载了“命令行图形绘制工具”和“JPGC-Standard Set”。 我从jmeter/lib/ext路径执行以下命令:命令1:Java-jar cmdrunner.jar--工具报告器--生成-csv C:\jtl\aggregate_report.csv--输入-jtl C:\jtl\file1.jtl--plugin-type AggregateReport-

  • null 它制作了一个带有Manifest.mf的罐子,其中包含: 这些都是在click-the-block.jar中提取到我的桌面的 当我双击时,什么也没有发生。 当我在CMD中键入“java-jar click-the-block.jar”时,我得到以下错误:

  • 我有osgi项目。每个包都是一个单独的maven项目。项目足够大,包括大约10个包。一切正常,一切正常。 在org.apache.maven.plugin.abstractCompilerMojo.execute(abstractCompilerMojo.java:656)在org.apache.maven.plugin.compilerMojo.execute(compilerMojo.java