diff options
author | Ofir Sonsino <os0695@att.com> | 2018-01-31 17:19:00 +0200 |
---|---|---|
committer | Ofir Sonsino <os0695@att.com> | 2018-01-31 17:19:00 +0200 |
commit | 1cfb08779ea0e00be69e072a940b3063e049fe6b (patch) | |
tree | 6602a900387c8393ed0dcd81c0539381632903c6 /vid-automation/src/main/java/vid/automation/test/infra | |
parent | 2f20b001b9243e0f8b44aecc768ec265fd538732 (diff) |
org.onap migration
Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d
Issue-ID: VID-86
Signed-off-by: Ofir Sonsino <os0695@att.com>
Diffstat (limited to 'vid-automation/src/main/java/vid/automation/test/infra')
6 files changed, 367 insertions, 0 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Click.java b/vid-automation/src/main/java/vid/automation/test/infra/Click.java new file mode 100644 index 00000000..f2cbbef8 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/Click.java @@ -0,0 +1,54 @@ +package vid.automation.test.infra; + +import org.junit.Assert; +import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import java.util.List; + +public class Click { + public static void byText(String text) { + WebElement element = GeneralUIUtils.findByText(text); + Assert.assertTrue(element != null); + + element.click(); + } + + public static void byId(String id) { + WebElement element = Get.byId(id); + Assert.assertTrue(element != null); + + element.click(); + } + + public static void byTestId(String testId) { + WebElement element = Get.byTestId(testId); + Assert.assertTrue(element != null); + element.click(); + } + + public static void byClass(String className) { + List<WebElement> elements = Get.byClass(className); + Assert.assertTrue(elements != null && elements.size() > 0); + + elements.get(0).click(); + } + + public static void onFirstSelectOptionById(String id) { + Select selectlist = new Select(Get.byId(id)); + if(selectlist.getOptions().size() > 1) { + selectlist.selectByIndex(1); + } + } + + public static void onFirstSelectOptionByClass(String className) { + final List<WebElement> webElements = Get.byClass(className); + webElements.forEach(webElement -> { + Select selectlist = new Select(webElement); + if (selectlist.getOptions().size() > 1) { + selectlist.selectByIndex(1); + } + }); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Exists.java b/vid-automation/src/main/java/vid/automation/test/infra/Exists.java new file mode 100644 index 00000000..14339d63 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/Exists.java @@ -0,0 +1,34 @@ +package vid.automation.test.infra; + +import org.openqa.selenium.NoSuchElementException; +import vid.automation.test.Constants; + +public class Exists { + public static boolean byId(String id) { + return Get.byId(id) != null; + } + + public static boolean byTestId(String testId) { + return Get.byTestId(testId) != null; + } + + public static boolean byClass(String className) { + return Get.byClass(className) != null; + } + + public static boolean byClassAndText(String className, String text) { + return Get.byClassAndText(className, text) != null; + } + + public static boolean byCssSelectorAndText(String css, String text) { + return Get.byCssSelectorAndText(css, text) != null; + } + + public static boolean modal() { + try { + return Get.byCssSelector(Constants.Modals.modalClass) != null; + } catch (NoSuchElementException exception) { + return false; + } + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Get.java b/vid-automation/src/main/java/vid/automation/test/infra/Get.java new file mode 100644 index 00000000..f9ce529f --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/Get.java @@ -0,0 +1,95 @@ +package vid.automation.test.infra; + +import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.ArrayList; +import java.util.List; + +public class Get { + public static WebElement byId(String id) { + try { + return GeneralUIUtils.getDriver().findElement(By.id(id)); + } catch (Exception var2) { + return null; + } + } + + public static WebElement byTestId(String dataTestId) { + try { + return GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']")); + } catch (Exception var2) { + return null; + } + } + + + + public static WebElement byClassAndText(String className, String text) { + WebElement result = null; + List<WebElement> elements = GeneralUIUtils.getWebElementsListByContainsClassName(className); + + for(WebElement element : elements) { + if (element.getText().contains(text)) { + result = element; + break; + } + } + + return result; + } + + public static WebElement byCssSelectorAndText(String css, String text) { + WebElement element = GeneralUIUtils.getDriver().findElement(By.cssSelector(css)); + + if (element != null && element.getText().contains(text)) { + return element; + } + + return null; + } + + public static String selectedOptionText(String dataTestId) { + return GeneralUIUtils.getSelectedElementFromDropDown(dataTestId).getText(); + } + + public static List<WebElement> byClass(String className) { + return GeneralUIUtils.getWebElementsListByContainsClassName(className); + } + + public static WebElement byCssSelector(String css) { + return GeneralUIUtils.getDriver().findElement(By.cssSelector(css)); + } + + public static List<String> tableHeaderValuesByTestId(String tableId) { + return tableValuesById(tableId, "thead", "th").get(0); + } + + public static List<List<String>> tableBodyValuesByTestId(String tableId) { + return tableValuesById(tableId, "tbody", "td"); + } + + private static List<WebElement> rowsByTableId(String tableId,String section, String column) { + try { + return GeneralUIUtils.getElemenetsFromTable(By.xpath("//table[@data-tests-id=\"" + tableId + "\"]/" + section + "/tr")); + } catch (Exception var2) { + return null; + } + } + + private static List<List<String>> tableValuesById(String tableId, String section, String column) { + List<WebElement> rows = rowsByTableId(tableId, section, column); + if(rows != null) { + List<List<String>> tableContent = new ArrayList<List<String>>(); + for(WebElement row:rows) { + List<WebElement> columns = row.findElements(By.xpath(column)); + tableContent.add(GeneralUIUtils.getWebElementListText(columns)); + } + return tableContent; + } + else { + return null; + } + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Input.java b/vid-automation/src/main/java/vid/automation/test/infra/Input.java new file mode 100644 index 00000000..15fa2254 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/Input.java @@ -0,0 +1,38 @@ +package vid.automation.test.infra; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.SystemUtils; +import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; + +/** + * Created by itzikliderman on 11/09/2017. + */ +public class Input { + public static void text(String text, String inputTestsId) { + WebElement inputElement = GeneralUIUtils.getWebElementByTestID(inputTestsId, 30); + inputElement.sendKeys(text); + } + + public static String getValueByTestId(String testId) { + WebElement input = GeneralUIUtils.getInputElement(testId); + return input.getAttribute("value"); + } + + /* + Get relative path to resource and id of file input element, + and send the resource full path to the input element + */ + public static void file(String pathInResources, String inputId) { + + String path = Input.class.getResource("../../../../"+pathInResources).getPath().toString(); + if (SystemUtils.IS_OS_WINDOWS) { + path = FilenameUtils.separatorsToSystem(path); + if (path.charAt(0)=='\\') { + path = path.substring(1); + } + } + WebElement inputElement = Get.byId(inputId); + inputElement.sendKeys(path); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/infra/SelectOption.java b/vid-automation/src/main/java/vid/automation/test/infra/SelectOption.java new file mode 100644 index 00000000..048174e9 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/SelectOption.java @@ -0,0 +1,47 @@ +package vid.automation.test.infra; + +import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; +import vid.automation.test.Constants; + +import java.util.List; + +/** + * Created by itzikliderman on 18/07/2017. + */ +public class SelectOption { + public static Select byValue(String value, String dataTestsId) { + Select select = new Select(GeneralUIUtils.getWebElementByTestID(dataTestsId)); + if(value != null) { + select.selectByValue(value); + } + + return select; + } + + public static void byIdAndVisibleText(String id, String text) { + Select selectlist = new Select(Get.byId(id)); + selectlist.selectByVisibleText(text); + } + + public static void byClassAndVisibleText(String className, String text) { + final List<WebElement> webElements = Get.byClass(className); + webElements.forEach(webElement -> { + final String id = webElement.getAttribute("id"); + byIdAndVisibleText(id, text); + }); + } + + public static void byTestIdAndVisibleText(String displayName, String selectDataTestId) { + GeneralUIUtils.getSelectList(displayName, selectDataTestId); + } + + public static void selectFirstTwoOptionsFromMultiselectById(String multiSelectId) throws InterruptedException { + Click.byId(multiSelectId); + Thread.sleep(1000); + Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS); + Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS); + + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Wait.java b/vid-automation/src/main/java/vid/automation/test/infra/Wait.java new file mode 100644 index 00000000..fa6ce4f3 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/Wait.java @@ -0,0 +1,99 @@ +package vid.automation.test.infra; + +import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NoSuchElementException; +import vid.automation.test.Constants; + +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; + +public class Wait { + public static boolean byText(String text) { + return GeneralUIUtils.findAndWaitByText(text, Constants.generalTimeout); + } + + public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval, TimeUnit intervalUnit) { + for (int i=0; i<numOfRetries; i++) { + try { + if (predicate.test(input)) { + return true; + } + } + catch (Throwable t) { + System.out.println("a retry failed duo to:" +t.getMessage()); + } + try { + intervalUnit.sleep(interval); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return false; + } + + public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval) { + return waitFor(predicate, input, numOfRetries, interval, TimeUnit.SECONDS); + } + + public static boolean waitByClassAndText(String className, String text, int timeoutInSeconds) { + return waitFor((x->Get.byClassAndText(className,text)!=null),null, timeoutInSeconds, 1); + } + + public static boolean waitByTestId(String dataTestId, int timeoutInSeconds) { + return waitFor((x->Get.byTestId(dataTestId)!=null),null, timeoutInSeconds, 1); + } + + public static void angularHttpRequestsLoaded() { + JavascriptExecutor js = (JavascriptExecutor) GeneralUIUtils.getDriver(); + for (int i=0; i<Constants.generalRetries; i++) { + Object result = js.executeScript("return window.angular.element('body').injector().get('$http').pendingRequests.length;"); + if(result.toString().equals("0")) { + break; + } else { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + public static void modalToDisappear() { + for (int i=0; i<Constants.generalRetries; i++) { + try { + Object modalElement = Get.byCssSelector(Constants.Modals.modalClass); + if(modalElement == null) { + break; + } else { + Thread.sleep(1000); + } + } catch (NoSuchElementException e) { + break; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + public static void modalToBeDisplayed() { + for (int i=0; i<Constants.generalRetries; i++) { + try { + Object modalElement = Get.byCssSelector(Constants.Modals.modalClass); + if(modalElement == null) { + Thread.sleep(1000); + } else { + break; + } + } catch (Exception e) { + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + e.printStackTrace(); + } + } + } +} |