Introduction
This page shows how to create your own custom UI Driver, UI Engine and UI Element classes (Button, TextBox, etc.)
Then you will see a simple automation test using all these custom classes.
UI Driver example
Here we will take a look at a simple example on how to create a custom UI Driver.
public class MyCustomDriver extends UiDriver { // create a logger, so we can debug the driver execution if we want private static Logger log = Logger.getLogger(MyCustomDriver.class); // if needed, we can do some initialization here // this code will be called before we obtain our custom engine @Override public void start() { log.info("Starting MyCustomDriver..."); } // if needed, we can do some cleanup here // this code will be called before the driver is stopped @Override public void stop() { log.info("Stopping MyCustomDriver..."); } // get the custom engine, so we can locate the custom UI elements public MyCustomEngine getEngine(){ return new MyCustomEngine(this); } }
UI Engine example
Here we will take a look at a simple example on how to create a custom UI Engine.
public class MyCustomEngine extends AbstractEngine implements IMyCustomEngine { // the factory, used to get custom UI elements from the map file private MyCustomElementsFactory myCustomElementsFactory; public MyCustomEngine(MyCustomDriver myCustomDriver) { super(myCustomDriver, MyCustomElementsFactory.getInstance()); this.myCustomElementsFactory = (MyCustomElementsFactory) elementsFactory; } // get custom element by locating it via UiElementProperties properties object public MyCustomElement getElement(UiElementProperties properties) { return new MyCustomElement(uiDriver, properties); } // get custom element by locating it via mapId public MyCustomElement getElement(String mapId) { return this.myCustomElementsFactory.getElement(mapId, uiDriver); } } // additional engine interface, for getting custom UI elements interface IMyCustomEngine{ public MyCustomElement getElement(UiElementProperties properties); public MyCustomElement getElement(String mapId); }
UI elements example
Here we will take a look at a simple example on how to create a custom UI ElementsFactory and custom UI Element
public class MyCustomElementsFactory extends AbstractElementsFactory { private static MyCustomElementsFactory instance; public static MyCustomElementsFactory getInstance() { if (instance == null) { instance = new MyCustomElementsFactory(); } return instance; } // get custom element by locating it via UiElementProperties properties object public MyCustomElement getElement(UiElementProperties properties, UiDriver uiDriver) { return new MyCustomElement(uiDriver, properties); } // get custom element by locating it via mapId public MyCustomElement getElement(String mapId, UiDriver uiDriver) { return getElement(elementsMap.getElementProperties(mapId), uiDriver); } } // the custom UIElement class MyCustomElement extends UiElement { public MyCustomElement(UiDriver uiDriver, UiElementProperties properties) { super(uiDriver, properties); } }
Test example
First you must load you custom driver, here are the extra steps compared to the already known UI engine examples:
// the full name of your custom UiDriver class String driverClassName = MyCustomUiDriver.class.getName(); // the parameter types for the constructor you want to use in order to instantiate the custom UiDriver Class[] constructorParameterTypes = new Class[]{String.class}; // arguments to be passed to the constructor Object[] constructorArguments = new Object[]{"http://www.someurl.com"}; // load the custom UiDriver class MyCustomDriver driver = (MyCustomDriver) UiDriver.getCustomDriver(driverClassName, constructorParameterTypes, constructorArguments);
And now you can use it in the regular way:
// start the driver driver.start(); // get the custom driver's engine MyCustomEngine engine = driver.getEngine(); // set the properties, which will be used to get the custom UiButton UiElementProperies properties = new UiElementProperties('id','sayHelloButton'); // get the button MyUiButton sayHelloButton = engine.getButton(properties); sayHelloButton.click(); // stop the driver driver.stop()
Back to parent page
Go to Table of Contents