aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java
blob: d4e09be2de9db3d2ae2d816d6024941564b1b144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package vid.automation.test.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.openecomp.sdc.ci.tests.datatypes.Configuration;
import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.utilities.FileHandling;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import vid.automation.test.Constants;
import vid.automation.test.infra.Click;
import vid.automation.test.infra.SelectOption;
import vid.automation.test.model.*;
import vid.automation.test.sections.*;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static org.testng.AssertJUnit.fail;


public class VidBaseTestCase extends SetupCDTest {

    static String currentUserId = null;

    @Override
    protected UserCredentials getUserCredentials() {
        ObjectMapper mapper = new ObjectMapper().enableDefaultTyping();
        try {
            File configFile = FileHandling.getConfigFile("credentials");
            if(!configFile.exists()) {
                String basePath = System.getProperty("BASE_PATH");
                configFile = new File( basePath + File.separator + "conf" + File.separator + "credentials");
            }
            Credentials credentials = mapper.readValue(configFile, Credentials.class);
            return new UserCredentials(credentials.userId, credentials.password, "", "", "");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    protected org.openecomp.sdc.ci.tests.datatypes.Configuration getEnvConfiguration() {

        try {
            String envUrl = System.getProperty("ENV_URL");
            boolean isCustomLogin = Boolean.valueOf(System.getProperty("CUSTOM_LOGIN"));
            Configuration configuration = new org.openecomp.sdc.ci.tests.datatypes.Configuration(envUrl, isCustomLogin);
            //configuration.setBrowser("chorme");
            return configuration;
            //return new org.openecomp.sdc.ci.tests.datatypes.Configuration(envUrl, isCustomLogin);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    protected void loginToLocalSimulator(UserCredentials userCredentials) {
        LoginExternalPage.performLoginExternal(userCredentials);
    }

    protected void relogin(Credentials credentials) throws Exception {
        if (!credentials.userId.equals(currentUserId)) {
            currentUserId = credentials.userId;
            UserCredentials userCredentials = new UserCredentials(credentials.userId,
                    credentials.password, "", "", "");
            reloginWithNewRole(userCredentials);
        }
    }

    /**
     * Validates that permitted options are enabled and others are disabled.
     *
     * @param permittedItems           the list of permitted items.
     * @param dropdownOptionsClassName the class name of the specific dropdown options.
     * @return true, if all dropdown options disabled state is according to the permissions.
     */
    protected void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
        GeneralUIUtils.ultimateWait();
        List<WebElement> optionsList =
                GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
        for (WebElement option :
                optionsList) {
            String optionValue = option.getAttribute("value");
            if ((option.isEnabled() && !permittedItems.contains(optionValue)) ||
                    !option.isEnabled() && permittedItems.contains(optionValue)) {
                fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
            }
        }
    }

    protected void assertAllIsPermitted(String dropdownOptionsClassName) {
        GeneralUIUtils.ultimateWait();
        List<WebElement> optionsList =
                GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
        for (WebElement option :
                optionsList) {
            String optionValue = option.getAttribute("value");
            if (!option.isEnabled()) {
                fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
            }
        }
    }

    protected void assertDropdownPermittedItemsByName(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
        GeneralUIUtils.ultimateWait();
        List<WebElement> optionsList =
                GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
        for (WebElement option :
                optionsList) {
            String optionText = option.getText();
            if ((option.isEnabled() && !permittedItems.contains(optionText)) ||
                    !option.isEnabled() && permittedItems.contains(optionText)) {
                fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
            }
        }
    }

    protected void assertViewEditButtonState(String expectedButtonText, String UUID) {
        WebElement viewEditWebElement = GeneralUIUtils.getWebElementByTestID(Constants.VIEW_EDIT_TEST_ID_PREFIX + UUID, 100);
        Assert.assertEquals(expectedButtonText, viewEditWebElement.getText());
        GeneralUIUtils.ultimateWait();
    }

    protected void addVNF(String name, String lcpRegion, String tenant, String suppressRollback,
                          String legacyRegion, String productFamily, ArrayList<String> permittedTenants) throws InterruptedException {
        ViewEditPage viewEditPage = new ViewEditPage();

        viewEditPage.selectNodeInstanceToAdd(name);
        viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VNF_INSTANCE_NAME_PREFIX);
        viewEditPage.selectProductFamily(productFamily);
        viewEditPage.selectLCPRegion(lcpRegion);

        assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
        viewEditPage.selectTenant(tenant);

        Click.onFirstSelectOptionById(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
        SelectOption.selectFirstTwoOptionsFromMultiselectById(Constants.OwningEntity.LOB_SELECT_TEST_ID);

        viewEditPage.selectSuppressRollback(suppressRollback);

        viewEditPage.setLegacyRegion(legacyRegion);

        viewEditPage.clickConfirmButton();
        assertSuccessfulVNFCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    protected void addVFModule(String name, String lcpRegion, String tenant, String suppressRollback,
                               String legacyRegion, ArrayList<String> permittedTenants) {
        ViewEditPage viewEditPage = new ViewEditPage();

        viewEditPage.selectVolumeGroupToAdd(name);
        viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VF_MODULE_INSTANCE_NAME_PREFIX);
        viewEditPage.selectLCPRegion(lcpRegion);

        assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
        viewEditPage.selectTenant(tenant);

        viewEditPage.selectSuppressRollback(suppressRollback);

        viewEditPage.setLegacyRegion(legacyRegion);

        viewEditPage.clickConfirmButton();
        assertSuccessfulVFModuleCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    protected void addVolumeGroup(String name, String lcpRegion, String tenant, String suppressRollback,
                                  String legacyRegion, ArrayList<String> permittedTenants) {
        ViewEditPage viewEditPage = new ViewEditPage();

        viewEditPage.selectVolumeGroupToAdd(name);
        viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VOLUME_GROUP_INSTANCE_NAME_PREFIX);
        viewEditPage.selectLCPRegion(lcpRegion);

        assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
        viewEditPage.selectTenant(tenant);

        viewEditPage.selectSuppressRollback(suppressRollback);

        viewEditPage.setLegacyRegion(legacyRegion);

        viewEditPage.clickConfirmButton();
        assertSuccessfulVolumeGroupCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    void assertSuccessfulVNFCreation() {
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VNF_CREATED_SUCCESSFULLY_TEXT, 100);
        Assert.assertTrue(Constants.ViewEdit.VNF_CREATION_FAILED_MESSAGE, byText);
    }

    void assertSuccessfulPNFAssociation() {
        //TODO
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.PnfAssociation.PNF_ASSOCIATED_SUCCESSFULLY_TEXT, 100);
        Assert.assertTrue(Constants.PnfAssociation.PNF_ASSOCIATED_FAILED_MESSAGE, byText);
    }
    void assertSuccessfulVolumeGroupCreation() {
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VOLUME_GROUP_CREATED_SUCCESSFULLY_TEXT, 100);
        Assert.assertTrue(Constants.ViewEdit.VOLUME_GROUP_CREATION_FAILED_MESSAGE, byText);
    }

    void assertSuccessfulVFModuleCreation() {
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VF_MODULE_CREATED_SUCCESSFULLY_TEXT, 100);
        Assert.assertTrue(Constants.ViewEdit.VF_MODULE_CREATION_FAILED_MESSAGE, byText);
    }

    void goToExistingInstanceById(String instanceUUID) {
        SearchExistingPage searchExistingPage = new SearchExistingPage();
        SideMenu.navigateToSearchExistingPage();
        searchExistingPage.searchForInstanceByUuid(instanceUUID);
        assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceUUID);
        searchExistingPage.clickEditViewByInstanceId(instanceUUID);
    }

    void goToExistingInstanceByName(String instanceName) {
        SearchExistingPage searchExistingPage = new SearchExistingPage();
        SideMenu.navigateToSearchExistingPage();
        searchExistingPage.searchForInstanceByName(instanceName);
        WebElement instanceIdRow = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
        String instanceId = instanceIdRow.getText();
        assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceId);
        searchExistingPage.clickEditViewByInstanceId(instanceId);
    }

}