All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmarquee.demo.DemoGrid Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
/*
 * 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 java.util.List;

/**
 * Created by Mark Humphreys on 16/02/2017.
 *
 * Test the automation wrapper on a Delphi AutomatedGrid.
 */
public class DemoGrid extends TestBase {

    public void run() {
        UIAutomation automation = UIAutomation.getInstance();

        AutomationApplication application = null;

        try {
            application = automation.launchOrAttach("apps\\GridsDemo.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("Main Form");
        } catch (Exception ex) {
            logger.info("Failed to find `Demo Form`");
        }

        try {
            Object framework = applicationWindow.getFramework();
            logger.info("Framework is " + framework.toString());

            Object id = applicationWindow.getProcessId();
            logger.info("Process = " + id.toString());

            String name = applicationWindow.getName();
            logger.info(name);

            try {
                boolean val = applicationWindow.isModal();

                logger.info(val);
            } catch (Exception ex) {
                logger.info("Ouch");
            }

            // GRIDS ***********************************
            AutomationDataGrid grid = applicationWindow.getDataGrid("grdDemoGrid", "TJHCGrid");
            logger.info(grid.getName());

            // By convention, if there are no selected rows, then show the 'fields' memu of our grids
         //   grid.showContextMenu();

            AutomationDataGridCell cell1 = grid.getItem(1, 1);

            logger.info("value: " + cell1.getValue());

            List cells = grid.selectedRow();

            logger.info("size: " + cells.size());

            if (cells.size() != 0) {
                logger.info("value is " + cells.get(1).getValue());
            }

            AutomationDataGridCell cell3 = grid.getItem(3, 3);
            cell3.select();

            List cells0 = grid.selectedRow();

            logger.info("value is now " + cells0.get(1).getValue());

            logger.info("++ ALL DONE ++");

//            cell3.showContextMenu();
            cell3.invoke();

        } catch (Exception ex) {
            logger.info("Something went wrong - " + ex.getClass());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy