1 package vid.automation.test.sections;
3 import com.aventstack.extentreports.Status;
4 import org.junit.Assert;
5 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
6 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
7 import org.openqa.selenium.By;
8 import org.openqa.selenium.WebDriver;
9 import org.openqa.selenium.WebElement;
10 import org.openqa.selenium.support.ui.ExpectedConditions;
11 import org.openqa.selenium.support.ui.WebDriverWait;
12 import vid.automation.test.Constants;
13 import vid.automation.test.infra.*;
15 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.text.SimpleDateFormat;
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.List;
22 import java.util.function.Function;
24 import static org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.getDriver;
26 public class VidBasePage {
28 public VidBasePage setInstanceName(String name) {
29 setInputText(Constants.INSTANCE_NAME_SELECT_TESTS_ID, name);
34 public VidBasePage setLegacyRegion(String name) {
35 setInputText(Constants.ViewEdit.LEGACY_REGION_INPUT_TESTS_ID, name);
39 public String generateAndSetInstanceName(String prefix) {
40 String instanceName = generateInstanceName(prefix);
41 setInstanceName(instanceName);
45 public VidBasePage setInputText(String inputTestsId, String text) {
46 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
47 instanceNameInput.sendKeys(text);
51 public String getInputValue(String inputTestsId) {
52 WebElement instanceNameInput = GeneralUIUtils.getInputElement(inputTestsId);
53 String value =instanceNameInput.getAttribute("value");
57 public String generateInstanceName(String prefix) {
58 SimpleDateFormat sdf = new SimpleDateFormat(Constants.BrowseASDC.DATE_FORMAT);
59 Date now = Calendar.getInstance().getTime();
60 return prefix + sdf.format(now);
63 public VidBasePage selectServiceTypeByName(String serviceType) {
64 SelectOption.byTestIdAndVisibleText(serviceType, Constants.SERVICE_TYPE_SELECT_TESTS_ID);
67 public VidBasePage selectFromDropdownByTestId(String itemTestId, String dropdownButtonTestId) {
68 GeneralUIUtils.clickOnElementByTestId(dropdownButtonTestId, 60);
69 Assert.assertTrue(String.format(Constants.ViewEdit.OPTION_IN_DROPDOWN_NOT_EXISTS,itemTestId, dropdownButtonTestId),GeneralUIUtils.getWebElementByTestID(itemTestId) != null );
70 GeneralUIUtils.clickOnElementByTestId(itemTestId, 60);
73 public VidBasePage noOptionDropdownByTestId( String dropdownButtonTestId) {
74 List<WebElement> selectList= SelectOption.getList(dropdownButtonTestId);
75 Assert.assertTrue("The Select Input "+ dropdownButtonTestId+" should be empty",selectList.size()==1);
79 public static void selectSubscriberById(String subscriberId) {
80 SelectOption.byValue(subscriberId, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
83 public VidBasePage selectSubscriberByName(String subscriberName) {
84 SelectOption.byTestIdAndVisibleText(subscriberName, Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
88 public VidBasePage selectProductFamily(String productFamily) {
89 SelectOption.byValue(productFamily, Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
93 public VidBasePage selectSuppressRollback(String shouldSuppress) {
94 SelectOption.byTestIdAndVisibleText(shouldSuppress, Constants.SUPPRESS_ROLLBACK_SELECT_TESTS_ID);
98 public VidBasePage clickDeployServiceButtonByServiceUUID(String serviceUUID) {
99 Input.replaceText(serviceUUID, Constants.BROWSE_SEARCH);
100 String elementTestId = Constants.DEPLOY_BUTTON_TESTS_ID_PREFIX + serviceUUID;
101 GeneralUIUtils.clickOnElementByTestId(elementTestId, 30);
102 GeneralUIUtils.ultimateWait();
104 screenshotDeployDialog(serviceUUID);
109 public void screenshotDeployDialog(String serviceUUID) {
111 GeneralUIUtils.ultimateWait();
112 GeneralUIUtils.ultimateWait(); // better screenshot
113 String screenshotName = "deployService-" + serviceUUID;
114 ExtentTestActions.addScreenshot(Status.INFO, screenshotName, screenshotName);
115 } catch (IOException e) {
116 throw new RuntimeException(e);
121 public VidBasePage clickEditViewByInstanceId(String instanceId) {
122 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
123 GeneralUIUtils.clickOnElementByTestId(elementTestId, 100);
128 public Boolean checkEditOrViewExistsByInstanceId(String instanceId) {
129 String elementTestId = Constants.VIEW_EDIT_TEST_ID_PREFIX + instanceId;
130 return Exists.byTestId(elementTestId);
135 public VidBasePage clickSubmitButton() {
136 GeneralUIUtils.clickOnElementByText(Constants.SUBMIT_BUTTON_TEXT, 30);
140 public VidBasePage clickCancelButton() {
141 Click.byId(Constants.generalCancelButtonId);
145 public VidBasePage clickCancelButtonByTestID() {
146 GeneralUIUtils.clickOnElementByTestId(Constants.CANCEL_BUTTON_TEST_ID, 30);
151 public VidBasePage clickConfirmButton() {
152 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_BUTTON_TESTS_ID, 30);
156 public VidBasePage clickConfirmButtonInResumeDelete() {
157 GeneralUIUtils.clickOnElementByTestId(Constants.CONFIRM_RESUME_DELETE_TESTS_ID);
161 public VidBasePage clickCommitCloseButton() {
162 GeneralUIUtils.clickOnElementByTestId(Constants.COMMIT_CLOSE_BUTTON_ID, 30);
166 public VidBasePage clickCloseButton() {
167 return clickCloseButton(30);
170 public VidBasePage clickCloseButton(int customTimeout) {
171 GeneralUIUtils.clickOnElementByText(Constants.CLOSE_BUTTON_TEXT, customTimeout);
176 public VidBasePage selectLcpRegion(String lcpRegion) {
177 SelectOption.byValue(lcpRegion, Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID);
181 public VidBasePage selectTenant(String tenant) {
182 SelectOption.byValue(tenant, Constants.ViewEdit.TENANT_SELECT_TESTS_ID);
186 public VidBasePage selectAicZone(String aicZone) {
187 SelectOption.byValue(aicZone, Constants.ViewEdit.AIC_ZONE_TEST_ID);
191 public VidBasePage selectRollbackOption(boolean rollback) {
192 SelectOption.byValue(String.valueOf(rollback) , Constants.ViewEdit.ROLLBACK_TEST_ID);
196 public VidBasePage selectPlatform(String platform) {
197 SelectOption.byValue(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
201 public VidBasePage selectLineOfBusiness(String lob) {
202 SelectOption.byValue(lob, Constants.OwningEntity.LOB_SELECT_TEST_ID);
206 public void assertButtonState(String dataTestId, boolean shouldBeEnabled) {
207 assertButtonStateInternal(dataTestId, shouldBeEnabled,
208 (dataTestIdInner) -> GeneralUIUtils.getWebElementByTestID(dataTestIdInner, 60));
211 public void assertButtonStateEvenIfButtonNotVisible(String dataTestId, boolean shouldBeEnabled) {
212 // getInputElement is quite similar to getWebElementByTestID, but doesn't use
213 // the visibility predicate, so button is reachable bhind the grayed-out panel
214 assertButtonStateInternal(dataTestId, shouldBeEnabled,
215 (dataTestIdInner) -> GeneralUIUtils.getInputElement(dataTestIdInner));
218 protected void assertButtonStateInternal(String dataTestId, boolean shouldBeEnabled, Function<String,WebElement> strategy) {
219 GeneralUIUtils.ultimateWait();
220 boolean enabledElement= strategy.apply(dataTestId).getAttribute("disabled") == null;
221 if(shouldBeEnabled) {
222 Assert.assertTrue(String.format(Constants.ViewEdit.DISABLE_ERROR_MESSAGE,dataTestId), enabledElement);
224 Assert.assertFalse(String.format(Constants.ViewEdit.ENABLE_ERROR_MESSAGE,dataTestId),enabledElement);
228 public VidBasePage assertMsoRequestModal(String statusMsg) {
229 boolean waitForTextResult = Wait.waitByClassAndText("status", statusMsg, 20);
230 Assert.assertTrue(statusMsg + " message didn't appear on time", waitForTextResult);
235 public VidBasePage refreshPage() {
236 getDriver().navigate().refresh();
240 public String navigateTo(String path) {
241 String envUrl = System.getProperty("ENV_URL");
244 uri = new URI(envUrl);
245 } catch (URISyntaxException e) {
246 throw new RuntimeException(e);
248 String target = uri.resolve(path).toString();
250 getDriver().navigate().to(target);
251 GeneralUIUtils.ultimateWait();
256 public String getTextByTestID(String testId){
257 WebElement webElement= GeneralUIUtils.getWebElementByTestID(testId);
258 return webElement.getText();
261 public void checkAndCloseAlert(String expectedText) {
262 String alertText= Get.alertText();
263 Assert.assertEquals(expectedText, alertText);
266 public void goToIframe() {
267 final long start = System.currentTimeMillis();
269 GeneralUIUtils.ultimateWait();
270 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start));
271 final WebDriver iframeReady = new WebDriverWait(getDriver(), 10).until(
272 ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe"))
274 Assert.assertNotNull("failed going into iframe", iframeReady);
276 final long start2 = System.currentTimeMillis();
277 GeneralUIUtils.ultimateWait();
278 System.out.println("ultimateWait waited " + (System.currentTimeMillis() - start2));
281 public void goOutFromIframe(){
282 getDriver().switchTo().defaultContent();
289 public static WebDriverWait waitUntilDriverIsReady(int time) {
290 return new WebDriverWait(getDriver(), (long)time);