mmarquee.demo.TestMainWPFAutomationId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ui-automation Show documentation
Show all versions of ui-automation Show documentation
A Java library that wraps the MS UIAutomation library.
/*
* Copyright 2016-17 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package mmarquee.demo;
import com.sun.jna.platform.win32.WinDef;
import mmarquee.automation.*;
import mmarquee.automation.controls.*;
import mmarquee.automation.controls.menu.AutomationMainMenu;
import mmarquee.automation.controls.menu.AutomationMenuItem;
import mmarquee.automation.controls.mouse.AutomationMouse;
import mmarquee.automation.uiautomation.RowOrColumnMajor;
import mmarquee.automation.uiautomation.ToggleState;
import mmarquee.automation.utils.Utils;
import java.util.List;
/**
* Created by Mark Humphreys on 26/02/2016.
*
* Test the automation wrapper on a WPF application.
*/
public class TestMainWPFAutomationId extends TestBase {
public void run() {
UIAutomation automation = UIAutomation.getInstance();
AutomationApplication application = null;
try {
application = automation.launchOrAttach("apps\\WpfApplicationWithAutomationIds.exe");
} catch (Throwable ex) {
logger.warn("Failed to find application", ex);
}
// Wait for the process to start
// This doesn't seem to wait for WPF examples
application.waitForInputIdle(5000);
// Sleep for WPF, to address above issue
this.rest();
AutomationWindow applicationWindow = null;
try {
applicationWindow = automation.getDesktopWindow("MainWindow");
} catch (Exception ex) {
logger.info("Failed to find `MainWindow`");
}
try {
Object framework = applicationWindow.getFramework();
logger.info("Framework is " + framework.toString());
Object id = applicationWindow.getProcessId();
logger.info("Process = " + id.toString());
WinDef.POINT point = applicationWindow.getClickablePoint();
logger.info("Clickable point = " + point.toString());
String name = applicationWindow.getName();
logger.info(name);
try {
boolean val = applicationWindow.isModal();
logger.info(val);
} catch (Exception ex) {
logger.info("Ouch");
}
// BUTTONS ***********************************
logger.info("++ BUTTONS ++");
// NOTE: WPF buttons will set the automationID to be the name of the control
AutomationButton btnClickMe = applicationWindow.getButtonByAutomationId("idBtn1");
logger.info(btnClickMe.getName());
btnClickMe.click();
logger.info("++ ALL DONE ++");
} catch (Exception ex) {
logger.info("Something went wrong - " + ex.getClass());
}
}
}