Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从Spring框架启动firefoxDriver,设置Spring属性_Java_Spring_Webdriver - Fatal编程技术网

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

Java 从Spring框架启动firefoxDriver,设置Spring属性,java,spring,webdriver,Java,Spring,Webdriver,我正在尝试从spring启动FirefoxWebDriver进行测试。我需要像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

我正在尝试从spring启动FirefoxWebDriver进行测试。我需要像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();
    }
}

我认为firefoxProfile bean应该将属性proxyPreferences转换为firefoxProfile.setProxyPreferencesproxy。但它抛出了一个无效属性“proxyPreferences”NotWritablePropertyException


谢谢。

来回答我自己的问题。住院的导师帮了我这个忙

spring似乎只处理真正的bean属性。proxyPreferences不是一个真正的bean属性,它只有一个setter方法setProxyPreferences。Spring试图通过访问不存在的getProxyPreferences来验证它是否设置了变量

谢谢,小君

<?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>