Merge from ecomp 718fd196 - Integration Tests
[vid.git] / vid-automation / src / main / java / vid / automation / test / sections / ViewEditPage.java
1 package vid.automation.test.sections;
2
3 import org.junit.Assert;
4 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.By;
6 import org.openqa.selenium.WebElement;
7 import vid.automation.test.Constants;
8 import vid.automation.test.infra.Features;
9 import vid.automation.test.infra.Get;
10 import vid.automation.test.infra.SelectOption;
11
12 import static org.hamcrest.core.Is.is;
13
14 /**
15  * Created by itzikliderman on 13/06/2017.
16  */
17 public class ViewEditPage extends VidBasePage {
18     public ViewEditPage selectNodeInstanceToAdd(String vnfName) {
19         selectFromDropdownByTestId(Constants.ViewEdit.VNF_OPTION_TEST_ID_PREFIX + vnfName,
20                 Constants.ViewEdit.ADD_VNF_BUTTON_TEST_ID);
21         return this;
22     }
23
24     public ViewEditPage selectVfModuleToAdd(String vfModuleName) {
25         selectFromDropdownByTestId(Constants.ViewEdit.VF_MODULE_OPTION_TEST_ID_PREFIX + vfModuleName,
26                 Constants.ViewEdit.ADD_VF_MODULE_BUTTON_TEST_ID);
27         return this;
28     }
29
30     public ViewEditPage clickResumeButton(String instanceName) {
31         //instanceName = "my_vfModule";
32         String instanceId = Constants.ViewEdit.VF_MODULE_RESUME_ID_PREFIX + instanceName;
33         checkIfExistResumeButton(instanceName,true);
34         GeneralUIUtils.clickOnElementByTestId(instanceId);
35         return this;
36     }
37
38
39     public ViewEditPage checkIfExistResumeButton(String instanceName, Boolean expected) {
40         //instanceName = "my_vfModule";
41         String instanceId = Constants.ViewEdit.VF_MODULE_RESUME_ID_PREFIX + instanceName;
42         WebElement resumeButton = GeneralUIUtils.getWebElementByTestID(instanceId, 30);
43         Assert.assertThat(resumeButton != null, is(expected));
44         return this;
45     }
46
47     public ViewEditPage selectVolumeGroupToAdd(String volumeGroupName) {
48         selectFromDropdownByTestId(Constants.ViewEdit.VOLUME_GROUP_OPTION_TEST_ID_PREFIX + volumeGroupName,
49                 Constants.ViewEdit.ADD_VOLUME_GROUP_BUTTON_TEST_ID);
50         return this;
51     }
52
53     public ViewEditPage selectFromDropdownByText(String itemText, String dropdownButtonTestId) {
54         GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 30);
55         GeneralUIUtils.clickOnElementByText(itemText, 30);
56         return this;
57     }
58
59     public ViewEditPage selectNetworkToAdd(String networkName) {
60         selectFromDropdownByTestId(Constants.ViewEdit.NETWORK_OPTION_TEST_ID_PREFIX + networkName,
61                 Constants.ViewEdit.ADD_NETWORK_BUTTON_TEST_ID);
62         return this;
63     }
64
65     public ViewEditPage selectProductFamily(String productFamily){
66         SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
67         return this;
68     }
69
70     public ViewEditPage selectLcpRegion(String lcpRegion, String cloudOwner){
71         selectLcpRegion(lcpRegion);
72         if (Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST.isActive()) {
73             String selectedOption = SelectOption.getSelectedOption(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
74             Assert.assertEquals(lcpRegion + " (" + cloudOwner.toUpperCase() + ")", selectedOption);
75         }
76         return this;
77     }
78
79     public ViewEditPage selectLineOfBusiness(String lineOfBusiness, String cloudOwner){
80         selectLineOfBusiness(lineOfBusiness);
81         return this;
82     }
83
84     public ViewEditPage setLegacyRegion(String legacyRegionName){
85         setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, legacyRegionName);
86         return this;
87     }
88
89     public ViewEditPage selectTenant(String tenant){
90         SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
91        // GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.TENANT_SELECT_TESTS_ID, 60);
92         return this;
93     }
94
95     public VidBasePage clickActivateButton() {
96         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, 60);
97         return this;
98     }
99
100     public VidBasePage clickActivateFabricConfigurationButton() {
101         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.ACTIVATE_FABRIC_CONFIGURATION_BUTTON_TEST_ID, 60);
102         return this;
103     }
104     public VidBasePage clickInfoButton() {
105         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.INFOSERVICEBUTTON, 30);
106         return this;
107     }
108
109     public VidBasePage clickDeleteButton() {
110         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.DELETESERVICEBUTTON, 3);
111         return this;
112     }
113
114
115     public WebElement getPnf(String pnfName) {
116         WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: " + pnfName);
117         Assert.assertNotNull("Pnf "+ pnfName +" not found under service instance", pnfElement);
118         return pnfElement;
119     }
120
121     public ViewEditPage clickDissociatePnfButton(String pnfName) {
122         WebElement pnfToDissociate = getPnf(pnfName);
123         WebElement dissociateBtn = pnfToDissociate.findElement(By.className(Constants.ViewEdit.DISSOCIATE_BTN_CLASS));
124         Assert.assertNotNull("Dissociate button not found for pnf " + pnfName, dissociateBtn);
125         dissociateBtn.click();
126         return this;
127     }
128
129     public VidBasePage clickDeactivateButton() {
130         GeneralUIUtils.clickOnElementByTestId(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, 30);
131         return this;
132     }
133
134 //    public ViewEditPage selectLineOfBusiness(String lineOfBusiness) {
135 //        try {
136 //            SelectOption.selectFirstTwoOptionsFromMultiselectById(Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID);
137 //        } catch (InterruptedException e) {
138 //            e.printStackTrace();
139 //            return this;
140 //        }
141 //        //TODO multi SelectOption.byValue(lineOfBusiness, Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID);
142 //        return this;
143 //    }
144
145     public ViewEditPage selectPlatform(String platform) {
146         SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
147         return this;
148     }
149 }