Anda di halaman 1dari 3

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

xychart;

import java.io.UnsupportedEncodingException;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

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

/***
* This is the visual test for XY chart widget. It includes testing following
scenarios : 1) 'Visible' property 2) ChartStyle 3)
* ChartLegendStyle 4) ChartTitleStyle 5) XAxisStyle 6) YAxisStyle 7) GridStyle 8)
SelectedItemStyle 9) ShowLegends 10) LegendLocation 11)
* LegendOrientation 12) ChartIndicatorStyle 13) ShowXAxisLabels 14)
ShowYAxisLabels 15) ShowXAxisTicks 16) ShowYAxisTicks 17)
* YAxisIntervals 18) YAxisMinorTicks 19) YAxisLabels 20) ShowYAxis 21) ShowXAxis
*
* Bug ID : TW-26951
*
* @author kdeshpande
*/

public class VisualXYChartTests extends BaseTest {

public static final String TEST_SPECIFIC_ENTITY =


"Widgets_XYChart_Entities.xml";

public static final String TEST_MASHUP_NAME = "Widgets_XYChart_VisualTests";

public static final String VOCABULARY_TERM_NAME = "Widgets_XYChart";

public static final String CHECKBOX_VISIBLE_WIDGET_ID = "checkbox-12";

public static final String XY_CHART_VISIBLE_WIDGET_ID = "xychart-11";

public static final String XY_CHART_STYLE_WIDGET_ID = "xychart-13";

public static final int DATA_FIELD_ITEM = 6;

@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(VOCABULARY_TERM_NAME);
}

@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws UnsupportedEncodingException {

getWebdriver().navigate().refresh();
try {

getPages().mashupRuntimePage().waitForFocusOfWidget(CHECKBOX_VISIBLE_WIDGET_ID);
} catch (Exception e) {
// Click on the Widget to force focus in case of a timeout failure
(Click 2 times to bring it to default state)

getPages().mashupRuntimePage().checkBoxWidget(CHECKBOX_VISIBLE_WIDGET_ID).click();

getPages().mashupRuntimePage().checkBoxWidget(CHECKBOX_VISIBLE_WIDGET_ID).click();
}
}

@Requirements(reqs = { "TW-23124" })
@Test(
description = "1. Take a screenshot of mashup containing XY chart as is. 2.
Visible: Disabled 3. ShowLegends: Disabled " +
"4. LegendLocation: Left 5. LegendOrientation: Vertical 6.
LegendLocation: Top " +
"7. LegendLocation: Right 8. LegendLocation: Bottom 9.
LegendOrientation: Horizontal 10. ChartTitleStyle " +
"11. ChartStyle 12. ChartLegendStyle 13. XAxisStyle 14.
YAxisStyle 15. GridStyle " +
"16. ShowXAxisLabels 17. ShowYAxisLabels 18. ShowXAxisTicks
19. ShowYAxisTicks 20. YAxisIntervals " +
"21. YAxisMinorTicks 22. YAxisLabels 23. ShowYAxis 24.
ShowXAxis",
groups = { "VISUAL_TESTING", "XY_CHART" })
public void asIsTest() throws Exception {

// TODO: Created bug TW-26951 Grid Axis Lines Disappear When Disabling
Chart Widget's "Show...Axis..." Settings
// Take a screenshot of mashup as-is.
ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "XYChartAsIs"));
}

@Requirements(reqs = { "TW-23124" })
@Test(
description = "Take a screenshot of mashup containing XY chart to verify
visible property ",
groups = { "VISUAL_TESTING", "XY_CHART" })
public void xyChartVisiblePropertyBindingTest() throws Exception {

// Select the checkbox to make XY Chart visible

getPages().mashupRuntimePage().checkBoxWidget(CHECKBOX_VISIBLE_WIDGET_ID).click();

// Wait for XY chart to be visible

getPages().mashupRuntimePage().xyChartWidget(XY_CHART_VISIBLE_WIDGET_ID).waitForVis
ibilityOfElement();

// Take the screenshot of the mashup when 'visible' property is enabled for
XY chart
ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "VisibleTest"));
}

@Requirements(reqs = { "TW-23124" })
@Test(
description = "Take a screenshot of mashup containing XY chart to verify
the SelectedItemStyle",
groups = { "VISUAL_TESTING", "XY_CHART" })
public void xyChartSelectedItemStyleTest() throws Exception {

// Click on a particular data point to verify the chart selected item style

getPages().mashupRuntimePage().xyChartWidgetCircleDataItem(XY_CHART_STYLE_WIDGET_ID
, DATA_FIELD_ITEM).click();

getPages().mashupRuntimePage().xyChartWidgetCircleDataItem(XY_CHART_STYLE_WIDGET_ID
, DATA_FIELD_ITEM)
.waitForElementAttributeValueToBeEqualTo("fill", "#4a0000");

// Take a screenshot of mashup when a particular data point is selected on


XY chart
ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "SelectedItemStyleTest"));
}

@Requirements(reqs = { "TW-23124" })
@Test(
description = "Take a screenshot of mashup containing XY chart to verify
ChartIndicatorStyle",
groups = { "VISUAL_TESTING", "XY_CHART" })
public void xyChartIndicatorStyleTest() throws Exception {

// Mouse over on a particular data point

getPages().mashupRuntimePage().xyChartWidgetCircleDataItem(XY_CHART_STYLE_WIDGET_ID
, DATA_FIELD_ITEM).mouseOver();

// Wait for tooltip to be visible


final Predicate<WebDriver> predicate = webdriver -> {
return
(getPages().mashupRuntimePage().xyChartWidgetTooltip(XY_CHART_STYLE_WIDGET_ID,
true).getCssValue("display")
.equals("block"));
};

// Take a screenshot of mashup to verify chart indicator style


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "ChartIndicatorStyleTest"));
}
}

Anda mungkin juga menyukai