This documentation supports the 20.02 version of BMC Helix Platform.

To view the documentation for the current version, select 20.08 from the Product version menu.

UI automation framework methods and sample code

The UI automation framework provides a comprehensive set of methods for testing BMC Helix Platform based UI elements and custom UI elements.

The following sections describe how to  use several of the UI element methods that are provided by the UI automation framework.

Consider a sampleView view definition that contains BMC Helix Platform UI elements such as Record Editor(sampleEditor), Record Grid (sampleGrid), and so on. After you use the Page class loader utility to create the page classes for the sampleView view definition, you can use the UI element methods provided by the UI automation framework to create test cases. The UI element classes are located in the com.bmc.rx.test.framework.elements package.

UI automation sample: Initializing a view definition

The UI automation framework uses JGiven, which provides the stage classes such as TestUIGivenState, TestUIWhenState, TestUIThenState, and so on.

The following code illustrates how to initialize the example view definition (sampleView):

sampleView myView = new sampleView (driver, errorHandler)

The driver and errorHandler are initialized in the Baseclasses such as BaseUITestGiven, BaseUITestWhen, and BaseUITestThen.

UI automation sample: Testing a record editor element

Use the Record Editor (sampleEditor) examples to test the UI elements in the following table. The following table contains the available classes and example code:

UI element

UI element classAction

Example

Attachment

AttachmentFieldUploads a file
File resume = new File("C:\\temp\text.txt");
myView.sampleEditor.Attachment().setData(resume);
Gets the file name of the file that is uploaded
myView.sampleEditor.Attachment().getData();

Boolean

BooleanFieldSets the value of a Boolean field to true
myView.sampleEditor.boolean().setData("True");
Sets the value of a Boolean field to false
myView.sampleEditor.boolean().setData("False");
Gets a Boolean field value
myView.sampleEditor.boolean().getData();

Button

ButtonField

Clicks a button

myView.Save().click();    

Date

DateFieldSets data for a Date field and pass the data in the string format, "YYYY-MM-DD"
myView.sampleEditor.Date().setData("2017-10-30");

DateTime

DateTimeField

Sets a Date field and pass the data in the string format YYYY-MM-DD

myView.sampleEditor.DateTime().setData("2017-10-30,01:05:AM");

Time

TimeField

Sets data for a Time field and pass the data in the string format, "HH:MM:AM"

myView.sampleEditor.Time().setData("01:05:AM");

Drop down

(single selection)

DropDownFieldSelects the DropDown field
myView.sampleEditor.DropDownField().setData("Monday");

Drop down

(Multi-select )

MultiSelectFieldSets multiple values
List<String> countries = Arrays.asList("PAK", "BAN", "AUS");
myView.sampleEditor.MultiSelectDropDownField().setData(countries);

Decimal, Floating

DecimalField, FloatingFieldProvides a value to a Decimal field
myView.sampleEditor.DecimalField().setData("3.14");
IntegerIntegerFieldProvides a value to an Integer field
myView.sampleEditor.IntegerField().setData("10");
TextArea, TextTextAreaField, TextFieldProvides a value to a TextArea field
myView.sampleEditor.TextAreaField().setData("Hello World.");

UI automation sample: Testing a record grid

Use the following examples to test the record grid UI element:

UI elementUI element classAction

Example

Record GridRecordGridFieldGets all of the values from a specific column
myView.RecordGridField().getAllValuesFromColumn("Description")
Selects a specific row
myView.RecordGridField().selectRowByUniqueColumnValue("Month","February");
Applies a filter
List<String> monthsToBeSelected = Arrays.asList("January", "November");
myView.RecordGridField()
      .openFilter()
      .selectCheckBoxes(monthsToBeSelected,"Month")
      .applyFilter();

UI automation sample: Testing the Approval Console

Use the ApprovalConsole class methods to test the Approval Console interface. The following table contains the available methods and examples:

MethodDescriptionExample
clickOnTab(String)Selects a tab in the approve console such as Pending, On Hold, and so on.
myView.testApproveConsoleElement().clickOnTab("Pending");
getRequestCount()Provides the row count.
myView.testApproveConsoleElement().clickOnTab("Pending");     
 int pendingCount = 
sampleUIPage.testApproveConsoleElement().getRequestCount();
selectMoreViewOptions(String)Selects the More Views tab in the Approval Console.
myView.testApproveConsoleElement().selectMoreViewOptions("Approved");
selectRecordDefinitionByIndex(intValue)Selects a grid row based on the index specified.
myView.testApproveConsoleElement().selectRecordDefinitionByIndex(1);
deselectRecordDefinitionByIndex(intValue)Deselects a  grid row based on the index specified.
myView.testApproveConsoleElement().deselectRecordDefinitionByIndex(1);

selectRecordDefinitionBasedOnUniqueCellValue(columnName, Value)

