You are on page 1of 3

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

checkbox;

import java.io.UnsupportedEncodingException;

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;

/***
* This is the functional test for Checkbox widget. It includes testing three main
scenarios- 1)Checkbox click triggers event
* i.e.hides/unhides textbox 2)Checkbox click triggers event i.e. resets Textbox
value to default 3)Checks whether DisabledCheckbox can be
* clicked to check it
*
* @author pbiswas
*
*/
public class CheckboxTests 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 STATECHECKED_CHECKBOX_WIDGET_ID_NUMBER = 5;

public static final int DISABLED_CHECKBOX_WIDGET_ID_NUMBER = 6;

public static final int TRUE_TEXTBOX_WIDGET_ID_NUMBER = 10;

public static final int INPUTIN_TEXTBOX_WIDGET_ID_NUMBER = 11;

public static final String TEXT_TO_ADD = "Test1234398492384 Test1234398492384";

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

@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 {
navigateToMashupInRuntime(TEST_MASHUP_NAME);

getPages().mashupRuntimePage().pointerToCheckbox(STATECHECKED_CHECKBOX_WIDGET_ID_NU
MBER).waitForVisibilityOfElement();
}

@Requirements(reqs = { "TW-23059" })
@Test(
description = "This test verifies another widget hides and unhides based on
checkbox click",
groups = { "FUNCTIONAL_TESTING", "CHECKBOX" })
public void checkboxClickHideShowAnotherWidgetTest() throws Exception {

// Verify whether the TextBox with 'true' value in it is visible

Assert.assertEquals(getPages().mashupRuntimePage().textboxInputforMashupWithCheckbo
x(TRUE_TEXTBOX_WIDGET_ID_NUMBER).isDisplayed(),
true, "The TextBox with 'true' value in it is not displayed.");

// Click on StateChecked checkbox to hide Textbox with 'true' value in it

getPages().mashupRuntimePage().pointerToCheckbox(STATECHECKED_CHECKBOX_WIDGET_ID_NU
MBER).click();

// Verify whether the TextBox with 'true' value in it is Invisible

Assert.assertEquals(getPages().mashupRuntimePage().textboxInputforMashupWithCheckbo
x(TRUE_TEXTBOX_WIDGET_ID_NUMBER).isDisplayed(),
false, "The TextBox with 'true' value in it is not invisible.");

// Click on StateChecked checkbox to unhide Textbox with 'true' value in it

getPages().mashupRuntimePage().pointerToCheckbox(STATECHECKED_CHECKBOX_WIDGET_ID_NU
MBER).click();
}

// Changed event trigger


@Requirements(reqs = { "TW-23059" })
@Test(
description = "This test verifies when the state of the checkbox changes,
the text in the second textbox should reset to its default value",
groups = { "FUNCTIONAL_TESTING", "CHECKBOX" })
public void changeEventTriggerTest() throws Exception {

// Verify whether the TextBox has default value


Assert.assertEquals(

getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).getAttribute("value"),
"This is the default text.", "The TextBox does not have default value
in it.");

getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).click();
getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).clear();

getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).sendKeys(TEXT_TO_ADD);

// Verify whether the TextBox now has the changed value


Assert.assertEquals(

getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).getAttribute("value"),
TEXT_TO_ADD, "The TextBox is not set to desired value.");

// Click on StateChecked checkbox to reset Textbox to its default value

getPages().mashupRuntimePage().pointerToCheckbox(STATECHECKED_CHECKBOX_WIDGET_ID_NU
MBER).click();

// Verify whether the TextBox has been reset to default value


Assert.assertEquals(

getPages().mashupRuntimePage().textboxInputforMashupWithCheckbox(INPUTIN_TEXTBOX_WI
DGET_ID_NUMBER).getAttribute("value"),
"This is the default text.", "TextBox has not being reset to default
value");
}

@Requirements(reqs = { "TW-23059" })
@Test(
description = "This test verifies whether Disabled attribute checkbox can
be checked/selected.",
groups = { "FUNCTIONAL_TESTING", "CHECKBOX" })
public void disabledAttributeTest() 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();

// Verify that disabled checkbox is not checked on Mashup Runtime

Assert.assertEquals(getPages().mashupRuntimePage().pointerToCheckbox(DISABLED_CHECK
BOX_WIDGET_ID_NUMBER).isSelected(), false,
"Disabled Checkbox does not have disabled tag in it");
}
}

You might also like