从Spring框架启动firefoxDriver,设置Spring属性



我正试图从spring启动firefox网络驱动程序进行测试。我需要像在startFF方法中那样设置一个代理。有人能帮我做弹簧配置吗。

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>

我认为firefoxProfilebean应该将属性proxyReferences转换为firefoxProfile.setProxyPreferences(proxy)。但它抛出了一个无效的属性"proxyReferences"NotWritablePropertyException。

谢谢。

所以来回答我自己的问题。常驻大师帮了我一把。

看来spring只适用于真正的bean属性。proxyReferences不是一个真正的bean属性,它只有一个setter方法(setProxyPreferences)。Spring试图通过访问不存在的getProxyPreferences来验证其是否设置了变量。

感谢Jun.

最新更新