Selects a record definition based on the column value specified.
myView.testApproveConsoleElement().selectRecordDefinitionBasedOnUniqueCellValue
("RecordDefinition","com.bmc.example.apr-assig-config-test:TestRecord_Console3520");

deselectRecordDefinitionBasedOnUniqueCellValue(columnName, Value)

Deselects a record definition based on the column value specified.
myView.testApproveConsoleElement().deselectRecordDefinitionBasedOnUniqueCellValue
("RecordDefinition","com.bmc.example.apr-assig-config-test:TestRecord_Console3520");
clickRefresh()Refreshes record grid.
myView.testApproveConsoleElement().clickRefresh();
performAction(String)Clicks an action in the Approve Console such as Approve, Reject, and Hold.
myView.testApproveConsoleElement().selectRecordDefinitionByIndex(1);  
 
myView.testApproveConsoleElement().performAction("Approve");
clickOkButton()Clicks the OK button in a dialog box.
myView.testApproveConsoleElement().performAction("Approve");  
myView.clickOkButton();
initiateReassignDialogAndAssign(userName)Clicks the Reassign button in a task and assigns the  task to the specified user.
myView.testApproveConsoleElement().initiateReassignDialogAndAssign("admin_ta");
openVisibleColumnsDropDown()Opens the Visible Column list to add or remove a column in the record grid.
myView.testApproveConsoleElement().openVisibleColumnsDropDown();
selectCheckBoxInVisibleColumnsMenuByText(String)Selects the specified string in the Visible Column menu.
myView.testApproveConsoleElement().selectCheckBoxInVisibleColumnsMenuByText
("Justification");
deselectCheckBoxInVisibleColumnsMenuByText(String)Deselects the specified string in the Visible Column menu.
myView.testApproveConsoleElement().deselectCheckBoxInVisibleColumnsMenuByText
("Justification");
closeVisibleColumnsDropDown()Closes the Visible Column list.
myView.testApproveConsoleElement().closeVisibleColumnsDropDown();

initiateQuestionDialogAndAddQuestion(UserName, Question)

Clicks the New button in the Questions tab and adds a question.
myView.testApproveConsoleElement().clickOnTab("Questions");    
 
myView.testApproveConsoleElement().initiateQuestionDialogAndAddQuestion
("admin_ta","reason for this request");
initiateAndEnterCommentsDialog(userName)Clicks the New button in the Comments tab and adds a comment.
myView.testApproveConsoleElement().clickOnTab("Comments");   
 
myView.testApproveConsoleElement().initiateAndEnterCommentsDialog("test");
getRequestFieldValues()Provides the list of request field values in a request.
List<String> list = myView.testApproveConsoleElement().getRequestFieldValues();
getRequestFieldNames()Provides the list of request field names in a request.
List<String> list1 = myView.testApproveConsoleElement().getRequestFieldNames();
setSearchText(String)Searches record instances based on the search text.
myView.testApproveConsoleElement().setSearchText("com.bmc.example.apr-assig-config-test:TestRecord_Console9118");

UI automation sample: Testing the BMC Modern Shell

Use the following example to test the BMC Modern Shell:

UI elementUI element classAction

Example

Navigation bar

ApplicationGlobalHeaderWorks with the application global header that is the navigation bar
sampleView myView = new sampleView (driver, errorHandler)
 
myView.header().clickSubMenuItem("Consoles","Task Manager Console");
myView.header().clickMenuItem("SomeMenuItem");

UI automation sample: Testing an application configuration or setting

Use the following methods to test your application configurations or settings. These methods are available in the Base class.

MethodDescriptionExample
openApplicationConfiguration()

Navigates to a particular application configuration (or setting).

myView.openApplicationConfiguration();
filterSettings(String)Filters the setting component based on the search string.
myView.openApplicationConfiguration().filterSettings("First Component");
clearSettingsFilter()Clears the search text.
myView.openApplicationConfiguration().clearSettingsFilter();
selectConfigurationNode(ArrayList Obj)Selects a configuration node from the ArrayList object.

For example, the result of the following code automates the menu sequence is Configure My Sever > People > Manage User Accounts.

ArrayList<String> filterPath = new ArrayList<String>();
filterPath.add("Configure My Server");
filterPath.add("People");
filterPath.add("Manage User Accounts");
myView.openApplicationConfiguration().selectConfigurationNode(filterPath);

UI automation sample: Calling a wait method

While creating the UI test cases, you might need to call wait methods. The UI automation framework provides the wait methods shown in the following sample code:

sampleView myView = new sampleView (driver, errorHandler)

myView.waitForExecutionComplete();
myView.waitForAllErrorMessagesToDisappear();
myView.waitForAllSpinnersToHide();
myView.waitForInfoMessagesToDisappear();
myView.waitForSuccessfulMessagesToDisappear();


UI automation sample: Testing custom UI elements

