在RFT中,一般关闭一个窗口对象使用的是对象的close方法,例如:
计算器window().close();
但是在某些情况下,可能需要采用下面两种更为灵活的方法:
方法1:
public void closeActiveWindow()
{
IWindow activeWindow = getScreen().getActiveWindow();
if ( activeWindow != null )
activeWindow.close();
}
这种方法先取到当前处于激活状态的窗口,然后作为IWindow对象调用其close方法来关闭窗口。
方法2:
public void acceptActiveWindow()
{
IWindow activeWindow = getScreen().getActiveWindow();
if ( activeWindow != null )
activeWindow.inputKeys("{ENTER}");
}
这种方法先取到激活状态的窗口,然后调用其inputkeys方法,发送回车键,一般会把窗口中的确定或取消按钮按下,从而关闭窗口。
关于getScreen和getActiveWindow,可参考RFT的帮助文档:
public static IScreen getScreen()
Returns an interface to the screen object. This is provided to allow scripting a solution for various situations. This method is never recorded. Any script that uses this method is probably platform specific.
Since:
RFT1.0
通过IScreen对象可以调用的方法如下:
IWindow windowFromHandle(long handle)
Returns a window object when given a native window handle.
Parameters:
handle
- The handle for the object
Returns:
IWindow the IWindow object for the handle
Detail description:
Given the handle, returns an IWindow
object
Example:
Given the handle, return the equivalent IWindow
long handle = 262476; //Handle for a window
IScreen scr = getRootTestObject().getScreen();
IWindow win =scr.getwindowFromHandle(handle);
Since:
RFT6.1.1.1
IWindow windowFromPoint(java.awt.Point point)
Returns a IWindow object at the given screen point.
Parameters:
point
- java.awt.Point The point on the screen
Returns:
IWindow The IWindow for the given point. The child's IWindow is given instead of the parent's IWindow
Detail description:
Return a IWindow
object when given a point. If the screen point is on a child window, the child, not the parent, is returned.
Example:
Get the IWindow object located at the screen point 10,10.
java.awt.Point pt = new java.awt.Point(10,10);
IScreen scr = getRootTestObject().getScreen();
IWindow win =scr.windowFromPoint(pt);
Since:
RFT6.1.1.1
IWindow getActiveWindow()
Returns the current active window.
Returns:
IWindow
Detail description:
Provides access to the current active visible IWindow
in the screen. The API can come to help in cases when the dialogs are not recognized.
Example:
Get the rectangle of the current active window
IScreen scr = getRootTestObject().getScreen();
IWindow win =scr.getActiveWindow();
java.awt.Rectangle rect = win.getScreenRectangle();
Since:
RFT6.1.1.1
java.awt.Point getMousePosition()
Returns the current screen location of the mouse pointer.
Returns:
java.awt.Point The current location of the cursor in the screen.
Detail description:
Use the method to gain access to current cursor location in the screen.
Example:
Get the current cursor location in the screen
IScreen scr = getRootTestObject().getScreen();
java.awt.Point screenPt =scr.getMousePosition;
Since:
RFT6.1.1.1
void inputKeys(java.lang.String keys)
Sends the key events to the current active window.
Parameters:
keys
- java.lang.String The keys to be sent to the current active window
Detail description:
In addition to sending characters, inputKeys helps in sending key strokes that of ALT, SHIFT, ENTER etc.. No window activation implicitly occurs. For detailed explanation of the key syntax, see inputKeys
.
Example:
Send "AB" to the top window that can consume the screen key events
IScreen scr = getRootTestObject().getScreen();
scr.inputKeys("+a+b");
Since:
RFT6.1.1.1
void inputChars(java.lang.String characters)
Sends the characters to the current active window
Parameters:
characters
- java.lang.String The characters to be sent to the current active window
Detail description:
The characters to the current active window are sent as a sequence of key events. No special interpretation of the characters (such as for inputKeys
) is used. No window activation implicitly occurs.
Example:
Send "AB" to the top window that can consume the screen key events
IScreen scr = getRootTestObject().getScreen();
scr.inputKeys("AB");
Since:
RFT6.1.1.1