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 class | Action | Example |
---|---|---|---|
Attachment | AttachmentField | Uploads a file |
|
Gets the file name of the file that is uploaded |
| ||
Boolean | BooleanField | Sets the value of a Boolean field to true |
|
Sets the value of a Boolean field to false |
| ||
Gets a Boolean field value |
| ||
Button | ButtonField | Clicks a button |
|
Date | DateField | Sets data for a Date field and pass the data in the string format, "YYYY-MM-DD" |
|
DateTime | DateTimeField | Sets a Date field and pass the data in the string format YYYY-MM-DD |
|
Time | TimeField | Sets data for a Time field and pass the data in the string format, "HH:MM:AM" |
|
Drop down (single selection) | DropDownField | Selects the DropDown field |
|
Drop down (Multi-select ) | MultiSelectField | Sets multiple values |
|
Decimal, Floating | DecimalField, FloatingField | Provides a value to a Decimal field |
|
Integer | IntegerField | Provides a value to an Integer field |
|
TextArea, Text | TextAreaField, TextField | Provides a value to a TextArea field |
|
UI automation sample: Testing a record grid
Use the following examples to test the record grid UI element:
UI element | UI element class | Action | Example |
---|---|---|---|
Record Grid | RecordGridField | Gets all of the values from a specific column |
|
Selects a specific row |
| ||
Applies a filter |
|
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:
Method | Description | Example |
---|---|---|
clickOnTab(String) | Selects a tab in the approve console such as Pending, On Hold, and so on. |
|
getRequestCount() | Provides the row count. |
|
selectMoreViewOptions(String) | Selects the More Views tab in the Approval Console. |
|
selectRecordDefinitionByIndex(intValue) | Selects a grid row based on the index specified. |
|
deselectRecordDefinitionByIndex(intValue) | Deselects a grid row based on the index specified. |
|
selectRecordDefinitionBasedOnUniqueCellValue(columnName, Value) | Selects a record definition based on the column value specified. |
|
deselectRecordDefinitionBasedOnUniqueCellValue(columnName, Value) | Deselects a record definition based on the column value specified. |
|
clickRefresh() | Refreshes record grid. |
|
performAction(String) | Clicks an action in the Approve Console such as Approve, Reject, and Hold. |
|
clickOkButton() | Clicks the OK button in a dialog box. |
|
initiateReassignDialogAndAssign(userName) | Clicks the Reassign button in a task and assigns the task to the specified user. |
|
openVisibleColumnsDropDown() | Opens the Visible Column list to add or remove a column in the record grid. |
|
selectCheckBoxInVisibleColumnsMenuByText(String) | Selects the specified string in the Visible Column menu. |
|
deselectCheckBoxInVisibleColumnsMenuByText(String) | Deselects the specified string in the Visible Column menu. |
|
closeVisibleColumnsDropDown() | Closes the Visible Column list. |
|
initiateQuestionDialogAndAddQuestion(UserName, Question) | Clicks the New button in the Questions tab and adds a question. |
|
initiateAndEnterCommentsDialog(userName) | Clicks the New button in the Comments tab and adds a comment. |
|
getRequestFieldValues() | Provides the list of request field values in a request. |
|
getRequestFieldNames() | Provides the list of request field names in a request. |
|
setSearchText(String) | Searches record instances based on the search text. |
|
UI automation sample: Testing the BMC Modern Shell
Use the following example to test the BMC Modern Shell:
UI element | UI element class | Action | Example |
---|---|---|---|
Navigation bar | ApplicationGlobalHeader | Works with the application global header that is the navigation bar |
|
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.
Method | Description | Example |
---|---|---|
openApplicationConfiguration() | Navigates to a particular application configuration (or setting). |
|
filterSettings(String) | Filters the setting component based on the search string. |
|
clearSettingsFilter() | Clears the search text. |
|
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.
|
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.
Comments
Log in or register to comment.