Вы находитесь на странице: 1из 5

package com.twx.ux.composer.classic.mashup.widgets.charts.

bubblechart;

import static org.testng.Assert.assertEquals;

import java.io.UnsupportedEncodingException;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.twx.base.BaseTest;
import com.twx.common.requirements.Requirements;
import com.twx.common.utilities.ThingworxRESTUtils;

/***
* This is the functional test for Bubble Chart Widget.It consists of 5 main
scenarios as follows: 1)Visibility of the existing data point
* tooltip on mouse hover, 2)Creating a new data point, 3)Updating the bubble size,
4)Changed event- DoubleClicked when 'AllowSelection'
* property is enabled, 5)AllowSelection property is disabled.
*
* Story ID : TW-23116.
*
* @author snkulkarni
*
*/
public class BubbleChartTests extends BaseTest {

public static final String TEST_SPECIFIC_ENTITY =


"Widgets_BubbleChart_Entities.xml";

public static final String TEST_MASHUP_NAME =


"Widgets_BubbleChart_FunctionalTests";

public static final String WIDGET_BUBBLE_CHART_MODEL_TAG =


"Widget_BubbleChart";

public static final String BUBBLE_CHART_WITH_ALLOWSELECTION_ENABLED_WIDGET_ID =


"bubblechart-10";

public static final String BUBBLE_CHART_WITH_ALLOWSELECTION_DISABLED_WIDGET_ID


= "bubblechart-18";

public static final String BUBBLE_CHART_NUMERICENTRY_TITLED_X_WIDGET_ID =


"numericentry-11";

public static final String BUBBLE_CHART_NUMERICENTRY_TITLED_Y_WIDGET_ID =


"numericentry-12";

public static final String BUBBLE_CHART_NUMERICENTRY_BUBBLE_SIZE_WIDGET_ID =


"numericentry-13";

public static final String


BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTION_ENABLED_WIDGET_ID = "textbox-15";

public static final String


BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTION_DISABLED_WIDGET_ID = "textbox-19";
public static final String VALUE = "value";

public static final String DEFAULT_VALUE = "Default Value";

public static final String NOT_A_DEFAULT_VALUE = "Not a Default Value";

public static final String EXPECTED_VALUES_FOR_EXISTING_DATA_POINT = "Size :


4.0\nX : 10.0\nY : 20.0";

public static final String EXPECTED_VALUES_FOR_NEW_DATA_POINT = "Size :


4.0\nX : 90.0\nY : 90.0";

public static final String EXPECTED_VALUES_FOR_UPDATED_DATA_POINT = "Size :


50.0\nX : 90.0\nY : 90.0";

@BeforeClass(alwaysRun = true)
public void beforeClass() throws UnsupportedEncodingException {
getThingworxRESTUtils().importXmlEntities(TEST_SPECIFIC_ENTITY, true,
ThingworxRESTUtils.HTTP_OK);
navigateToMashupInRuntime(TEST_MASHUP_NAME);
}

@AfterClass(alwaysRun = true)
public void afterClass() throws Exception {

getThingworxRESTUtils().deleteEntitiesByApplicationModelTag(WIDGET_BUBBLE_CHART_MOD
EL_TAG);
}

@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws UnsupportedEncodingException {
getWebdriver().navigate().refresh();
try {
// Wait for the Bubble Chart's numeric entry widget named 'X' to gain
focus automatically.

getPages().mashupRuntimePage().waitForFocusOfWidget(BUBBLE_CHART_NUMERICENTRY_TITLE
D_X_WIDGET_ID);

} catch (Exception e) {
// Safeguard in case the timeout above fails. Just click on the above
numeric entry widget to get the focus explicitly.

getPages().mashupRuntimePage().numericEntryWidget(BUBBLE_CHART_NUMERICENTRY_TITLED_
X_WIDGET_ID).click();
}
}

@Requirements(reqs = { "TW-23116" })
@Test(
description = "6)This test verifies that tooltip is displayed" +
"after hovering the mouse on the existing data point of the
Bubble Chart Widget.",
groups = { "FUNCTIONAL_TESTING", "BUBBLE_CHART" })
public void bubbleChartMouseOverOnExistingDataPointTest() throws Exception {

// Fetch and verify tooltip of the existing data point.


getAndVerifyDataPointToolTipValues(BUBBLE_CHART_WITH_ALLOWSELECTION_ENABLED_WIDGET_
ID, EXPECTED_VALUES_FOR_EXISTING_DATA_POINT, 4);
}

@Requirements(reqs = { "TW-23116" })
@Test(
description = "This test verifies below scenarios :" +
"7)The tooltip is displayed after hovering the mouse on
newly created data point of the Bubble Chart Widget." +
"8)Updated bubble size gets displayed after hovering the
mouse on above created data point.",
groups = { "FUNCTIONAL_TESTING", "BUBBLE_CHART" })
public void bubbleChartMouseOverOnNewDataPointTest() throws Exception {

final String[] numericEntryWidgetIds =


{ BUBBLE_CHART_NUMERICENTRY_TITLED_X_WIDGET_ID,
BUBBLE_CHART_NUMERICENTRY_TITLED_Y_WIDGET_ID };
// The row number present in the DOM which represents the Bubble(circle) in
the Bubble Chart Widget.
final int bubbleRowNumber = 1;

// Enter the values for X/Y co-ordinates to get the new Bubble.
for (int coordinateIterator = 0; coordinateIterator < 2;
coordinateIterator++) {

getPages().mashupRuntimePage().numericEntryInput(numericEntryWidgetIds[coordinateIt
erator], "90");
}

// Fetch and verify tooltip of the above created data point.

getAndVerifyDataPointToolTipValues(BUBBLE_CHART_WITH_ALLOWSELECTION_ENABLED_WIDGET_
ID, EXPECTED_VALUES_FOR_NEW_DATA_POINT,
bubbleRowNumber);

// Enter the new value for Bubble Size.

getPages().mashupRuntimePage().numericEntryInput(BUBBLE_CHART_NUMERICENTRY_BUBBLE_S
IZE_WIDGET_ID, "50");

// Fetch and verify tooltip of the above data point with updated bubble
size.

getAndVerifyDataPointToolTipValues(BUBBLE_CHART_WITH_ALLOWSELECTION_ENABLED_WIDGET_
ID, EXPECTED_VALUES_FOR_UPDATED_DATA_POINT,
bubbleRowNumber);
}

@Requirements(reqs = { "TW-23116" })
@Test(
description = "9a)This test verifies that the updated value for the text
box with label 'Test DoubleClicked Event'" +
"gets reset to the 'Default Value' when any bubble is
double clicked." +
"This is applicable when 'AllowSelection' propety is set to
true.",
groups = { "FUNCTIONAL_TESTING", "BUBBLE_CHART" })
public void bubbleChartDoubleClickedEventTest() throws Exception {
// Update and verify the value for textBox widget with label 'Test
DoubleClicked Event'.

updateAndVerifyTextboxWidgetValue(BUBBLE_CHART_WITH_ALLOWSELECTION_ENABLED_WIDGET_I
D,
BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTION_ENABLED_WIDGET_ID);

// Wait till the text gets reset to 'Default Value'.

getPages().mashupRuntimePage().textboxWidget(BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTIO
N_ENABLED_WIDGET_ID)
.waitForElementAttributeValueToBeEqualTo(VALUE, DEFAULT_VALUE);

// Verify that the textBox with label 'Test DoubleClicked Event' displays
"Default Value" text.
assertEquals(

getPages().mashupRuntimePage().textboxWidget(BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTIO
N_ENABLED_WIDGET_ID).getAttribute(VALUE),
DEFAULT_VALUE, "Default value for the textbox widget is not as
expected.");
}

@Requirements(reqs = { "TW-23116" })
@Test(
description = "9b)This test verifies that the updated value for the text
box with label 'Test DoubleClicked Event'" +
"does not get reset to the 'Default Value' when any bubble
is double clicked." +
"This is applicable when 'AllowSelection' propety is set to
false.",
groups = { "FUNCTIONAL_TESTING", "BUBBLE_CHART" })
public void bubbleChartDoubleClickedEventAllowSelectionDisabledTest() throws
Exception {

// Update and verify the value for textBox widget with label 'Not returning
to Default Value'.

updateAndVerifyTextboxWidgetValue(BUBBLE_CHART_WITH_ALLOWSELECTION_DISABLED_WIDGET_
ID,
BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTION_DISABLED_WIDGET_ID);

// Verify that the textBox with label 'Test DoubleClicked Event' still
displays the updated text.
assertEquals(

getPages().mashupRuntimePage().textboxWidget(BUBBLE_CHART_TEXTBOX_FOR_ALLOWSELECTIO
N_DISABLED_WIDGET_ID).getAttribute(VALUE),
NOT_A_DEFAULT_VALUE, "Default value for the textbox widget is not
reset.");
}

// This is a private method to fetch and verify the data point values of the
Bubble Chart Widget.
private void getAndVerifyDataPointToolTipValues(String widgetId, String
expectedValue, int bubbleNumber) throws InterruptedException {

// Hover the mouse on the bubble.


getPages().mashupRuntimePage().bubbleChartWidgetCircleDataItem(widgetId,
bubbleNumber).mouseOver();

// Wait for tooltip to be visible.

getPages().mashupRuntimePage().bubbleChartWidgetToolTip(widgetId).waitForElementToB
ePresent();

// Verify that the tooltip provides the expected Bubble Size, X and Y co-
ordinates.
// TODO : This is a workaround added to get tooltip values through
JavaScript since tooltip is not displaying in some charts. Need
// to revisit and revert after selenium 3.x is deployed

assertEquals(getPages().mashupRuntimePage().getChartTooltipValuesJS(widgetId),
expectedValue,
"Values for Bubble Size , X and Y are not as expected");
}

// This is a private method to update and verify the textBox widget value.
private void updateAndVerifyTextboxWidgetValue(String widgetId, String
textBoxWidgetId) {

// Verify that the textBox with label 'Test DoubleClicked Event' displays
'Default Value' text initially.

assertEquals(getPages().mashupRuntimePage().textboxWidget(textBoxWidgetId).getAttri
bute(VALUE), DEFAULT_VALUE,
"Default value for the textbox widget is not as expected.");

// Update the value in the text-box from 'Default Value' to 'Not a Default
Value'.
getPages().mashupRuntimePage().textBoxInput(textBoxWidgetId,
NOT_A_DEFAULT_VALUE);

// Verify that the above value gets updated successfully.

assertEquals(getPages().mashupRuntimePage().textboxWidget(textBoxWidgetId).getAttri
bute(VALUE), NOT_A_DEFAULT_VALUE,
"The textbox value is not updated succesfully.");

// Double Click on the bubble.


getPages().mashupRuntimePage().bubbleChartWidgetCircleDataItem(widgetId,
2).doubleClick();
}
}

Вам также может понравиться