You are on page 1of 3

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

checkbox;

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.ScreenCapture;
import com.twx.common.utilities.ThingworxRESTUtils;

/***
* This is the visual test for Checkbox widget. It includes testing scenarios like
hoverOver Test, disabled attribute test and check
* un-check, focus tests.
*
* @author pbiswas
*
*/

public class VisualCheckboxTests extends BaseTest {

public static final String TEST_MASHUP_NAME =


"Mashups_VisualTest_Widgets_Checkbox";

public static final String TEST_SPECIFIC_ENTITY =


"Mashups_VisualTest_Widgets_Checkbox_Entities.xml";

public static final int HOVEROVER_CHECKBOX_WIDGET_ID_NUMBER = 7;

public static final int DISABLED_CHECKBOX_WIDGET_ID_NUMBER = 6;

public static final int CHECKBOX_WIDGET_ID_NUMBER = 3;

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

@AfterClass(alwaysRun = true)
public void afterClass() throws Exception {
getThingworxRESTUtils()
.deleteEntitiesByModelTags("{\"tags\":
[{\"vocabulary\": \"Applications\", \"vocabularyTerm\": \"VisualTest_Checkbox\"}]}"
);
}

// This empty Method is used to overlap BaseTest beforeMethod


@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws UnsupportedEncodingException {
getWebdriver().navigate().refresh();
getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).waitForVisibilityOfElement();

getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).click();
}

@Requirements(reqs = { "TW-23059" })
@Test(
description = "Takes snapshot of a Mashup containing checkbox to test
following scenarios 1) Prompt attribute display 2) Prompt attribute display - with
really long text 3) State attribute 5)Disable Attribute",
groups = { "VISUAL_TESTING", "CHECKBOX" })
public void asIsTest() throws Exception {

// Take a screenshot of the Mashup as-is


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "As-Is"));
}

@Requirements(reqs = { "TW-23059" })
@Test(
description = "Takes snapshot of a Mashup containing checkbox to test
following scenarios 1)Hover Display with ToolTip",
groups = { "VISUAL_TESTING", "CHECKBOX" })
public void hoverOverTest() throws Exception {

// Hover over Tooltip checkbox

getPages().mashupRuntimePage().pointerToCheckbox(HOVEROVER_CHECKBOX_WIDGET_ID_NUMBE
R).mouseOver();

// Take a screenshot of the Mashup after hovering over Tooltip checkbox


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

@Requirements(reqs = { "TW-23059" })
@Test(
description = "Takes snapshot of a Mashup containing checkbox to test
following scenarios 1)Hover Display with ToolTip",
groups = { "VISUAL_TESTING", "CHECKBOX" })
public void disableCheckboxTest() throws Exception {

// Try to check DisabledCheck checkbox

getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).mouseOver();

getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).click();

// Take a screenshot of the Mashup to check whether disabled checkbox is


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

@Requirements(reqs = { "TW-23059" })
@Test(
description = "Takes snapshot of a Mashup containing checkbox to test
following scenarios 1)Click checkbox to enable i. Checkmark should be displayed
ii.Focus should now be on checkbox iii.Click out of the checkbox and the focus
should be lost",
groups = { "VISUAL_TESTING", "CHECKBOX" })
public void clickCheckboxToEnableDisableFocusTest() throws Exception {

// Click on one of the check boxes

getPages().mashupRuntimePage().pointerToCheckbox(CHECKBOX_WIDGET_ID_NUMBER).click()
;

// Take a screenshot of the Mashup after checking CheckThisBox checkbox


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

// Click on some other place in the Mashup to loose focus on CheckThisBox


checkbox

getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).click();

// Take a screenshot of the Mashup to see loose of focus


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

// Click on StateUnchecked checkbox to uncheck it

getPages().mashupRuntimePage().pointerToCheckbox(CHECKBOX_WIDGET_ID_NUMBER).click()
;

// Take a screenshot of the Mashup to see loose of focus


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

// Click on some other place in the Mashup to loose focus on CheckThisBox


checkbox

getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECKBOX_WIDGET_ID_NUMBER
).click();

// Take a screenshot of the Mashup to see loose of focus


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

You might also like