Using the UI framework, you can also create custom test classes for your custom UI elements. Custom UI elements can be data fields (such as a text field) and control fields (such as a button). BMC recommends that you extend the RXControlField abstract class and RXDataField abstract class to create your custom UI elements classes. The RXControlField class and the RXDataField class are located in the com.bmc.rx.test.framework.elements package.

The following sample code illustrates how to test a custom control field:

package com.bmc.rx.test.framework.elements;
import com.bmc.rx.test.framework.listener.ErrorListener;
import com.bmc.rx.test.framework.utils.web.AngularJs;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
//This is the sample code snippet for the Custom Control field
public class CustomControlField extends RXControlField {
    
    //Unique Locator for the Custom field
    private static String cssButtonField = "[rx-view-component-id='%s'] button";
    
    public CustomControlField(WebDriver drv,String guid,ErrorListener listener){
        actualcssTag = String.format(cssButtonField, guid);
        driver = drv;
        addListener(listener);
    }
    
    
    /**
    * This method is used to click on the getWebElement()
    */
    @Override
    public void click() {
        getWebElement().click();
        AngularJs.waitForAngularRequestsToFinish(driver);
    }
    
    /** 
    * This method is used to see if getWebElement() is enabled or not 
    */
    public boolean isEnabled() {
        //Implement as per the Custom element's behavior
        return true;
    }
    
    /**
    * This method will be used to see if getWebElement() is visible or not. 
    */
    @Override
    public boolean isVisible() {
        //Implement as per the Custom element's behavior
        return true;
    }
    
    @Override
    public WebElement apply(WebDriver  input) {
        WebElement resultCountElement = null;
        if(driver.findElements(By.cssSelector(actualcssTag)).size() > 0){
            resultCountElement = driver.findElement(By.cssSelector(actualcssTag));    
        }        
        return resultCountElement;
    } 
}

The following sample code illustrates how to test a custom data field:
package com.bmc.rx.test.framework.elements;
import java.util.List;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import com.bmc.rx.test.framework.listener.ErrorListener;
/**
 * This is a sample code snippet for Custom Data Field
 */ 
public class CustomDataField extends RXDataField {
private static String cssBooleanField = "[rx-view-component-id='%s']";
    private String sBoolean = "rx-boolean";
    String sFieldName = "span";
    String sTrueButton = ".d-icon-check";
    String sFalseButton = ".d-icon-circle_slash_o";
    /**
     * This constructor will be used for initialising the instance of this class.
     */
    public CustomDataField(WebDriver drv,String guid,ErrorListener listener){
        actualcssTag = String.format(cssBooleanField, guid);
        driver = drv;
        addListener(listener);
    }
    /**
     * This method is used to see if element is enabled or not
     */
    @Override
    public boolean isEnabled() {
        //Write the implentation as per the requirement
        return true;
    }
    /*
    * If Data can be passed as 'True' or 'False'
    */
    @Override
    public void setData(Object data){
        //Write the implentation as per the requirement
    }
    /**
     * This method will be used for getting the selected state of the Boolean Field.
     * If the boolean field is set to True, then this method will return true. Else false will be returned
     *
     */
    @Override
    public Boolean getData(){
        //Write the implentation as per the requirement
        return true;
    }
    /**
     * This method is used to set the focus on the element
     */
    @Override
    public void setFieldFocus(){
        new Actions(driver).moveToElement(getWebElement()).perform();
    }
    /**
     * This method will be used for clearing / deselecting whatever was selected in the boolean field.
     */
    @Override
    public void clear(){
        getWebElement().findElement(By.cssSelector(sBoolean)).clear();
    }
    /**
     * This method will be used for getting the label of the element
     */
    @Override
    public String getLabel(){
        try {
            List<WebElement> labels = getWebElement().findElements(By.tagName("label"));
            if (labels.size() == 1) {
                return labels.get(0).getText();
            }
        }catch (Exception e){
            return null;
        }
        return null;
    }
    private boolean isButtonChecked(WebElement button) {
        return button.getAttribute("class").contains("is-checked");
    }
    /**
     * This method will be used to see, if element is visible or not.
     */
    @Override
    public boolean isVisible() {
        if (getWebElement().isDisplayed()){
            return true;
        }else {return false;}
    }
    /**
     * This method will be used to see, if element is readOnly or not.
     */
    @Override
    public boolean isReadOnly() {
        //Write the implentation as per the requirement
        return true;
    }
    @Override
    public WebElement apply(WebDriver  input) {
        WebElement resultCountElement = null;
        if(driver.findElements(By.cssSelector(actualcssTag)).size() > 0){
            resultCountElement = driver.findElement(By.cssSelector(actualcssTag));
        }
        return resultCountElement;
    }
}

For more information about all the methods available in the various elements classes (com.bmc.rx.test.framework.elements), see API documentation for UI automation framework.

Related topic

Testing the user interface with the UI automation framework

Was this page helpful? Yes No Submitting... Thank you

Comments