1 package vid.automation.test.sections;
3 import static org.hamcrest.CoreMatchers.containsString;
4 import static org.hamcrest.MatcherAssert.assertThat;
5 import static org.onap.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
7 import com.aventstack.extentreports.Status;
8 import java.io.IOException;
10 import java.net.URISyntaxException;
11 import java.text.SimpleDateFormat;
12 import java.util.Calendar;
13 import java.util.Date;
14 import java.util.List;
15 import java.util.function.Function;
16 import org.junit.Assert;
17 import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions;
18 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
19 import org.openqa.selenium.By;
20 import org.openqa.selenium.WebDriver;
21 import org.openqa.selenium.WebElement;
22 import org.openqa.selenium.support.ui.ExpectedConditions;
23 import org.openqa.selenium.support.ui.WebDriverWait;
24 import vid.automation.test.Constants;
25 import vid.automation.test.infra.Click;
26 import vid.automation.test.infra.Exists;
27 import vid.automation.test.infra.Get;
28 import vid.automation.test.infra.Input;
29 import vid.automation.test.infra.SelectOption;
30 import vid.automation.test.infra.Wait;
32 public class VidBasePage {
35 public VidBasePage setInstanceName(String name) {
36 setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
41 public VidBasePage setLegacyRegion(String name) {
42 setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, name);
46 public String generateAndSetInstanceName(String prefix) {
47 String instanceName = generateInstanceName(prefix);
48 setInstanceName(instanceName);
52 public VidBasePage setInputText(String inputTestsId, String text) {
53 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
54 instanceNameInput.sendKeys(text);
58 public String getInputValue(String inputTestsId) {
59 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
60 String value =instanceNameInput.getAttribute("value");
64 public String generateInstanceName(String prefix) {
65 SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
66 Date now = Calendar.getInstance().getTime();
67 return prefix + sdf.format(now);
70 public VidBasePage selectServiceTypeByName(String serviceType) {
71 SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
74 public VidBasePage selectFromDropdownByTestId(String itemTestId, String dropdownButtonTestId) {
75 GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 60);
76 Assert.assertTrue(String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,itemTestId, dropdownButtonTestId),GeneralUIUtils.getWebElementByTestID(itemTestId) != null );
77 GeneralUIUtils.clickOnElementByTestId(itemTestId, 60);
80 public VidBasePage noOptionDropdownByTestId( String dropdownButtonTestId) {
81 List<WebElement> selectList= SelectOption.getList(dropdownButtonTestId);
82 Assert.assertTrue("The Select Input "+ dropdownButtonTestId+" should be empty",selectList.size()==1);
86 public static void selectSubscriberById(String subscriberId) {
87 SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
90 public VidBasePage selectSubscriberByName(String subscriberName) {
91 SelectOption.byTestIdAndVisibleText(subscriberName, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
95 public VidBasePage selectProductFamily(String productFamily) {
96 SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
100 public VidBasePage selectSuppressRollback(String shouldSuppress) {
101 SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
105 public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
106 Input.replaceText(serviceUUID, Constants.BROWSE_SEARCH);
107 GeneralUIUtils.ultimateWait();
108 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
109 GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
110 GeneralUIUtils.ultimateWait();
112 screenshotDeployDialog(serviceUUID);
117 public void screenshotDeployDialog(String serviceUUID) {
119 GeneralUIUtils.ultimateWait();
120 GeneralUIUtils.ultimateWait(); // better screenshot
121 String screenshotName = "deployService-" + serviceUUID;
122 ExtentTestActions.addScreenshot(Status.INFO, screenshotName, screenshotName);
123 } catch (IOException e) {
124 throw new RuntimeException(e);
129 public VidBasePage clickEditViewByInstanceId(String instanceId) {
130 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
131 GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
136 public Boolean checkEditOrViewExistsByInstanceId(String instanceId) {
137 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
138 return Exists.byTestId(elementTestId);
143 public VidBasePage clickSubmitButton() {
144 GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
148 public VidBasePage clickCancelButton() {
149 Click.byId(Constants.generalCancelButtonId);
153 public VidBasePage clickCancelButtonByTestID() {
154 GeneralUIUtils.clickOnElementByTestId(Constants.CANCEL_BUTTON_TEST_ID, 30);
159 public VidBasePage clickConfirmButton() {
160 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
164 public VidBasePage clickConfirmButtonInResumeDelete() {
165 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
169 public VidBasePage clickButtonByTestId(String testId) {
170 GeneralUIUtils.clickOnElementByTestId(testId);
174 public VidBasePage clickCommitCloseButton() {
175 GeneralUIUtils.clickOnElementByTestId(Constants.COMMIT_CLOSE_BUTTON_ID, 30);
179 public VidBasePage clickCloseButton() {
180 return clickCloseButton(30);
183 public VidBasePage clickCloseButton(int customTimeout) {
184 GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, customTimeout);
189 public VidBasePage selectLcpRegion(String lcpRegion) {
190 GeneralUIUtils.ultimateWait();
191 SelectOption.byValue(lcpRegion, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
195 public VidBasePage selectTenant(String tenant) {
196 GeneralUIUtils.ultimateWait();
197 SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
201 public VidBasePage selectAicZone(String aicZone) {
202 SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
206 public VidBasePage selectRollbackOption(boolean rollback) {
207 SelectOption.byValue(String.valueOf(rollback) , Constants.ViewEdit.ROLLBACK_TEST_ID);
211 public VidBasePage selectPlatform(String platform) {
212 SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
216 public VidBasePage selectLineOfBusiness(String lob) {
217 SelectOption.byValue(lob, Constants.OwningEntity.LOB_SELECT_TEST_ID);
221 public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
222 assertButtonStateInternal(dataTestId, shouldBeEnabled,
223 (dataTestIdInner) -> GeneralUIUtils.getWebElementByTestID(dataTestIdInner, 60));
226 public void assertButtonStateEvenIfButtonNotVisible(String dataTestId, boolean shouldBeEnabled) {
227 // getInputElement is quite similar to getWebElementByTestID, but doesn't use
228 // the visibility predicate, so button is reachable bhind the grayed-out panel
229 assertButtonStateInternal(dataTestId, shouldBeEnabled,
230 (dataTestIdInner) -> GeneralUIUtils.getInputElement(dataTestIdInner));
233 protected void assertButtonStateInternal(String dataTestId, boolean shouldBeEnabled, Function<String,WebElement> strategy) {
234 GeneralUIUtils.ultimateWait();
235 boolean enabledElement= strategy.apply(dataTestId).getAttribute("disabled") == null;
236 if(shouldBeEnabled) {
237 Assert.assertTrue(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId), enabledElement);
239 Assert.assertFalse(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId),enabledElement);
243 public VidBasePage assertMsoRequestModal(String statusMsg) {
244 boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 20);
245 Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
250 public VidBasePage refreshPage() {
251 getDriver().navigate().refresh();
255 public String navigateTo(String path) {
256 String envUrl = System.getProperty("ENV_URL");
259 uri = new URI(envUrl);
260 } catch (URISyntaxException e) {
261 throw new RuntimeException(e);
263 String target = uri.resolve(path).toString();
265 getDriver().navigate().to(target);
266 GeneralUIUtils.ultimateWait();
271 public String getTextByTestID(String testId){
272 WebElement webElement= GeneralUIUtils.getWebElementByTestID(testId);
273 return webElement.getText();
276 public void checkAndCloseAlert(String expectedText) {
277 String alertText= Get.alertText();
278 Assert.assertEquals(expectedText, alertText);
281 public static void goToIframe() {
282 final long start = System.currentTimeMillis();
284 GeneralUIUtils.ultimateWait();
285 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start));
286 final WebDriver iframeReady = new WebDriverWait(getDriver(), 20).until(
287 ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe"))
289 Assert.assertNotNull("failed going into iframe", iframeReady);
291 final long start2 = System.currentTimeMillis();
292 GeneralUIUtils.ultimateWait();
293 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start2));
296 public static void goOutFromIframe(){
297 getDriver().switchTo().defaultContent();
301 public void verifyOpenOldViewEdit(String serviceInstanceName, String serviceInstanceId, boolean openShouldBeEnabled, boolean checkPortMirroring, boolean checkAddVnf) {
302 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openShouldBeEnabled, contextMenuOpen -> {
303 Click.byTestId(contextMenuOpen);
304 VidBasePage.goOutFromIframe();
305 GeneralUIUtils.ultimateWait();
307 Wait.byText("View/Edit Service Instance");
308 if (serviceInstanceId != null) {
309 Wait.byText(serviceInstanceId);
311 Wait.byText(serviceInstanceName);
313 if (checkPortMirroring) {
314 Wait.byText("Add node instance");
315 Wait.byText("i'm a port");
319 // Validate bug fix - we open old popup in view/edit
320 Click.byTestId("addVNFButton");
321 Click.byTestId("addVNFOption-2017-488_PASQUALE-vPE 0");
322 assertThat(Get.byTestId("create-modal-title").getText(), containsString("a la carte"));
323 Click.byTestId("cancelButton");
324 //end of bug fix validation
327 screenshotDeployDialog("view-edit-" + serviceInstanceName);
328 SideMenu.navigateToMacroInstantiationStatus();
333 public static WebDriverWait waitUntilDriverIsReady(int time) {
334 return new WebDriverWait(getDriver(), (long)time);