2017-09-27 78 views
2

嘗試更新我們的代碼硒3.x和我一直運行到一個錯誤被拋出,當我試圖運行我們的測試:Java的硒:錯誤:無法訪問MutableCapabilities

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; 
    } 
} 
+0

?你如何使用它?你真的需要擴展'DefaultCapabilitiesBuilder'來創建一組自定義的功能嗎? –

+0

我需要將瀏覽器暴徒代理代理信息附加到測試。以及如果我使用saucelabs進行測試,我需要輸入醬汁連接代理信息。 – Teresa

+0

這很好。但是我沒有看到在這裏使用'DefaultCapabilitiesBuilder'的任何理由。你可以用普通的java方法來做同樣的事情,該方法返回'DesiredCapabilities'。這就是爲什麼我要求你展示一個代碼,在哪裏使用這個類。 –

回答

3

好吧,事實證明,我的問題是因爲在行家幾個依賴這讓我周圍所有的軸包裹。我希望如果其他人遇到這個問題,他們可以在這裏看看並弄清楚發生了什麼。

所以對我來說,下面的文物不是硒的正確,匹配版本:

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

一旦我糾正這些是我正在運行的同一版本的硒(3.5.3)我能夠成功地獲得Firefox的開放,而不是我之前得到的例外。

0

我一直有這個問題,我 溶液中添加/更新究竟這個類用於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>