1

在我的测试环境中,我们有执行某些操作的类,其中一些使用 SilkTest 的东西。测试过程由我们解析、转换为 ActionImpl 类和执行操作的 XML 文件定义。比如下面会登录我们的app,切换用户,然后重启服务器:

<Script refBean="validateState" retry="false">
    <DataGroups>
        <Step action="log" mod="5.10.13 - Step 1" />
        <Step action="switchUsers" target="mlane" />
        <Step action="restartServer" />
    </DataGroups>
</Script>

restartServer操作的情况下,代码最终会调用以下方法,该方法使用正在运行eclipse.exe的测试创建一个 BaseState。

private PassFail restartServerInEclipse() {
    Desktop desktop = new Desktop();
    BaseState eclipseBaseState = new BaseState("*eclipse.exe", "/Shell[@caption='Java EE*']", TechDomain.SWT, TechDomain.XBROWSER, TechDomain.WIN32);
    desktop.executeBaseState(eclipseBaseState);
    // Do some stuff, like finding CTabItem objects, clicking them, etc.
    return passFail;
}

假设我正在运行当天的第一个测试。我刚开始工作,并决定进行测试。如果代码执行restartServer操作并调用restartServerInEclipse(),它将识别当前正在运行的eclipse.exe,并成功地对我告诉它的任何 Silk 对象执行任何 Silk 方法。

但是,在没有退出 Eclipse 或 Open Agent 的情况下,在测试完成后,如果我再次运行相同的测试,例如全新的对象、全新的测试线程,测试会运行并停止,然后我单击 Eclipse 中的绿色运行按钮再次,当它到达BaseState eclipseBaseState = new BaseState(...)代码时,我收到以下错误:

com.borland.silktest.jtf.common.LaunchApplicationFailedException: Failed to start application '*eclipse.exe' in working directory 'null'. The system cannot find the file specified.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.borland.silktest.jtf.agent.ExceptionTranslatorUtil.createException(ExceptionTranslatorUtil.java:60)
    at com.borland.silktest.jtf.agent.ExceptionTranslatorUtil.translate(ExceptionTranslatorUtil.java:37)
    at com.borland.silktest.jtf.agent.JtfModule.executeBaseState_aroundBody39$advice(JtfModule.java:121)
    at com.borland.silktest.jtf.agent.JtfModule.executeBaseState(JtfModule.java:1)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy24.executeBaseState(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
    at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
    at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
    at org.springframework.remoting.rmi.RmiBasedExporter.invoke(RmiBasedExporter.java:72)
    at org.springframework.remoting.rmi.RmiInvocationWrapper.invoke(RmiInvocationWrapper.java:72)
    at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    at org.springframework.remoting.support.RemoteInvocationUtils.fillInClientStackTraceIfPossible(RemoteInvocationUtils.java:47)
    at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:351)
    at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:258)
    at com.borland.silktest.startservice.RmiConnectionUtil$1.invoke(RmiConnectionUtil.java:134)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.executeBaseState(Unknown Source)
    at com.borland.silktest.jtf.Agent.executeBaseState(Agent.java:452)
    at com.borland.silktest.jtf.BaseState.execute(BaseState.java:298)
    at com.borland.silktest.jtf.Desktop.executeBaseState(Desktop.java:69)
    at scripts.misc.validation.action.RestartServerActionImpl.restartServerInEclipse(RestartServerActionImpl.java:62)
    at scripts.misc.validation.action.RestartServerActionImpl.evaluate(RestartServerActionImpl.java:25)
    at scripts.misc.validation.ValidateState.evaluateStep(ValidateState.java:108)
    at scripts.misc.validation.ValidateState.script(ValidateState.java:131)
    at scripts.base.BaseScript.runWithRetries(BaseScript.java:204)
    at scripts.base.BaseScript.runIt(BaseScript.java:312)
    at suite.MainThread.script(MainThread.java:667)
    at suite.MainThread.run(MainThread.java:281)

两秒前完全正常工作的基本状态现在不正确。好像一旦初始设置了基本状态,Eclipse 的某些内容就会发生变化,因此它无法重新识别它。

解决这个问题的唯一方法是重新启动 Eclipse 和 Open Agent,但即使这样有时也不起作用,而且我偶尔会遇到一些 OA 的许可证服务器问题,这需要重新启动计算机。

4

1 回答 1

1

从您发布的日志文件中,我可以看到您正在测试eclipse.exeiexplore.exe. 当前构建脚本的方式是其中一种。这意味着一旦您切换到 Internet Explorer,Silk Test 就会从 Eclipse 中分离,并且将不再识别该窗口。

由于无论如何您都是通过其他机制启动应用程序,因此我建议使用该attach方法,该方法是累积的并且将添加模式而不是替换它,因此您将避免在应用程序之间切换。

Desktop desktop = new Desktop();
desktop.attach("*\\eclipse.exe", TechDomain.SWT, TechDomain.XBROWSER, TechDomain.WIN32);
desktop.attach("*\\iexplore.exe", TechDomain.SWT, TechDomain.XBROWSER, TechDomain.WIN32);
Shell eclipse = desktop.find("/Shell[@caption='Java EE*']");
BrowserApplication browserApp = desktop.find("/BrowserApplication");
于 2012-11-27T06:52:24.227 回答