1 package vid.automation.test.infra;
3 import org.apache.commons.collections.CollectionUtils;
4 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.JavascriptExecutor;
6 import org.openqa.selenium.NoSuchElementException;
7 import vid.automation.test.Constants;
9 import java.util.concurrent.TimeUnit;
10 import java.util.function.Predicate;
13 public static boolean byText(String text) {
14 return GeneralUIUtils.findAndWaitByText(text, Constants.generalTimeout);
17 public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval, TimeUnit intervalUnit) {
18 for (int i=0; i<numOfRetries; i++) {
20 if (predicate.test(input)) {
25 System.out.println(String.format("a retry failed due to: %s %s", t, t.getMessage()));
28 intervalUnit.sleep(interval);
29 } catch (InterruptedException e) {
36 public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval) {
37 return waitFor(predicate, input, numOfRetries, interval, TimeUnit.SECONDS);
40 public static boolean waitByClassAndText(String className, String text, int timeoutInSeconds) {
41 return waitFor((x->Get.byClassAndText(className, text, 1)!=null), null, timeoutInSeconds, 1);
44 public static boolean waitByClassAndTextXpathOnly(String className, String text, int timeoutInSeconds) {
46 return CollectionUtils.isNotEmpty(
47 GeneralUIUtils.getWebElementsListByContainsClassNameAndText(className, text, timeoutInSeconds));
49 catch (RuntimeException exception) {
51 String.format("Failed to waitByClassAndText, after %d seconds. Class name: %s, Text: %s. Cause: %s",
52 timeoutInSeconds, className, text, exception.toString()));
57 public static boolean waitByTestId(String dataTestId, int timeoutInSeconds) {
58 return waitFor((x->Get.byTestId(dataTestId)!=null),null, timeoutInSeconds, 1);
61 public static boolean waitByIdAndText(String id, String text, int timeoutInSeconds) {
62 return waitFor((x->Get.byId(id).getText().equals(text)),null, timeoutInSeconds, 1);
65 public static void angularHttpRequestsLoaded() {
66 JavascriptExecutor js = (JavascriptExecutor) GeneralUIUtils.getDriver();
67 for (int i=0; i<Constants.generalRetries; i++) {
68 Object result = js.executeScript("return window.angular.element('body').injector().get('$http').pendingRequests.length;");
69 if(result.toString().equals("0")) {
74 } catch (InterruptedException e) {
81 public static void modalToDisappear() {
82 for (int i=0; i<Constants.generalRetries; i++) {
84 Object modalElement = Get.byCssSelector(Constants.Modals.modalClass);
85 if(modalElement == null) {
90 } catch (NoSuchElementException e) {
92 } catch (InterruptedException e) {
98 public static void modalToBeDisplayed() {
99 for (int i=0; i<Constants.generalRetries; i++) {
101 Object modalElement = Get.byCssSelector(Constants.Modals.modalClass);
102 if(modalElement == null) {
107 } catch (Exception e) {
110 } catch (InterruptedException e1) {
111 e1.printStackTrace();