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