我有一个典型的Web应用程序,它由Selenium WebDriver自动化。我的问题是自动化的一种特殊情况,其中有一个链接,该链接运行带有Java Web Start的swing应用程序,并且我想将自动化的控制权转移到Swing应用程序。这可能吗?我可以使用什么工具来做到这一点?而且,我该怎么办呢?提前致谢。
可以通过使用以下库来完成:
您可能可以使用其他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...
}
}
注意:uispec4j将截取该窗口,因此它将不可见。对我来说这不是问题,因此我没有调查是否可以看到它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句