如何自动化运行单击链接到 Web 应用程序的 Swing Java Web 启动应用程序,该应用程序由 Selenium WebDriver 自动化? [英] How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?

查看:34
本文介绍了如何自动化运行单击链接到 Web 应用程序的 Swing Java Web 启动应用程序,该应用程序由 Selenium WebDriver 自动化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个典型的 Web 应用程序,它由 Selenium WebDriver 自动化.我的问题是一个特殊的自动化案例,其中我有一个链接,它使用 Java Web Start 运行一个 Swing 应用程序,我想将自动化控制权转移到 Swing 应用程序.这可能吗?我可以使用什么工具来做到这一点?而且,我该怎么做?提前致谢.

I have a typical web application, which is automated by Selenium WebDriver. My problem is a particular case of automation in which I have a link, which runs a swing app with Java Web Start, and I would like to transfer the control of the automation to the Swing app. is this possible? What tool can I use to do it? and, how can I do it? Thanks in advance.

推荐答案

  1. 点击webdriver中的jnlp文件链接,将jnlp文件保存到磁盘;
  2. 从 jnlp 运行 webstart 应用;
  3. 捕获打开的应用并将其用于测试.

可以使用以下库来完成:

It can be done by using following libraries:

  • netx (http://jnlp.sourceforge.net/netx/) - for running webstart application from jnlp
  • uispec4j (http://www.uispec4j.org/) - for intercepting created webstart window and manipulating window elements

你可能可以用其他 AWT/Swing 测试工具做同样的事情,但是 uispec4j 允许拦截从 jnlp 执行的 webstart 应用程序,你不需要通过调用 main() 来运行应用程序,你不需要在您的测试代码仓库中包含您的 webstart 应用程序源代码.我在使用其他库(包括 Jemmy)时遇到了问题.

You can probably do the same trick with other AWT/Swing testing tool, but uispec4j allows to intercept webstart app executed from jnlp, you don't need to run the app by calling main() and you don't need to have your webstart app source code in your testing code repo. I had problems to achieve this with other libs, including Jemmy.

这对我有用:

import java.io.File;    
import javax.swing.JTextField;  
import netx.jnlp.JNLPFile;
import netx.jnlp.Launcher;
import org.junit.Assert;
import org.junit.Test;
import org.uispec4j.Trigger;
import org.uispec4j.UISpecAdapter;
import org.uispec4j.UISpecTestCase;
import org.uispec4j.Window;
import org.uispec4j.interception.WindowInterceptor;

public class WebstartTest extends UISpecTestCase {

    @Test
    public void test() throws Exception {
        // click your webdriver link, save the jnlp file to disk
        final File file = new File("file.jnlp");
        final JNLPFile jnlp = new JNLPFile(file.toURI().toURL());

        // adapter is a UISpec4j way to allow capturing windows created in 
        // non-standard way, exactly what we need.
        this.setAdapter(new UISpecAdapter() {
            @Override
            public Window getMainWindow() {
                return WindowInterceptor.run(new Trigger() {
                    @Override
                    public void run() throws Exception {
                        // running jnlp by netx launcher 
                        Launcher launcher = new Launcher();
                        launcher.setCreateAppContext(false);
                        launcher.launch(jnlp);
                    }
                });
            }
        });

        Window w = this.getMainWindow();

        // verify if window's components are there
        Assert.assertEquals("text", ((JTextField) w.getSwingComponents(JTextField.class)[0]).getText());

        // manipulate window components...
    }
}

注意:uispec4j 会拦截窗口,所以它不会变得可见.这对我来说不是问题,所以我没有调查是否可以让它可见.

Note: uispec4j will intercept the window, so it won't become visible. It wasn't a problem for me, so I didn't investigate if making it visible is possible.

这篇关于如何自动化运行单击链接到 Web 应用程序的 Swing Java Web 启动应用程序,该应用程序由 Selenium WebDriver 自动化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