gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:30:34 24 4
gpt4 key购买 nike

我正在尝试从 Spring 启动 Firefox WebDriver 进行测试。我需要像 startFF 方法中那样设置代理。有人可以帮我配置 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 应该将属性 proxyPreferences 转换为 firefoxProfile.setProxyPreferences(proxy)。但它抛出了无效的属性“proxyPreferences”NotWritablePropertyException。

谢谢。

最佳答案

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

Spring 似乎只适用于真实的 bean 属性。 proxyPreferences 不是真正的 bean 属性,它只有一个 setter 方法 (setProxyPreferences)。 Spring 正在尝试通过访问 getProxyPreferences 来验证其是否设置了变量,但 getProxyPreferences 并不存在。

谢谢君。

关于java - 从Spring框架启动firefoxDriver,设置spring属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com