From 66af8b9b391879be78660d6ccb0a1f1f9340b423 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 11 Mar 2019 09:34:34 +0200 Subject: Merge automation from ECOMP's repository Reference commit in ECOMP: 8e92a8c6 Issue-ID: VID-378 Change-Id: Ia32f4813378ef95097f788246aa5b1172e20ca48 Signed-off-by: Ittay Stern --- .../ci/tests/utilities/AdditionalConditions.java | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/AdditionalConditions.java (limited to 'vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/AdditionalConditions.java') diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/AdditionalConditions.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/AdditionalConditions.java new file mode 100644 index 000000000..9a070e2b0 --- /dev/null +++ b/vid-automation/src/main/java/org/onap/sdc/ci/tests/utilities/AdditionalConditions.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.ci.tests.utilities; + +import com.paulhammant.ngwebdriver.NgWebDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import java.util.List; + +public class AdditionalConditions { + + public static ExpectedCondition searchForOneElement(List ByList){ + return new ExpectedCondition() { + @Override + public WebElement apply(WebDriver driver) { + for (By by : ByList){ + WebElement findElement = driver.findElement(by); + if (findElement != null){ + return findElement; + } + } + return null; + } + }; + } + + public static ExpectedCondition jQueryAJAXCallsHaveCompleted() { + return new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { + return (Boolean) ((JavascriptExecutor)driver). + executeScript("return (window.jQuery!= null) && (jQuery.active === 0);"); + } + }; + } + + public static ExpectedCondition angularHasFinishedProcessing() { + return new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { +// String scriptJS = "return (window.angular !==undefined) &&" +// + " (angular.element(document).injector() !==undefined) &&" +// + " (angular.element(document).injector().get('$http').pendingRequests.length === 0)"; +// return Boolean.valueOf(( (JavascriptExecutor) driver).executeScript(scriptJS).toString()); + new NgWebDriver((JavascriptExecutor) driver).waitForAngularRequestsToFinish(); + return true; + } + }; + } + + public static ExpectedCondition angular2HasFinishedProcessing() { + return driver -> { + new NgWebDriver((JavascriptExecutor) driver).waitForAngular2RequestsToFinish(); + return true; + }; + } + + public static ExpectedCondition pageLoadWait() { + return new ExpectedCondition() { + @Override + public Boolean apply(WebDriver driver) { + String scriptJS = + "try {\r\n" + + " if (document.readyState !== 'complete') {\r\n" + + " return false; // Page not loaded yet\r\n" + + " }\r\n" + + " if (window.jQuery) {\r\n" + + " if (window.jQuery.active) {\r\n" + + " return false;\r\n" + + " } else if (window.jQuery.ajax && window.jQuery.ajax.active) {\r\n" + + " return false;\r\n" + + " }\r\n" + + " }\r\n" + + " if (window.angular) {\r\n" + + " if (!window.qa) {\r\n" + + " // Used to track the render cycle finish after loading is complete\r\n" + + " window.qa = {\r\n" + + " doneRendering: false\r\n" + + " };\r\n" + + " }\r\n" + + " // Get the angular injector for this app (change element if necessary)\r\n" + + " var injector = window.angular.element(document).find('body').injector();\r\n" + + " // Store providers to use for these checks\r\n" + + " var $rootScope = injector.get('$rootScope');\r\n" + + " var $http = injector.get('$http');\r\n" + + " var $timeout = injector.get('$timeout');\r\n" + + " // Check if digest\r\n" + + " if ($rootScope.$$phase === '$apply' || $rootScope.$$phase === '$digest' || $http.pendingRequests.length !== 0) {\r\n" + + " window.qa.doneRendering = false;\r\n" + + " return false; // Angular digesting or loading data\r\n" + + " }\r\n" + + " if (!window.qa.doneRendering) {\r\n" + + " // Set timeout to mark angular rendering as finished\r\n" + + " $timeout(function() {\r\n" + + " window.qa.doneRendering = true;\r\n" + + " }, 0);\r\n" + + " return false;\r\n" + + " }\r\n" + + " }\r\n" + + " return true;\r\n" + + "} catch (ex) {\r\n" + + " return false;\r\n" + + "}"; + return Boolean.valueOf(( (JavascriptExecutor) driver).executeScript(scriptJS).toString()); + } + }; + } + + + +} -- cgit 1.2.3-korg