如何自动化它运行点击一个链接到一个Web应用程序,这是与硒的webdriver自动摆动Java Web Start应用? [英] How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?

查看:308
本文介绍了如何自动化它运行点击一个链接到一个Web应用程序,这是与硒的webdriver自动摆动Java Web Start应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个典型的web应用,这是由硒的webdriver自动化。我的问题是自动化,我有一个链接,它运行使用Java Web Start一个Swing应用程序的特定情况下,我想自动化的控制转移到Swing应用程序。这可能吗?什么工具,我可以用它来做到这一点?而且,我该怎么办呢?先谢谢了。


解决方案

  1. 单击在webdriver的JNLP文件的链接,保存JNLP文件到磁盘;

  2. 运行从JNLP的Webstart的应用;

  3. 拍摄打开应用程序,并用它来测试。

它可以通过使用以下库来完成:

您也许可以做其他AWT / Swing的测试工具同样的伎俩,但uispec4j可以拦截从JNLP执行Webstart的应用程序,你并不需要通过调用主(运行程序),你不需要有你在webstart应用程序的源$ C ​​$ C在测试code回购。我有问题,与其他库,包括Jemmy实现这一目标。

下面是我工作:

 进口的java.io.File;
进口javax.swing.JTextField中;
进口netx.jnlp.JNLPFile;
进口netx.jnlp.Launcher;
进口org.junit.Assert;
进口org.junit.Test;
进口org.uispec4j.Trigger;
进口org.uispec4j.UISpecAdapter;
进口org.uispec4j.UISpecTestCase;
进口org.uispec4j.Window;
进口org.uispec4j.interception.WindowInterceptor;公共类WebstartTest扩展UISpecTestCase {    @测试
    公共无效测试()抛出异常{
        //单击您的webdriver的环节,节省JNLP文件到硬盘
        最终文件的文件=新的文件(file.jnlp);
        最后JNLPFile JNLP =新JNLPFile(file.toURI()的toURL());        //适配器是一个UISpec4j方式,让捕捉创建的窗口
        //非标准的方式,正是我们需要的。
        this.setAdapter(新UISpecAdapter(){
            @覆盖
            公共窗口getMainWindow(){
                返回WindowInterceptor.run(新触发器(){
                    @覆盖
                    公共无效的run()抛出异常{
                        //由NETX发射运行JNLP
                        发射器发射器=新发射();
                        launcher.setCreateAppContext(假);
                        launcher.launch(JNLP);
                    }
                });
            }
        });        窗口W = this.getMainWindow();        //验证,如果窗口的组成部分是有
        Assert.assertEquals(文字,((JTextField中)w.getSwingComponents(JTextField.class)[0])的getText());        //操作窗口组件...
    }
}

请注意:uispec4j将截取的窗口,所以不会变得可见。这是不是我的问题,所以如果使其可见有可能我没有调查。

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. Click the jnlp file link in webdriver, save jnlp file to disk;
  2. Run the webstart app from jnlp;
  3. Capture opened app and use it for test.

It can be done by using following libraries:

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.

Here is what worked for me:

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...
    }
}

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应用程序,这是与硒的webdriver自动摆动Java Web Start应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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