Запуск firefoxDriver из среды Spring, настройка свойств Spring - PullRequest
1 голос
/ 29 января 2012

Я пытаюсь запустить веб-драйвер 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>

Я думаю, что bean-компонент firefoxProfile должен преобразовать свойство proxyPreferences в firefoxProfile.setProxyPreferences (proxy). Но он выбрасывает недопустимое свойство 'proxyPreferences' NotWritablePropertyException.

Спасибо.

1 Ответ

0 голосов
/ 30 января 2012

Итак, чтобы ответить на мой собственный вопрос.Гуру-резидент помог мне в этом.

Кажется, весна работает только с реальными свойствами бобов.proxyPreferences не является реальным свойством бина, у него есть только метод установки (setProxyPreferences).Spring пытается проверить, что он установил переменную, обращаясь к getProxyPreferences, который не существует.

Спасибо Jun.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...