About
To simulate user actions on application windows (maximization, minimization and so on), use the following methods –
Use the methods that the IWindow
and ITopLevelWindow
interfaces provide:
Activate
- Activates the top-level window.Maximize
- Maximizes the top-level window.Minimize
- Minimizes the top-level window.Position
- Sets the position and size of the top-level window.Restore
- Restores the minimized top-level window.SetFocus
- Moves the input focus to a top-level window or to a control (since controls are windows).
Use the methods that the Window
and TopLevelWindow
classes provide:
activate
- Activates the top-level window.maximize
- Maximizes the top-level window.minimize
- Minimizes the top-level window.position
- Sets the position and size of the top-level window.restore
- Restores the minimized top-level window.setFocus
- Moves the input focus to a top-level window or to a control (since controls are windows).
Example
The sample code below demonstrates how to minimize and then restore Notepad's window (Notepad must be running):
C#
using SmartBear.TestLeft;
using SmartBear.TestLeft.TestObjects;
…
public void Test()
{
ITopLevelWindow wndNotepad = Driver.Find<IProcess>(new ProcessPattern()
{
ProcessName = "notepad"
}).Find<ITopLevelWindow>(new WindowPattern()
{
WndClass = "Notepad"
});
wndNotepad.Minimize();
wndNotepad.Restore();
}
Visual Basic .NET
Imports SmartBear.TestLeft
Imports SmartBear.TestLeft.TestObjects
…
Public Sub Test()
Dim wndNotepad As ITopLevelWindow = Driver.Find(Of IProcess)(New ProcessPattern() With {
.ProcessName = "notepad"
}).Find(Of ITopLevelWindow)(New WindowPattern() With {
.WndClass = "Notepad"
})
wndNotepad.Minimize()
wndNotepad.Restore()
End Sub
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;
…
@Test
public void Test() throws Exception{
TopLevelWindow wndNotepad = driver.find(TestProcess.class, new ProcessPattern() {{
ProcessName = "notepad";
}}).find(TopLevelWindow.class, new WindowPattern() {{
WndClass = "Notepad";
}});
wndNotepad.minimize();
wndNotepad.restore();
}
Capturing Images of Application Windows
It may be difficult to determine the state of the tested window before simulating user actions. You can enable TestLeft Visualizer to capture images of the tested application’s windows automatically.
See Also
Simulating User Actions
Creating TestLeft Tests
About Driver Objects
Object Identification