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

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

containedmashup;

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 class covers the functional test aspect of the Contained mashup widget.
Scenarios include: 1> Adding gadget to dashboard test 2>
* Refresh service verification test
*
* Support Story TW-23085.
*
* @author rraj
*
*/

public class ContainedMashupTests extends BaseTest {

public static final String TEST_ENTITIES_FILE_NAME =


"Widgets_ContainedMashup_Entities.xml";

public static final String AUTOMATION_CONTAINED_MASHUP =


"Widgets_ContainedMashup_FunctionalTests";

public static final String ADD_GADGET_TO_DASHBOARD_TEST_BUTTON_WIDGET =


"button-15";

public static final String REFRESH_TEST_BUTTON_WIDGET = "button-16";

public static final String CONFIRM_BUTTON_CLASS_NAME = "confirm-btn";

public static final String TEMPLATE_MASHUP_CONTAINER = "mashupcontainer-14";

public static final String SOURCE_TEXTBOX_GADGET = "textbox-4";

public static final String REFLECTED_TEXTBOX_GADGET = "textbox-5";

public static final String REFRESH_TEST_TEXTBOX_GADGET = "textbox-6";

public static final String POPUP_WIDGET_CLASS = "twPopoverDialog";

public static final String DASHBOARD_TITLE_ITEM_CLASS_NAME = "dashboard-item-


name";

public static final String ENTITY_APPLICATION_MODEL_TAG_NAME =


"Widgets_ContainedMashup";

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

@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws UnsupportedEncodingException {
getWebdriver().navigate().refresh();
// ensuring the DOM gets settled here

getPages().mashupRuntimePage().waitForFocusOfWidget(ADD_GADGET_TO_DASHBOARD_TEST_BU
TTON_WIDGET);
}

@Requirements(reqs = { "TW-25364" })
@Test(
description = "Verify add gadget to dashboard & verify title, source &
reflected textbox values",
groups = { "FUNCTIONAL_TESTING", "CONTAINED_MASHUP" })
public void verifyAddGadgetsToDashboardTest() throws Exception {

final String testGadgetTitle = "TestGadget1";


final String parentWidgetID = "root_dashboard-13-bounding-box";
final int widgetSequence = 0;

// clicking on the 'AddGadgetToDashboardTest' button

getPages().mashupRuntimePage().buttonWidget(ADD_GADGET_TO_DASHBOARD_TEST_BUTTON_WID
GET).click();

// giving a dummy test title


getPages().mashupRuntimePage().popUpElementLocator(POPUP_WIDGET_CLASS,
DASHBOARD_TITLE_ITEM_CLASS_NAME).enter(testGadgetTitle);

// click on the confirm button


getPages().mashupRuntimePage().popUpElementLocator(POPUP_WIDGET_CLASS,
CONFIRM_BUTTON_CLASS_NAME).click();

// refreshing the page, so that the newly added widget is reflected on the
UI.
getWebdriver().navigate().refresh();

getPages().mashupRuntimePage().waitForFocusOfWidget(ADD_GADGET_TO_DASHBOARD_TEST_BU
TTON_WIDGET);

// getting the newly added gadget's title


final String actualGadgetTitle =

getPages().mashupRuntimePage().containedMashupDashboardWidget(parentWidgetID,
widgetSequence).getAttribute("ref-title");

// this is the source text box value displayed on the dashboard.


final String sourceTextboxExpectedTextDescription =
getPages().mashupRuntimePage()
.containedMashupDashboardGadgetTextBox(parentWidgetID, widgetSequence,
SOURCE_TEXTBOX_GADGET).getAttribute("value");

// this is the source text box value displayed on the template left panel.
final String sourceTextboxActualTextDescription =
getPages().mashupRuntimePage().textboxWidget(TEMPLATE_MASHUP_CONTAINER
+ "_" + SOURCE_TEXTBOX_GADGET).getAttribute("value");

// this is the reflected text box value displayed on the dashboard.


final String reflectedTextboxExpectedTextDescription =
getPages().mashupRuntimePage()
.containedMashupDashboardGadgetTextBox(parentWidgetID, widgetSequence,
REFLECTED_TEXTBOX_GADGET).getAttribute("value");

// this is the reflected text box value displayed on the template left
panel
final String reflectedTextboxActualTextDescription =
getPages().mashupRuntimePage().textboxWidget(TEMPLATE_MASHUP_CONTAINER
+ "_" + REFLECTED_TEXTBOX_GADGET).getAttribute("value");

Assert.assertEquals(actualGadgetTitle, testGadgetTitle, "The title of the


newly created gadget is not correct");
Assert.assertEquals(sourceTextboxActualTextDescription,
sourceTextboxExpectedTextDescription,
"The source textbox values are not correct");
Assert.assertEquals(reflectedTextboxActualTextDescription,
reflectedTextboxExpectedTextDescription,
"The reflected textbox values are not correct");
}

@Requirements(reqs = { "TW-25364" })
@Test(
description = "Verify refresh service to check that the Textbox Widget
inside the Contained Mashup Widget " +
"contains 'Refresh Service Test Description' on clicking
the 'Refresh Test' button",
groups = { "FUNCTIONAL_TESTING", "CONTAINED_MASHUP" })
public void verifyRefreshServiceTest() throws Exception {

final String refrestTestExpectedTextDescription = "Refresh Service Test


Description";
final String refreshTestTextBoxGadget = "mashupcontainer-14_textbox-6";

// Checking if the default value of template refresh test textbox is empty


or not
final String refreshTestDefaultText =
getPages().mashupRuntimePage().textboxWidget(refreshTestTextBoxGadget).getAttribute
("value");
Assert.assertTrue(refreshTestDefaultText.isEmpty(),
"The default value of refresh test textbox should be empty but found "
+ refreshTestDefaultText);

// clicking on the refresh service test button

getPages().mashupRuntimePage().buttonWidget(REFRESH_TEST_BUTTON_WIDGET).click();

getPages().mashupRuntimePage().textboxWidget(refreshTestTextBoxGadget).waitForEleme
ntAttributeValueToBeEqualTo("value",
refrestTestExpectedTextDescription);

// this is the refresh test text box value displayed on the template left
panel after executing the Refresh Service.
final String refresTestActualTextDescription =

getPages().mashupRuntimePage().textboxWidget(refreshTestTextBoxGadget).getAttribute
("value");
Assert.assertEquals(refresTestActualTextDescription,
refrestTestExpectedTextDescription,
"The refresh service is not working properly as the text in refresh
test textbox is not correct");
}

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

getThingworxRESTUtils().deleteEntitiesByApplicationModelTag(ENTITY_APPLICATION_MODE
L_TAG_NAME);
}
}

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