我尝试使用 PhantomJS 驱动程序进行 Selenium 测试,但未能成功恢复我的 Firefox 配置文件以避免登录网站。 这是我的代码:
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Stackoverflow {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
System.setProperty("phantomjs.binary.path", System.getProperty("user.dir") + "/lib/phantomjs-2.1.1-windows/bin/phantomjs.exe");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
driver = new PhantomJSDriver(capabilities);
driver.manage().window().maximize();
baseUrl = "http://stackoverflow.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testStackoverflow() throws Exception {
driver.get(baseUrl);
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
你能告诉我如何设置 PhantomJS 驱动程序吗?
最佳答案
您无法将 firefox 配置文件与 PhantomJS 一起使用,因为您正在尝试将 firefox 配置文件与 PhantomJS 一起使用...PhantomJS 不是 firefox,您认为这会如何工作。
关于java - 无法在 Selenium 中将 PhantomJS 驱动程序与 Firefox 配置文件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38011039/