gpt4 book ai didi

java - Junit 中的远程 PhantomJS 驱动程序

转载 作者:行者123 更新时间:2023-11-30 09:21:46 27 4
gpt4 key购买 nike

如何在 junit 中使用远程 phantomjs 驱动器配置 selenium?我一直试图为此找到一个教程,但没有运气。我的目标是使用它在 spring mvc 中测试我的单页应用程序。

最佳答案

经过反复试验,我得出了以下解决方案。 Junit测试类中使用此配置

private URI siteBase;
private static PhantomJSDriverService service;
private WebDriver driver;
protected static DesiredCapabilities dCaps;

@BeforeClass
public static void createAndStartService() throws IOException {
service = new PhantomJSDriverService.Builder().usingPhantomJSExecutable(new File("/path/to/phantom/driver"))
.usingAnyFreePort()
.build();
service.start();
}
@AfterClass
public static void stopService() throws IOException {
service.stop();
}

@Before
public void setUp() throws Exception {
siteBase = new URI("http://localhost:8080/");
dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", false);

driver = new RemoteWebDriver(service.getUrl(),dCaps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

如果您需要更多信息,请在下方评论。

关于java - Junit 中的远程 PhantomJS 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16794721/

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