我嘗試在我的Selenium測試中使用PhantomJS驅動程序,但我沒有成功恢復我的Firefox配置文件以避免我在網站中登錄。 這是我的代碼:無法在Selenium中使用PhantomJS驅動程序和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或其他的解決方案。 – Steefler35