org.onap migration
[vid.git] / vid-automation / src / main / java / vid / automation / test / sections / VidBasePage.java
1 package vid.automation.test.sections;
2
3 import org.junit.Assert;
4 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.WebElement;
6 import vid.automation.test.Constants;
7 import vid.automation.test.infra.Click;
8 import vid.automation.test.infra.SelectOption;
9 import vid.automation.test.infra.Wait;
10
11 import java.text.SimpleDateFormat;
12 import java.util.Calendar;
13 import java.util.Date;
14
15 public class VidBasePage {
16
17     public VidBasePage setInstanceName(String name) {
18         setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
19         return this;
20     }
21
22     public void generateAndSetInstanceName(String prefix) {
23         String instanceName = generateInstanceName(prefix);
24         setInstanceName(instanceName);
25     }
26
27     public VidBasePage setInputText(String inputTestsId, String text) {
28         WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
29         instanceNameInput.sendKeys(text);
30         return this;
31     }
32
33     public String generateInstanceName(String prefix) {
34         SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
35         Date now = Calendar.getInstance().getTime();
36         return prefix + sdf.format(now);
37     }
38
39     public VidBasePage selectServiceTypeByName(String serviceType) {
40         SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
41         return this;
42     }
43
44     public static void selectSubscriberById(String subscriberId) {
45         SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
46     }
47
48     public VidBasePage selectProductFamily(String productFamily) {
49         SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
50         return this;
51     }
52
53     public VidBasePage selectSuppressRollback(String shouldSuppress) {
54         SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
55         return this;
56     }
57
58     public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
59         setInputText(Constants.BROWSE_SEARCH, serviceUUID);
60         String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
61         GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
62         GeneralUIUtils.ultimateWait();
63         return this;
64     }
65
66     public VidBasePage clickEditViewByInstanceId(String instanceId) {
67         String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
68         GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
69         GeneralUIUtils.ultimateWait();
70         return this;
71     }
72
73     public VidBasePage clickSubmitButton() {
74         GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
75         return this;
76     }
77
78     public VidBasePage clickCancelButton() {
79         Click.byId(Constants.generalCancelButtonId);
80         return this;
81     }
82
83
84     public VidBasePage clickConfirmButton() {
85         GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
86         return this;
87     }
88
89     public VidBasePage clickCloseButton() {
90         GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, 30);
91         return this;
92     }
93
94     public VidBasePage selectLcpRegion(String lcpRegion) {
95         SelectOption.byValue(lcpRegion, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
96         return this;
97     }
98
99     public VidBasePage selectTenant(String tenant) {
100         SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
101         return this;
102     }
103
104     public VidBasePage selectAicZone(String aicZone) {
105         SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
106         return this;
107     }
108
109     public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
110         GeneralUIUtils.ultimateWait();
111         WebElement webElement = GeneralUIUtils.getWebElementByTestID(dataTestId, 60);
112         boolean enabledElement= webElement.getAttribute("disabled")==null?true:false;
113         if(shouldBeEnabled) {
114             Assert.assertTrue(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId), enabledElement);
115         }else{
116             Assert.assertFalse(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId),enabledElement);
117         }
118
119     }
120     public VidBasePage assertMsoRequestModal(String statusMsg) {
121         boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 60);
122         Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
123
124         return this;
125     }
126
127     public VidBasePage refreshPage() {
128         GeneralUIUtils.getDriver().navigate().refresh();
129         return this;
130     }
131
132 }