1 package vid.automation.test.infra;
3 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
4 import org.openqa.selenium.JavascriptExecutor;
5 import org.openqa.selenium.NoSuchElementException;
6 import vid.automation.test.Constants;
8 import java.util.concurrent.TimeUnit;
9 import java.util.function.Predicate;
12 public static boolean byText(String text) {
13 return GeneralUIUtils.findAndWaitByText(text, Constants.generalTimeout);
16 public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval, TimeUnit intervalUnit) {
17 for (int i=0; i<numOfRetries; i++) {
19 if (predicate.test(input)) {
24 System.out.println("a retry failed duo to:" +t.getMessage());
27 intervalUnit.sleep(interval);
28 } catch (InterruptedException e) {
35 public static <T> boolean waitFor(Predicate<T> predicate, T input, int numOfRetries, int interval) {
36 return waitFor(predicate, input, numOfRetries, interval, TimeUnit.SECONDS);
39 public static boolean waitByClassAndText(String className, String text, int timeoutInSeconds) {
40 return waitFor((x->Get.byClassAndText(className,text)!=null),null, timeoutInSeconds, 1);
43 public static boolean waitByTestId(String dataTestId, int timeoutInSeconds) {
44 return waitFor((x->Get.byTestId(dataTestId)!=null),null, timeoutInSeconds, 1);
47 public static void angularHttpRequestsLoaded() {
48 JavascriptExecutor js = (JavascriptExecutor) GeneralUIUtils.getDriver();
49 for (int i=0; i<Constants.generalRetries; i++) {
50 Object result = js.executeScript("return window.angular.element('body').injector().get('$http').pendingRequests.length;");
51 if(result.toString().equals("0")) {
56 } catch (InterruptedException e) {
63 public static void modalToDisappear() {
64 for (int i=0; i<Constants.generalRetries; i++) {
66 Object modalElement = Get.byCssSelector(Constants.Modals.modalClass);
67 if(modalElement == null) {
72 } catch (NoSuchElementException e) {
74 } catch (InterruptedException e) {
80 public static void modalToBeDisplayed() {
81 for (int i=0; i<Constants.generalRetries; i++) {
83 Object modalElement = Get.byCssSelector(Constants.Modals.modalClass);
84 if(modalElement == null) {
89 } catch (Exception e) {
92 } catch (InterruptedException e1) {