b96a7d38db5c5b66bdda3274ea781ddc871b9195
[vid.git] / vid-automation / src / main / java / vid / automation / test / sections / ServiceProxyPage.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.WebElement;
6 import vid.automation.test.Constants;
7 import vid.automation.test.Constants.ViewEdit;
8 import vid.automation.test.infra.SelectOption;
9
10 import static org.hamcrest.core.Is.is;
11
12 public class ServiceProxyPage extends VidBasePage {
13
14     public ServiceProxyPage chooseSource(String source){
15         SelectOption.byTestIdAndVisibleText(source, Constants.ConfigurationCreation.SOURCE_DROPDOWN_TEST_ID);
16         return this;
17     }
18     public ServiceProxyPage chooseSourceServiceType(String sourceServiceType){
19         SelectOption.byTestIdAndVisibleText(sourceServiceType, "sourceServiceType");
20         GeneralUIUtils.ultimateWait();
21         return this;
22     }
23     public ServiceProxyPage chooseCollectorServiceType(String collectorServiceType){
24         SelectOption.byTestIdAndVisibleText(collectorServiceType, "collectorServiceType");
25         GeneralUIUtils.ultimateWait();
26         return this;
27     }
28     public void assertCollectorServiceType(String collectorServiceType) {
29         String displayedCollectorServiceType = SelectOption.getSelectedOption("collectorServiceType");
30         Assert.assertEquals("The displayed collector service type is incorrect", collectorServiceType, displayedCollectorServiceType);
31     }
32
33     public ServiceProxyPage chooseCollector(String collector){
34         GeneralUIUtils.ultimateWait();
35         SelectOption.byTestIdAndVisibleText(collector, Constants.ConfigurationCreation.COLLECTOR_DROPDOWN_TEST_ID);
36         return this;
37     }
38     public ServiceProxyPage clickCreateButton() {
39         GeneralUIUtils.clickOnElementByTestId(Constants.ConfigurationCreation.CREATE_BUTTON_TEST_ID, 60);
40         return this;
41     }
42
43     public ServiceProxyPage clickDeleteConfigurationButton() {
44         GeneralUIUtils.clickOnElementByTestId(deleteConfigurationButtonTestId(), 60);
45         return this;
46     }
47
48     private String configurationInstanceName() {
49         return "dummy_instance";
50     }
51
52     private String deleteConfigurationButtonTestId() {
53         return Constants.DELETE_CONFIGURATION_BUTTON + "-" + configurationInstanceName();
54     }
55
56     private String activateDeactivateButtonTestId() {
57         return Constants.ACTIVATE_DEACTIVATE_BUTTON + "-" + configurationInstanceName();
58     }
59
60     private String enableDisableButtonTestId(String portName) {
61         return Constants.ENABLE_DISABLE_BUTTON + "-" + configurationInstanceName() + "-" + portName;
62     }
63
64     public ServiceProxyPage assertDeleteConfigurationButtonExists(boolean shouldExist){
65
66         if (shouldExist) {
67             WebElement selectedV = GeneralUIUtils.getWebElementByTestID(deleteConfigurationButtonTestId(), 3);
68             Assert.assertThat(selectedV != null, is(shouldExist));
69             Assert.assertThat(selectedV.isDisplayed(), is(shouldExist));
70         } else {
71             boolean webElementExistByTestId = GeneralUIUtils.isWebElementExistByTestId(deleteConfigurationButtonTestId());
72             Assert.assertThat(webElementExistByTestId, is(shouldExist));
73         }
74         return this;
75     }
76
77     public void assertSourceModelName(String sourceName){
78         String displayedSourceName= getTextByTestID(Constants.ConfigurationCreation.SOURCE_INSTANCE_NAME_TEST_ID);
79         Assert.assertEquals("The displayed source name is not correct", sourceName+" i", displayedSourceName);
80     }
81
82     public void assertCollectorModelName(String collectorName) {
83         String displayedCollectorName = getTextByTestID(Constants.ConfigurationCreation.COLLECTOR_INSTANCE_NAME_TEST_ID);
84         Assert.assertEquals("The displayed collector name is not correct", collectorName+"i", displayedCollectorName);
85     }
86
87     public void assertNoResultRequirementsDropDown(String msgTestId, String resourceType){
88         String noResultText = GeneralUIUtils.getWebElementByTestID(msgTestId, 60).getText();
89         Assert.assertEquals("The error message no instance in DropDown is not match","No "+resourceType+" instances found.",noResultText);
90     }
91     public ServiceProxyPage clickInfoButton(String infoButtonTestId) {
92         GeneralUIUtils.clickOnElementByTestId(infoButtonTestId, 90);
93         return this;
94     }
95
96
97     public ServiceProxyPage assertSelectedInstanceIcon(String SelectedIconTestId){
98         WebElement selectedV = GeneralUIUtils.getWebElementByTestID(SelectedIconTestId, 90);
99         Assert.assertTrue(selectedV != null);
100         String selectedVClass = selectedV.getAttribute("class");
101         Assert.assertTrue(selectedVClass.contains("valid-large"));
102         return this;
103     }
104
105     public ServiceProxyPage clickActivateDeactivateButton() {
106         GeneralUIUtils.clickOnElementByTestId(activateDeactivateButtonTestId(), 60);
107         return this;
108     }
109
110     public ServiceProxyPage clickEnableDisableButton(){
111         GeneralUIUtils.clickOnElementByTestId(enableDisableButtonTestId(ViewEdit.COMMON_PORT_MIRRORING_PORT_NAME), 60);
112         return this;
113     }
114 }