1 package vid.automation.test.test;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import org.junit.Assert;
5 import org.openecomp.sdc.ci.tests.datatypes.Configuration;
6 import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
7 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
8 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
9 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
10 import org.openqa.selenium.By;
11 import org.openqa.selenium.WebElement;
12 import vid.automation.test.Constants;
13 import vid.automation.test.infra.Click;
14 import vid.automation.test.infra.SelectOption;
15 import vid.automation.test.model.*;
16 import vid.automation.test.sections.*;
19 import java.util.ArrayList;
20 import java.util.List;
22 import static org.testng.AssertJUnit.fail;
25 public class VidBaseTestCase extends SetupCDTest {
27 static String currentUserId = null;
30 protected UserCredentials getUserCredentials() {
31 ObjectMapper mapper = new ObjectMapper().enableDefaultTyping();
33 File configFile = FileHandling.getConfigFile("credentials");
34 if(!configFile.exists()) {
35 String basePath = System.getProperty("BASE_PATH");
36 configFile = new File( basePath + File.separator + "conf" + File.separator + "credentials");
38 Credentials credentials = mapper.readValue(configFile, Credentials.class);
39 return new UserCredentials(credentials.userId, credentials.password, "", "", "");
40 } catch (Exception e) {
47 protected org.openecomp.sdc.ci.tests.datatypes.Configuration getEnvConfiguration() {
50 String envUrl = System.getProperty("ENV_URL");
51 boolean isCustomLogin = Boolean.valueOf(System.getProperty("CUSTOM_LOGIN"));
52 Configuration configuration = new org.openecomp.sdc.ci.tests.datatypes.Configuration(envUrl, isCustomLogin);
53 //configuration.setBrowser("chorme");
55 //return new org.openecomp.sdc.ci.tests.datatypes.Configuration(envUrl, isCustomLogin);
56 } catch (Exception e) {
63 protected void loginToLocalSimulator(UserCredentials userCredentials) {
64 LoginExternalPage.performLoginExternal(userCredentials);
67 protected void relogin(Credentials credentials) throws Exception {
68 if (!credentials.userId.equals(currentUserId)) {
69 currentUserId = credentials.userId;
70 UserCredentials userCredentials = new UserCredentials(credentials.userId,
71 credentials.password, "", "", "");
72 reloginWithNewRole(userCredentials);
77 * Validates that permitted options are enabled and others are disabled.
79 * @param permittedItems the list of permitted items.
80 * @param dropdownOptionsClassName the class name of the specific dropdown options.
81 * @return true, if all dropdown options disabled state is according to the permissions.
83 protected void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
84 GeneralUIUtils.ultimateWait();
85 List<WebElement> optionsList =
86 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
87 for (WebElement option :
89 String optionValue = option.getAttribute("value");
90 if ((option.isEnabled() && !permittedItems.contains(optionValue)) ||
91 !option.isEnabled() && permittedItems.contains(optionValue)) {
92 fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
97 protected void assertAllIsPermitted(String dropdownOptionsClassName) {
98 GeneralUIUtils.ultimateWait();
99 List<WebElement> optionsList =
100 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
101 for (WebElement option :
103 String optionValue = option.getAttribute("value");
104 if (!option.isEnabled()) {
105 fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
110 protected void assertDropdownPermittedItemsByName(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
111 GeneralUIUtils.ultimateWait();
112 List<WebElement> optionsList =
113 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
114 for (WebElement option :
116 String optionText = option.getText();
117 if ((option.isEnabled() && !permittedItems.contains(optionText)) ||
118 !option.isEnabled() && permittedItems.contains(optionText)) {
119 fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
124 protected void assertViewEditButtonState(String expectedButtonText, String UUID) {
125 WebElement viewEditWebElement = GeneralUIUtils.getWebElementByTestID(Constants.VIEW_EDIT_TEST_ID_PREFIX + UUID, 100);
126 Assert.assertEquals(expectedButtonText, viewEditWebElement.getText());
127 GeneralUIUtils.ultimateWait();
130 protected void addVNF(String name, String lcpRegion, String tenant, String suppressRollback,
131 String legacyRegion, String productFamily, ArrayList<String> permittedTenants) throws InterruptedException {
132 ViewEditPage viewEditPage = new ViewEditPage();
134 viewEditPage.selectNodeInstanceToAdd(name);
135 viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VNF_INSTANCE_NAME_PREFIX);
136 viewEditPage.selectProductFamily(productFamily);
137 viewEditPage.selectLCPRegion(lcpRegion);
139 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
140 viewEditPage.selectTenant(tenant);
142 Click.onFirstSelectOptionById(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
143 SelectOption.selectFirstTwoOptionsFromMultiselectById(Constants.OwningEntity.LOB_SELECT_TEST_ID);
145 viewEditPage.selectSuppressRollback(suppressRollback);
147 viewEditPage.setLegacyRegion(legacyRegion);
149 viewEditPage.clickConfirmButton();
150 assertSuccessfulVNFCreation();
151 viewEditPage.clickCloseButton();
152 GeneralUIUtils.ultimateWait();
155 protected void addVFModule(String name, String lcpRegion, String tenant, String suppressRollback,
156 String legacyRegion, ArrayList<String> permittedTenants) {
157 ViewEditPage viewEditPage = new ViewEditPage();
159 viewEditPage.selectVolumeGroupToAdd(name);
160 viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VF_MODULE_INSTANCE_NAME_PREFIX);
161 viewEditPage.selectLCPRegion(lcpRegion);
163 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
164 viewEditPage.selectTenant(tenant);
166 viewEditPage.selectSuppressRollback(suppressRollback);
168 viewEditPage.setLegacyRegion(legacyRegion);
170 viewEditPage.clickConfirmButton();
171 assertSuccessfulVFModuleCreation();
172 viewEditPage.clickCloseButton();
173 GeneralUIUtils.ultimateWait();
176 protected void addVolumeGroup(String name, String lcpRegion, String tenant, String suppressRollback,
177 String legacyRegion, ArrayList<String> permittedTenants) {
178 ViewEditPage viewEditPage = new ViewEditPage();
180 viewEditPage.selectVolumeGroupToAdd(name);
181 viewEditPage.generateAndSetInstanceName(Constants.ViewEdit.VOLUME_GROUP_INSTANCE_NAME_PREFIX);
182 viewEditPage.selectLCPRegion(lcpRegion);
184 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
185 viewEditPage.selectTenant(tenant);
187 viewEditPage.selectSuppressRollback(suppressRollback);
189 viewEditPage.setLegacyRegion(legacyRegion);
191 viewEditPage.clickConfirmButton();
192 assertSuccessfulVolumeGroupCreation();
193 viewEditPage.clickCloseButton();
194 GeneralUIUtils.ultimateWait();
197 void assertSuccessfulVNFCreation() {
198 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VNF_CREATED_SUCCESSFULLY_TEXT, 100);
199 Assert.assertTrue(Constants.ViewEdit.VNF_CREATION_FAILED_MESSAGE, byText);
202 void assertSuccessfulPNFAssociation() {
204 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.PnfAssociation.PNF_ASSOCIATED_SUCCESSFULLY_TEXT, 100);
205 Assert.assertTrue(Constants.PnfAssociation.PNF_ASSOCIATED_FAILED_MESSAGE, byText);
207 void assertSuccessfulVolumeGroupCreation() {
208 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VOLUME_GROUP_CREATED_SUCCESSFULLY_TEXT, 100);
209 Assert.assertTrue(Constants.ViewEdit.VOLUME_GROUP_CREATION_FAILED_MESSAGE, byText);
212 void assertSuccessfulVFModuleCreation() {
213 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VF_MODULE_CREATED_SUCCESSFULLY_TEXT, 100);
214 Assert.assertTrue(Constants.ViewEdit.VF_MODULE_CREATION_FAILED_MESSAGE, byText);
217 void goToExistingInstanceById(String instanceUUID) {
218 SearchExistingPage searchExistingPage = new SearchExistingPage();
219 SideMenu.navigateToSearchExistingPage();
220 searchExistingPage.searchForInstanceByUuid(instanceUUID);
221 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceUUID);
222 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
225 void goToExistingInstanceByName(String instanceName) {
226 SearchExistingPage searchExistingPage = new SearchExistingPage();
227 SideMenu.navigateToSearchExistingPage();
228 searchExistingPage.searchForInstanceByName(instanceName);
229 WebElement instanceIdRow = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
230 String instanceId = instanceIdRow.getText();
231 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceId);
232 searchExistingPage.clickEditViewByInstanceId(instanceId);