如何自动运行 Swing java web start 应用程序,该应用程序运行单击链接进入 web 应用程序,这是使用 Selenium WebDriver 自动化的?

Jul*_*sar 2 java swing selenium automation webdriver

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

tpo*_*eba 5

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

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

您可能可以使用其他 AWT/Swing 测试工具执行相同的技巧,但 uispec4j 允许拦截从 jnlp 执行的 webstart 应用程序,您不需要通过调用 main() 来运行该应用程序,也不需要您的 webstart测试代码存储库中的应用源代码。我在使用其他库(包括 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...
    }
}
Run Code Online (Sandbox Code Playgroud)

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