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.JavascriptExecutor;
21 import org.openqa.selenium.TimeoutException;
22 import org.openqa.selenium.WebDriver;
23 import org.openqa.selenium.WebElement;
24 import org.openqa.selenium.support.ui.ExpectedConditions;
25 import org.openqa.selenium.support.ui.WebDriverWait;
26 import vid.automation.test.Constants;
27 import vid.automation.test.Constants.ViewEdit;
28 import vid.automation.test.infra.Click;
29 import vid.automation.test.infra.Exists;
30 import vid.automation.test.infra.Features;
31 import vid.automation.test.infra.Get;
32 import vid.automation.test.infra.Input;
33 import vid.automation.test.infra.SelectOption;
34 import vid.automation.test.infra.Wait;
36 public class VidBasePage {
39 public VidBasePage setInstanceName(String name) {
40 setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
45 public VidBasePage setLegacyRegion(String name) {
46 setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, name);
50 public String generateAndSetInstanceName(String prefix) {
51 String instanceName = generateInstanceName(prefix);
52 setInstanceName(instanceName);
56 public VidBasePage setInputText(String inputTestsId, String text) {
57 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
58 instanceNameInput.sendKeys(text);
62 public String getInputValue(String inputTestsId) {
63 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
64 return instanceNameInput.getAttribute("value");
67 public String generateInstanceName(String prefix) {
68 SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
69 Date now = Calendar.getInstance().getTime();
70 return prefix + sdf.format(now);
73 public VidBasePage selectServiceTypeByName(String serviceType) {
74 SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
77 public VidBasePage selectFromDropdownByTestId(String itemTestId, String dropdownButtonTestId) {
78 GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 60);
79 Assert.assertTrue(String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,itemTestId, dropdownButtonTestId),GeneralUIUtils.getWebElementByTestID(itemTestId) != null );
80 GeneralUIUtils.clickOnElementByTestId(itemTestId, 60);
83 public VidBasePage noOptionDropdownByTestId( String dropdownButtonTestId) {
84 List<WebElement> selectList= SelectOption.getList(dropdownButtonTestId);
85 Assert.assertTrue("The Select Input "+ dropdownButtonTestId+" should be empty",selectList.size()==1);
89 public static void selectSubscriberById(String subscriberId) {
90 SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
93 public VidBasePage selectSubscriberByName(String subscriberName) {
94 SelectOption.byTestIdAndVisibleText(subscriberName, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
98 public VidBasePage selectProductFamily(String productFamily) {
99 SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
103 public VidBasePage selectSuppressRollback(String shouldSuppress) {
104 SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
108 public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
109 Input.replaceText(serviceUUID, Constants.BROWSE_SEARCH);
110 GeneralUIUtils.ultimateWait();
111 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
112 GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
113 GeneralUIUtils.ultimateWait();
115 screenshotDeployDialog(serviceUUID);
120 public boolean isModelWithGivenServiceUUIDVisible(String serviceUUID) {
121 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
123 GeneralUIUtils.getWebElementByTestID(elementTestId, 10);
124 GeneralUIUtils.ultimateWait();
125 } catch (TimeoutException te) {
131 public void screenshotDeployDialog(String serviceUUID) {
133 GeneralUIUtils.ultimateWait();
134 GeneralUIUtils.ultimateWait(); // better screenshot
135 String screenshotName = "deployService-" + serviceUUID;
136 ExtentTestActions.addScreenshot(Status.INFO, screenshotName, screenshotName);
137 } catch (IOException e) {
138 throw new RuntimeException(e);
143 public VidBasePage clickEditViewByInstanceId(String instanceId) {
144 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
145 GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
150 public Boolean checkEditOrViewExistsByInstanceId(String instanceId) {
151 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
152 return Exists.byTestId(elementTestId);
157 public VidBasePage clickSubmitButton() {
158 GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
162 public VidBasePage clickCancelButton() {
163 Click.byId(Constants.generalCancelButtonId);
167 public VidBasePage clickCancelButtonByTestID() {
168 GeneralUIUtils.clickOnElementByTestId(Constants.CANCEL_BUTTON_TEST_ID, 30);
173 public VidBasePage clickConfirmButton() {
174 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
178 public VidBasePage clickConfirmButtonInResumeDelete() {
179 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
183 public VidBasePage clickButtonByTestId(String testId) {
184 GeneralUIUtils.clickOnElementByTestId(testId);
188 public VidBasePage clickCommitCloseButton() {
189 GeneralUIUtils.clickOnElementByTestId(Constants.COMMIT_CLOSE_BUTTON_ID, 30);
193 public VidBasePage clickCloseButton() {
194 return clickCloseButton(30);
197 public VidBasePage clickCloseButton(int customTimeout) {
198 GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, customTimeout);
202 public VidBasePage selectLcpRegion(String lcpRegion) {
203 return selectLcpRegion(lcpRegion, "AIC");
206 public VidBasePage selectLcpRegion(String lcpRegion, String cloudOwner) {
207 GeneralUIUtils.ultimateWait();
208 String visibleText = (Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST.isActive()) ?
209 String.format("%s (%s)", lcpRegion, cloudOwner) : lcpRegion;
210 SelectOption.byTestIdAndVisibleText(visibleText, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
214 public VidBasePage selectLineOfBusiness(String lineOfBusines) {
215 GeneralUIUtils.ultimateWait();
216 SelectOption.byValue(lineOfBusines, Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID);
220 public VidBasePage selectTenant(String tenant) {
221 GeneralUIUtils.ultimateWait();
222 SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
226 public VidBasePage selectAicZone(String aicZone) {
227 SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
231 public VidBasePage selectRollbackOption(boolean rollback) {
232 SelectOption.byValue(String.valueOf(rollback) , Constants.ViewEdit.ROLLBACK_TEST_ID);
236 public VidBasePage selectPlatform(String platform) {
237 SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
242 public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
243 assertButtonStateInternal(dataTestId, shouldBeEnabled,
244 (dataTestIdInner) -> GeneralUIUtils.getWebElementByTestID(dataTestIdInner, 60));
247 public void assertButtonStateEvenIfButtonNotVisible(String dataTestId, boolean shouldBeEnabled) {
248 // getInputElement is quite similar to getWebElementByTestID, but doesn't use
249 // the visibility predicate, so button is reachable bhind the grayed-out panel
250 assertButtonStateInternal(dataTestId, shouldBeEnabled,
251 (dataTestIdInner) -> GeneralUIUtils.getInputElement(dataTestIdInner));
254 protected void assertButtonStateInternal(String dataTestId, boolean shouldBeEnabled, Function<String,WebElement> strategy) {
255 GeneralUIUtils.ultimateWait();
256 boolean enabledElement= strategy.apply(dataTestId).getAttribute("disabled") == null;
257 if(shouldBeEnabled) {
258 Assert.assertTrue(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId), enabledElement);
260 Assert.assertFalse(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId),enabledElement);
264 public VidBasePage assertMsoRequestModal(String statusMsg) {
265 boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 20);
266 Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
271 public VidBasePage refreshPage() {
272 getDriver().navigate().refresh();
276 public String navigateTo(String path) {
277 String envUrl = System.getProperty("ENV_URL");
280 uri = new URI(envUrl);
281 } catch (URISyntaxException e) {
282 throw new RuntimeException(e);
284 String target = uri.resolve(path).toString();
287 getDriver().navigate().to(target);
288 GeneralUIUtils.ultimateWait();
293 public String getTextByTestID(String testId){
294 WebElement webElement= GeneralUIUtils.getWebElementByTestID(testId);
295 return webElement.getText();
298 public void checkAndCloseAlert(String expectedText) {
299 String alertText= Get.alertText();
300 Assert.assertEquals(expectedText, alertText);
303 public static void goToIframe() {
304 final long start = System.currentTimeMillis();
306 GeneralUIUtils.ultimateWait();
307 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start));
308 final WebDriver iframeReady = new WebDriverWait(getDriver(), 20).until(
309 ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe"))
311 Assert.assertNotNull("failed going into iframe", iframeReady);
313 final long start2 = System.currentTimeMillis();
314 GeneralUIUtils.ultimateWait();
315 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start2));
318 public static void goOutFromIframe(){
319 GeneralUIUtils.acceptDeadObjectException(GeneralUIUtils::ultimateWait);
320 getDriver().switchTo().defaultContent();
324 public void verifyOpenOldViewEdit(String serviceInstanceName, String serviceInstanceId, boolean openShouldBeEnabled, boolean checkPortMirroring, boolean checkAddVnf) {
325 InstantiationStatusPage.checkMenuItem(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openShouldBeEnabled, contextMenuOpen -> {
326 Click.byTestId(contextMenuOpen);
327 VidBasePage.goOutFromIframe();
328 GeneralUIUtils.ultimateWait();
330 Wait.byText("View/Edit Service Instance");
331 if (serviceInstanceId != null) {
332 Wait.byText(serviceInstanceId);
334 Wait.byText(serviceInstanceName);
336 if (checkPortMirroring) {
337 Wait.byText("Add node instance");
338 Wait.byText(ViewEdit.COMMON_PORT_MIRRORING_PORT_NAME);
342 // Validate bug fix - we open old popup in view/edit
343 Click.byTestId("addVNFButton");
344 Click.byTestId("addVNFOption-2017-488_PASQUALE-vPE 0");
345 assertThat(Get.byTestId("create-modal-title").getText(), containsString("a la carte"));
346 Click.byTestId("cancelButton");
347 //end of bug fix validation
350 screenshotDeployDialog("view-edit-" + serviceInstanceName);
351 SideMenu.navigateToMacroInstantiationStatus();
356 public static WebDriverWait waitUntilDriverIsReady(int time) {
357 return new WebDriverWait(getDriver(), (long)time);
360 public String getReduxState() {
361 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
362 String reduxState = (String)javascriptExecutor.executeScript("return window.sessionStorage.getItem('reduxState');");
363 System.out.println(reduxState);
367 public void setReduxState(String state) {
368 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
369 String script = String.format("window.sessionStorage.setItem('reduxState', '%s');", state);
370 System.out.println("executing script:");
371 System.out.println(script);
372 javascriptExecutor.executeScript(script);