gpt4 book ai didi

java - 如何让 Selenium 选择我的 .pac 文件?

转载 作者:行者123 更新时间:2023-12-01 05:40:27 28 4
gpt4 key购买 nike

我在 Firefox 中使用 Foxyproxy,每当我想切换到沙箱环境时,我都会使用 .pac 文件。生活是美好的。

但是当我尝试使用基于浏览器的测试实用程序(如 Selenium)进行自动化时,我无法使其通过我的 Sandbox .pac 代理。如何实现呢?我正在使用 JUnit。这是我的示例代码。

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;

public class TestCase1 extends SeleneseTestCase {

Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS = "60000";
private SeleniumServer seleniumServer;

public void setUp() throws Exception {

RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setSingleWindow(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox",
"https://mywebsite.com/");
seleniumServer.start();
selenium.start();
}

public void testLogin() {
selenium.open("/");
selenium.type("id=user_name", "test");
selenium.type("id=password", "test");
selenium.click("css=input.btn");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Signed in successfully"));
}

public void tearDown() throws InterruptedException {
selenium.stop();
seleniumServer.stop();
}
}

最佳答案

这个问题背后的主要目标是在 Windows 环境中在 Firefox 中运行 Selenium 测试。我为此做了一个解决办法。我打开了 Internet Explore,转到“Internet 选项”,然后转到“连接”并在那里设置自动 .pac 配置。答对了!它起作用了。

关于java - 如何让 Selenium 选择我的 .pac 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318322/

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