4

尝试通过属性在 Cucumber 中设置代理(到 OWASP ZAP 代理端口),但不可用。

黄瓜.xml

  <beans profile="firefoxRemote">
        <bean name="capability" init-method="firefox"
              class="org.openqa.selenium.remote.DesiredCapabilities">
            <property name="browserName" value="firefox"/>
            <property name="version" value="42.0"/>
            <property name="PROXY" value="127.0.0.1:8090"/>
        </bean>

我也可以在 CucumberRunner 中设置,但不知道怎么设置。

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/java/com/features"},
        glue = "com.mycompany.steps",
        format = {"pretty", "html:target/cucumber", "json:target/cucumber.json"},
        tags = {"~@ignore"})
public class CucumberRunner {
}

有人知道如何以及在哪里正确设置吗?

使用 Selenium 和 Webdriver 我可以这样做:

public class ZAPRunner {

    private WebDriver driver;
    private String site = "http://localhost:8080/app";

    public void setUp() throws Exception {
        Proxy proxy = new Proxy();
        proxy.setHttpProxy("localhost:8090");
        proxy.setFtpProxy("localhost:8090");
        proxy.setSslProxy("localhost:8090");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, proxy);
        driver = new FirefoxDriver(capabilities);
        this.setDriver(driver);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
    protected void setDriver(WebDriver driver) {
        this.driver = driver;
    }


    public static void main(String[] args) throws Exception {
        ZAPRunner test = new ZAPRunner();
        test.setUp();

    }

}

但是如何用 Cucumber 实现这一点?我想用 Cucumber,因为里面已经写好了测试。

谢谢,

4

0 回答 0