2012-01-29 4 views
1

私は、firefox webdriverをSpringからテストを開始しようとしています。 startFFメソッドのようにプロキシを設定する必要があります。誰かがスプリング設定で私を助けてくれますか?spring frameworkからfirefoxDriverを起動し、springプロパティを設定します。

package stephenn.info; 

import static org.junit.Assert.*; 

import java.io.File; 

import javax.annotation.Resource; 

import org.junit.Test; 
import org.openqa.selenium.Proxy; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxBinary; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
import org.springframework.test.context.ContextConfiguration; 
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; 

@ContextConfiguration(locations = "/applicationContext.xml") 
public class searchTitleTest extends AbstractJUnit4SpringContextTests { 

    @Resource 
    WebDriver webDriver; 

    @Resource 
    Proxy proxy; 

    @Resource 
    FirefoxProfile firefoxProfile; 

    @Test 
    public void testTitle(){ 
     assertTrue(true); 
    } 

    private void startFF(){ 
     Proxy myProxy = new Proxy(); 
     proxy.setHttpProxy("192.168.1.23"); 
     firefoxProfile.setProxyPreferences(myProxy); 
     firefoxProfile.setProxyPreferences(proxy); 
     File ffpath = new File("/usr/bin/firefox"); 
     FirefoxBinary binary = new FirefoxBinary(ffpath); 
     FirefoxDriver ffdriver = new FirefoxDriver(binary,firefoxProfile); 
     ffdriver.close(); 
    } 
} 

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> 

    <bean id="proxy" class="org.openqa.selenium.Proxy" /> 
    <bean id="firefoxProfile" class="org.openqa.selenium.firefox.FirefoxProfile"> 
     <property name="proxyPreferences"> 
     <ref bean="proxy" /> 
     </property> 
    </bean> 
    <bean class="org.openqa.selenium.firefox.FirefoxDriver" id="webDriver" destroy-method="close" /> 
</beans> 

私はfirefoxProfile BeanがfirefoxProfile.setProxyPreferences(プロキシ)にプロパティproxyPreferencesを翻訳すべきだと思います。しかし、それは無効なプロパティ 'proxyPreferences' NotWritablePropertyExceptionを投げる。

ありがとうございました。

答えて

0

私自身の質問に答えてください。居住の教祖は私にこれを手伝った。

春は実際のビーンプロパティでのみ動作しているようです。 proxyPreferencesは実際のBeanプロパティではなく、setterメソッド(setProxyPreferences)しかありません。 SpringはgetProxyPreferencesにアクセスすることで変数を設定しているかどうかを検証しようとしていますが、存在しません。

ありがとう6月

関連する問題