【问题标题】:Remote PhantomJS driver in JunitJunit 中的远程 PhantomJS 驱动程序
【发布时间】:2013-05-23 13:58:05
【问题描述】:

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

【问题讨论】:

    标签: java selenium junit phantomjs


    【解决方案1】:

    经过反复试验,我得到了以下解决方案。这个配置在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();
    }
    

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

    【讨论】:

    • 这个在 Spring MVC 控制器中是如何使用的?
    • 不确定你的意思。这使我可以调用外部(phantomjs)测试驱动程序并对我在春季制作的 Web 应用程序进行功能测试。我认为使用 Node.js 或 Ruby 以及像 capybara 这样的测试框架可以更好地实现这一点。我在这个练习中了解到,通过 JUnit 运行 phantomjs 非常有效。让测试花费更长的时间。
    • 你能看看我提出的这个问题吗:stackoverflow.com/questions/21949689/… ?我想做我的网页截图,其中 PhantomJS 由 Java 触发到视图。我同意,这需要更长的时间:(
    猜你喜欢
    • 2013-07-22
    • 1970-01-01
    • 2017-09-11
    • 2018-02-09
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2017-03-26
    • 2015-09-17
    相关资源
    最近更新 更多