1 package vid.automation.test.sections;
3 import com.aventstack.extentreports.Status;
4 import org.junit.Assert;
5 import org.onap.sdc.ci.tests.execute.setup.ExtentTestActions;
6 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
7 import org.openqa.selenium.*;
8 import org.openqa.selenium.support.ui.ExpectedConditions;
9 import org.openqa.selenium.support.ui.WebDriverWait;
10 import vid.automation.test.Constants;
11 import vid.automation.test.Constants.ViewEdit;
12 import vid.automation.test.infra.*;
14 import java.io.IOException;
16 import java.net.URISyntaxException;
17 import java.text.SimpleDateFormat;
18 import java.util.Calendar;
19 import java.util.Date;
20 import java.util.List;
21 import java.util.function.Function;
23 import static java.util.stream.Collectors.toMap;
24 import static org.hamcrest.CoreMatchers.containsString;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.onap.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
27 import static org.testng.Assert.assertEquals;
29 public class VidBasePage {
32 public VidBasePage setInstanceName(String name) {
33 setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
38 public VidBasePage setLegacyRegion(String name) {
39 setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, name);
43 public String generateAndSetInstanceName(String prefix) {
44 String instanceName = generateInstanceName(prefix);
45 setInstanceName(instanceName);
49 public VidBasePage setInputText(String inputTestsId, String text) {
50 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
51 instanceNameInput.sendKeys(text);
55 public String getInputValue(String inputTestsId) {
56 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
57 return instanceNameInput.getAttribute("value");
60 public String generateInstanceName(String prefix) {
61 SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
62 Date now = Calendar.getInstance().getTime();
63 return prefix + sdf.format(now);
66 public VidBasePage selectServiceTypeByName(String serviceType) {
67 SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
70 public VidBasePage selectFromDropdownByTestId(String itemTestId, String dropdownButtonTestId) {
71 GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 60);
72 Assert.assertTrue(String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,itemTestId, dropdownButtonTestId),GeneralUIUtils.getWebElementByTestID(itemTestId) != null );
73 GeneralUIUtils.clickOnElementByTestId(itemTestId, 60);
76 public VidBasePage noOptionDropdownByTestId( String dropdownButtonTestId) {
77 List<WebElement> selectList= SelectOption.getList(dropdownButtonTestId);
78 Assert.assertTrue("The Select Input "+ dropdownButtonTestId+" should be empty",selectList.size()==1);
82 public static void selectSubscriberById(String subscriberId) {
83 SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
86 public VidBasePage selectSubscriberByName(String subscriberName) {
87 SelectOption.byTestIdAndVisibleText(subscriberName, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
91 public VidBasePage selectProductFamily(String productFamily) {
92 SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
96 public VidBasePage selectSuppressRollback(String shouldSuppress) {
97 SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
101 public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
102 Input.replaceText(serviceUUID, Constants.BROWSE_SEARCH);
103 GeneralUIUtils.ultimateWait();
104 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
105 GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
106 GeneralUIUtils.ultimateWait();
108 screenshotDeployDialog(serviceUUID);
113 public boolean isModelWithGivenServiceUUIDVisible(String serviceUUID) {
114 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
116 GeneralUIUtils.getWebElementByTestID(elementTestId, 10);
117 GeneralUIUtils.ultimateWait();
118 } catch (TimeoutException te) {
124 public void screenshotDeployDialog(String serviceUUID) {
126 GeneralUIUtils.ultimateWait();
127 GeneralUIUtils.ultimateWait(); // better screenshot
128 String screenshotName = "deployService-" + serviceUUID;
129 ExtentTestActions.addScreenshot(Status.INFO, screenshotName, screenshotName);
130 } catch (IOException e) {
131 throw new RuntimeException(e);
136 public VidBasePage clickEditViewByInstanceId(String instanceId) {
137 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
138 GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
143 public Boolean checkEditOrViewExistsByInstanceId(String instanceId) {
144 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
145 return Exists.byTestId(elementTestId);
150 public VidBasePage clickSubmitButton() {
151 GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
155 public VidBasePage clickCancelButton() {
156 Click.byId(Constants.generalCancelButtonId);
160 public VidBasePage clickCancelButtonByTestID() {
161 GeneralUIUtils.clickOnElementByTestId(Constants.CANCEL_BUTTON_TEST_ID, 30);
166 public VidBasePage clickConfirmButton() {
167 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
171 public VidBasePage clickConfirmButtonInResumeDelete() {
172 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
176 public VidBasePage clickButtonByTestId(String testId) {
177 GeneralUIUtils.clickOnElementByTestId(testId);
181 public VidBasePage clickCommitCloseButton() {
182 GeneralUIUtils.clickOnElementByTestId(Constants.COMMIT_CLOSE_BUTTON_ID, 30);
186 public VidBasePage clickCloseButton() {
187 return clickCloseButton(30);
190 public VidBasePage clickCloseButton(int customTimeout) {
191 GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, customTimeout);
195 public VidBasePage selectLcpRegion(String lcpRegion) {
196 return selectLcpRegion(lcpRegion, "AIC");
199 public VidBasePage selectLcpRegion(String lcpRegion, String cloudOwner) {
200 GeneralUIUtils.ultimateWait();
201 String visibleText = (Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST.isActive()) ?
202 String.format("%s (%s)", lcpRegion, cloudOwner) : lcpRegion;
203 SelectOption.byTestIdAndVisibleText(visibleText, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
207 public VidBasePage selectLineOfBusiness(String lineOfBusines) {
208 GeneralUIUtils.ultimateWait();
209 SelectOption.byValue(lineOfBusines, Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID);
213 public VidBasePage selectTenant(String tenant) {
214 GeneralUIUtils.ultimateWait();
215 SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
219 public VidBasePage selectAicZone(String aicZone) {
220 SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
224 public VidBasePage selectRollbackOption(boolean rollback) {
225 SelectOption.byValue(String.valueOf(rollback) , Constants.ViewEdit.ROLLBACK_TEST_ID);
229 public VidBasePage selectPlatform(String platform) {
230 SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
235 public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
236 assertButtonStateInternal(dataTestId, shouldBeEnabled,
237 (dataTestIdInner) -> GeneralUIUtils.getWebElementByTestID(dataTestIdInner, 60));
240 public void assertButtonStateEvenIfButtonNotVisible(String dataTestId, boolean shouldBeEnabled) {
241 // getInputElement is quite similar to getWebElementByTestID, but doesn't use
242 // the visibility predicate, so button is reachable bhind the grayed-out panel
243 assertButtonStateInternal(dataTestId, shouldBeEnabled,
244 (dataTestIdInner) -> GeneralUIUtils.getInputElement(dataTestIdInner));
247 protected void assertButtonStateInternal(String dataTestId, boolean shouldBeEnabled, Function<String,WebElement> strategy) {
248 GeneralUIUtils.ultimateWait();
249 boolean enabledElement= strategy.apply(dataTestId).getAttribute("disabled") == null;
250 if(shouldBeEnabled) {
251 Assert.assertTrue(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId), enabledElement);
253 Assert.assertFalse(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId),enabledElement);
257 public VidBasePage assertMsoRequestModal(String statusMsg) {
258 boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 20);
259 Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
264 public VidBasePage refreshPage() {
265 getDriver().navigate().refresh();
269 public String navigateTo(String path) {
270 String envUrl = System.getProperty("ENV_URL");
273 uri = new URI(envUrl);
274 } catch (URISyntaxException e) {
275 throw new RuntimeException(e);
277 String target = uri.resolve(path).toString();
279 getDriver().navigate().to(target);
280 GeneralUIUtils.ultimateWait();
285 public String getTextByTestID(String testId){
286 WebElement webElement= GeneralUIUtils.getWebElementByTestID(testId);
287 return webElement.getText();
290 public void checkAndCloseAlert(String expectedText) {
291 String alertText= Get.alertText();
292 Assert.assertEquals(expectedText, alertText);
295 public static void goToIframe() {
296 final long start = System.currentTimeMillis();
298 GeneralUIUtils.ultimateWait();
299 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start));
300 final WebDriver iframeReady = new WebDriverWait(getDriver(), 20).until(
301 ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe"))
303 Assert.assertNotNull("failed going into iframe", iframeReady);
305 final long start2 = System.currentTimeMillis();
306 GeneralUIUtils.ultimateWait();
307 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start2));
310 public static void goOutFromIframe(){
311 getDriver().switchTo().defaultContent();
315 public void verifyOpenOldViewEdit(String serviceInstanceName, String serviceInstanceId, boolean openShouldBeEnabled, boolean checkPortMirroring, boolean checkAddVnf) {
316 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openShouldBeEnabled, contextMenuOpen -> {
317 Click.byTestId(contextMenuOpen);
318 VidBasePage.goOutFromIframe();
319 GeneralUIUtils.ultimateWait();
321 Wait.byText("View/Edit Service Instance");
322 if (serviceInstanceId != null) {
323 Wait.byText(serviceInstanceId);
325 Wait.byText(serviceInstanceName);
327 if (checkPortMirroring) {
328 Wait.byText("Add node instance");
329 Wait.byText(ViewEdit.COMMON_PORT_MIRRORING_PORT_NAME);
333 // Validate bug fix - we open old popup in view/edit
334 Click.byTestId("addVNFButton");
335 Click.byTestId("addVNFOption-2017-488_PASQUALE-vPE 0");
336 assertThat(Get.byTestId("create-modal-title").getText(), containsString("a la carte"));
337 Click.byTestId("cancelButton");
338 //end of bug fix validation
341 screenshotDeployDialog("view-edit-" + serviceInstanceName);
342 SideMenu.navigateToMacroInstantiationStatus();
347 public static WebDriverWait waitUntilDriverIsReady(int time) {
348 return new WebDriverWait(getDriver(), (long)time);
351 public String getReduxState() {
352 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
353 String reduxState = (String)javascriptExecutor.executeScript("return window.sessionStorage.getItem('reduxState');");
354 System.out.println(reduxState);
358 public void setReduxState(String state) {
359 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
360 String script = String.format("window.sessionStorage.setItem('reduxState', '%s');", state);
361 System.out.println("executing script:");
362 System.out.println(script);
363 javascriptExecutor.executeScript(script);