簡體   English   中英

Java Selenium:錯誤:無法訪問MutableCapabilities

[英]Java Selenium: error: cannot access MutableCapabilities

嘗試將我們的代碼更新為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;
  }
}

好吧,事實證明,我的問題是由於Maven中的一些依賴關系,使我全都陷入困境。 我發布的是希望如果有人遇到此問題,他們可以看看這里並弄清楚發生了什么。

因此,對我來說,以下工件不在正確,匹配的硒版本上:

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

一旦我將它們校正為與我正在運行的硒相同的版本(3.5.3),我便能夠成功打開Firefox,而沒有之前得到的異常。

我一直遇到這個問題,我的解決方案是添加/更新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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM