Anda di halaman 1dari 5

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

labelchart;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
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;

public class LabelChartTests extends BaseTest {

public static final String TEST_ENTITIES_FILE_NAME =


"Widget_LabelChart_Entities.xml";

public static final String AUTOMATION_TEST_MASHUP_NAME_ONE =


"AutomationTests_LabelChart_Mashup";

public static final String AUTOMATION_TEST_MASHUP_NAME_TWO =


"AutomationTests_LabelChartMashup2";

public static final String LABEL_CHART_WIDGETID_1 = "labelchart-1";

public static final String LABEL_CHART_WIDGETID_2 = "labelchart-2";

public static final String LABEL_CHART_WIDGETID_7 = "labelchart-7";

@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
// Import entities
getThingworxRESTUtils().importXmlEntities(TEST_ENTITIES_FILE_NAME, true,
ThingworxRESTUtils.HTTP_OK);
navigateToMashupInRuntime(AUTOMATION_TEST_MASHUP_NAME_ONE);
}

@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws UnsupportedEncodingException {
getWebdriver().navigate().refresh();

getPages().mashupRuntimePage().waitForLoadIconToBeInvisible(LABEL_CHART_WIDGETID_1,
1);
}

@Requirements(reqs = { "TW-24743" })
@Test(
description = "Verify and check label chart double clicking feature &
verifying the pop-up message",
groups = { "FUNCTIONAL_TESTING", "LABEL_CHART" })
public void verifyAndCheckLabelChartMessagePopUpOnDoubleClicking() throws
Exception {
final int circleNumber = 3;
final int circleRowNumber = 4;
final List<WebElement> listOfCircles =
getPages().mashupRuntimePage().labelChartWidgetAllCircleMarkers(LABEL_CHART_WIDGETI
D_1);
Assert.assertNotNull(listOfCircles, "The total number of circles in first
chart is null ");
Assert.assertTrue((listOfCircles.size() > circleRowNumber),
"The total number of circles in first chart is inconsistent , expected
values for circles found should be less than" +
listOfCircles.size() + ", but found " + circleRowNumber
+ " circles.");

getPages().mashupRuntimePage()
.labelChartWidgetCircleMarker(

getPages().mashupRuntimePage().labelChartWidgetAllCircleMarkers(LABEL_CHART_WIDGETI
D_1).get(circleNumber),
LABEL_CHART_WIDGETID_1, circleRowNumber)
.waitForVisibilityOfElement();

// Action class is used here to double click the marker so that the pop-up
message shows up.
Actions builder = new Actions(webdriver.getWebDriver());
builder.doubleClick(getPages().mashupRuntimePage()
.labelChartWidgetCircleMarker(

getPages().mashupRuntimePage().labelChartWidgetAllCircleMarkers(LABEL_CHART_WIDGETI
D_1).get(circleNumber),
LABEL_CHART_WIDGETID_1, circleRowNumber)
.getWebElement()).build().perform();

getPages().mashupRuntimePage().statusMessageboxCloseButton().waitForVisibilityOfEle
ment();

Assert.assertEquals(getPages().mashupRuntimePage().labelChartWidgetPopUpMessageText
().getText(),
"This is a test message. First chart was double-clicked.", "Double
click pop-up message on first chart is not correct");
}

@Requirements(reqs = { "TW-24743" })
@Test(description = "Verify label charts widget title", groups =
{ "FUNCTIONAL_TESTING", "LABEL_CHART" })
public void verifyChartTitleTest() throws Exception {

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 16).getText(),
"This is the First Chart Title", "Title of charts doesn't match");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_2, 4).getText(),
"This is the Second Chart Title", "Title of charts doesn't match");
}

@Requirements(reqs = { "TW-24743" })
@Test(description = "Verify label charts title for X-Axis", groups =
{ "FUNCTIONAL_TESTING", "LABEL_CHART" })
public void verifyChartXAxisTitleTest() throws Exception {
Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 6).getText(), "X-Axis",
"X-Axis title of chart doesn't match");
}

@Requirements(reqs = { "TW-24743" })
@Test(
description = "Verify label charts title for Y-Axis" + "Verify label charts
for Y-Axis title location & enablement" +
"Verify label charts Y-Axis minimum value" +
"Verify label charts for secondary Y-Axis title location &
enablement" +
"Verify label charts Y-Axis maximum value" + "Verify label
charts Secondary Y-Axis minimum value" +
"Verify label charts Secondary Y-Axis maximum value" +
"Verify Y-Axis Mode Test" +
"Verify Secondary YAxis AutoScale Values Test",
groups = { "FUNCTIONAL_TESTING", "LABEL_CHART" })
public void verifyChartYAxisTests() throws Exception {

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 10).getText(), "Y-Axis",
"Y-Axis title of chart doesn't match");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 7).getText(), "1.0",
"Y-Axis minimum value is not matching for first chart");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 9).getText(), "110.0",
"Y-Axis maximum value is not matching for first chart");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 11).getText(), "50.0",
"Secondary Y-Axis minimum value is not matching for first chart");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 13).getText(), "100.0",
"Secondary Y-Axis maximum value is not matching for first chart");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 10).getText(), "Y-Axis",
"Y-Axis Dual Mode scale is not properly set");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 14).getText(), "SecondaryAxis",
"Y-Axis Dual Mode scale is not properly set");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 11).getText(), "50.0",
"Secondary Y-Axis Auto scale is not properly set");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 12).getText(), "75.0",
"Secondary Y-Axis Auto scale is not properly set");

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_1, 13).getText(), "100.0",
"Secondary Y-Axis Auto scale is not properly set");
try {
navigateToMashupInRuntime(AUTOMATION_TEST_MASHUP_NAME_TWO);
final Integer chartBSecondaryAxisFirstValue =

Integer.parseInt(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WIDGET
ID_7, 20).getText());
final Integer chartBSecondaryAxisSecondValue =

Integer.parseInt(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WIDGET
ID_7, 19).getText());
final Integer chartBSecondaryAxisThirdValue =

Integer.parseInt(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WIDGET
ID_7, 18).getText());
final Integer chartBSecondaryAxisFourthValue =

Integer.parseInt(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WIDGET
ID_7, 17).getText());
Assert.assertTrue(chartBSecondaryAxisFirstValue >= 100,
"Secondary YAxis autoscale value for Chart_B of second mashup is
not properly set,expected value should be equal or greater than 100 , but the
actual value is " +
chartBSecondaryAxisFirstValue);
Assert.assertTrue(chartBSecondaryAxisSecondValue >= 75,
"Secondary YAxis autoscale value for Chart_B of second mashup is
not properly set,expected value should be equal or greater than 75 , but the actual
value is " +
chartBSecondaryAxisSecondValue);
Assert.assertTrue(chartBSecondaryAxisThirdValue >= 50,
"Secondary YAxis autoscale value for Chart_B of second mashup is
not properly set,expected value should be equal or greater than 50 , but the actual
value is " +
chartBSecondaryAxisThirdValue);
Assert.assertTrue(chartBSecondaryAxisFourthValue >= 25,
"Secondary YAxis autoscale value for Chart_B of second mashup is
not properly set,expected value should be equal or greater than 25 , but the actual
value is " +
chartBSecondaryAxisFourthValue);
} finally {
navigateToMashupInRuntime(AUTOMATION_TEST_MASHUP_NAME_ONE);
}
}

@Requirements(reqs = { "TW-24743" })
@Test(description = "Verify SecondaryAxisZeroScaleValuesTest", groups =
{ "FUNCTIONAL_TESTING", "LABEL_CHART" })
public void verifySecondaryAxisZeroScaleValuesTest() throws Exception {
final String zeroValue = "0";

Assert.assertNotEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_
WIDGETID_1, 11).getText(), zeroValue,
"Secondary Y-Axis Zero scale is not properly set");
try {
navigateToMashupInRuntime(AUTOMATION_TEST_MASHUP_NAME_TWO);

Assert.assertEquals(getPages().mashupRuntimePage().chartWidgetTitle(LABEL_CHART_WID
GETID_7, 16).getText(), zeroValue,
"Secondary Y-Axis Zero scale is not properly set");
} finally {
navigateToMashupInRuntime(AUTOMATION_TEST_MASHUP_NAME_ONE);
}
}

@AfterClass(alwaysRun = true)
public void afterClass() throws Exception {
// Delete entities created for test class

getThingworxRESTUtils().deleteEntitiesByApplicationModelTag("Widgets_LabelChart");
}
}

Anda mungkin juga menyukai