2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.ci.tests.utilities;
23 //import com.automation.common.report_portal_integration.annotations.Step;
25 import static org.hamcrest.Matchers.is;
27 import com.aventstack.extentreports.Status;
28 import java.awt.Robot;
29 import java.awt.event.KeyEvent;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Random;
35 import java.util.UUID;
36 import java.util.concurrent.TimeUnit;
37 import java.util.function.Supplier;
38 import org.apache.commons.io.FileUtils;
39 import org.junit.Assert;
40 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum;
41 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum.DashboardCardEnum;
42 import org.onap.sdc.ci.tests.execute.setup.DriverFactory;
43 import org.onap.sdc.ci.tests.execute.setup.SetupCDTest;
44 import org.openqa.selenium.By;
45 import org.openqa.selenium.JavascriptExecutor;
46 import org.openqa.selenium.Keys;
47 import org.openqa.selenium.NoSuchElementException;
48 import org.openqa.selenium.OutputType;
49 import org.openqa.selenium.TakesScreenshot;
50 import org.openqa.selenium.TimeoutException;
51 import org.openqa.selenium.WebDriver;
52 import org.openqa.selenium.WebElement;
53 import org.openqa.selenium.firefox.FirefoxDriver;
54 import org.openqa.selenium.interactions.Actions;
55 import org.openqa.selenium.support.ui.ExpectedCondition;
56 import org.openqa.selenium.support.ui.ExpectedConditions;
57 import org.openqa.selenium.support.ui.FluentWait;
58 import org.openqa.selenium.support.ui.Select;
59 import org.openqa.selenium.support.ui.WebDriverWait;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
64 public final class GeneralUIUtils {
66 public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
67 static final Logger logger = LoggerFactory.getLogger(GeneralUIUtils.class);
69 private static int timeOut=90;
71 // public static void setTimeOut(int time) {
80 /**************** DRIVER ****************/
82 public static WebDriver getDriver() {
84 return DriverFactory.getDriver();
91 /****************************************/
93 public static List<WebElement> getElemenetsFromTable(By by) {
94 return getDriver().findElements(by);
97 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
98 if (screenshotFilename == null) {
99 if (testName != null){
100 screenshotFilename = testName;
104 screenshotFilename = UUID.randomUUID().toString();
108 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
109 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
110 new File(dir).mkdirs();
111 FileUtils.copyFile(scrFile, filePath);
113 } catch (IOException e1) {
114 e1.printStackTrace();
119 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
120 return takeScreenshot(screenshotFilename, dir, null);
124 public static void scrollDown() {
126 Robot robot = new Robot();
127 robot.keyPress(KeyEvent.VK_DOWN);
128 robot.keyRelease(KeyEvent.VK_DOWN);
129 GeneralUIUtils.waitForLoader();
137 public static WebElement getWebElementByTestID(String dataTestId) {
138 return getWebElementByTestID(dataTestId, timeOut);
141 public static WebElement getWebElementByTestID(String dataTestId, int timeout) {
142 WebDriverWait wait = newWait(timeout);
143 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
146 public static WebElement getWebElementByTestID(String dataTestId, String text, int timeout) {
147 WebElement webElementByTestID = getWebElementByTestID(dataTestId, timeout);
149 newWait(timeout).until(ExpectedConditions.textToBePresentInElement(webElementByTestID, text));
150 return webElementByTestID;
153 public static boolean isWebElementExistByTestId(String dataTestId) {
154 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
160 public static WebElement getInputElement(String dataTestId) {
163 return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
170 public static List<WebElement> getInputElements(String dataTestId) {
172 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
176 public static WebElement getWebElementBy(By by) {
177 return getWebElementBy(by, timeOut);
180 public static WebElement getWebElementBy(By by, int timeoutInSeconds) {
181 WebDriverWait wait = newWait(timeoutInSeconds);
182 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
185 public static List<String> getWebElementListText(List<WebElement>elements) {
186 List<String>Text=new ArrayList<>();
187 for (WebElement webElement : elements) {
188 Text.add(webElement.getText());
194 public static List<WebElement> getWebElementsListBy(By by) {
195 return getWebElementsListBy(by, timeOut);
198 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
199 WebDriverWait wait = newWait(timeOut);
200 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
203 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
205 WebDriverWait wait = newWait(10);
206 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
209 return new ArrayList<WebElement>();
213 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
214 return getWebElementsListByContainsClassName(containedText, timeOut);
217 public static List<WebElement> getWebElementsListByContainsClassName(String containedText, int timeoutInSeconds) {
218 WebDriverWait wait = newWait(timeoutInSeconds);
219 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '"+containedText+"')]")));
222 public static WebElement getWebElementByContainsClassName(String containedText) {
223 return getWebElementByContainsClassName(containedText, timeOut);
226 public static WebElement getWebElementByContainsClassName(String containedText, int timeoutInSeconds) {
227 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"), timeoutInSeconds);
230 public static WebElement getWebElementByClassName(String className) {
231 return getWebElementByClassName(className, timeOut);
234 public static WebElement getWebElementByClassName(String className, int timeoutInSeconds) {
235 WebDriverWait wait = newWait(timeoutInSeconds);
236 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
239 public static List<WebElement> getWebElementsListByContainsClassNameAndText(String cssName, String text, int timeoutInSeconds) {
240 WebDriverWait wait = newWait(timeoutInSeconds);
241 String xpath = String.format("//*[contains(@class, '%s') and contains(text(),'%s')]", cssName, text);
242 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(
246 public static WebElement getWebElementByLinkText(String linkText) {
247 WebDriverWait wait = newWait(timeOut);
248 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
252 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
253 WebDriverWait wait = newWait(timeOut);
254 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
257 public static List<WebElement> getWebElementsListByClassName(String className) {
258 WebDriverWait wait = newWait(timeOut);
259 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
265 public static Boolean isElementInvisibleByTestId(String dataTestId) {
266 WebDriverWait wait = newWait(timeOut);
268 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
271 public static Boolean isElementVisibleByTestId(String dataTestId) {
273 WebDriverWait wait = newWait(timeOut);
274 if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
285 public static void clickOnElementByTestId(String dataTestId) {
286 clickOnElementByTestIdWithoutWait(dataTestId);
290 public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
291 WebDriverWait wait = newWait(timeOut);
292 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
295 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
296 WebDriverWait wait = newWait(customTimeout);
297 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
300 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
301 WebDriverWait wait = newWait(timeOut);
302 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
305 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
306 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
309 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
310 WebDriverWait wait = newWait(timeOut);
311 boolean displayed = getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).isEmpty();
313 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
320 public static Boolean waitForElementInVisibilityByTestId(By by) {
321 return waitForElementInVisibilityBy(by, timeOut);
325 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
326 WebDriverWait wait = newWait(timeOut);
327 boolean displayed = getDriver().findElements(by).isEmpty();
329 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
337 public static void setWebElementByTestId(String elementID, String value) {
338 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elementID);
339 resourceDescriptionTextbox.clear();
340 resourceDescriptionTextbox.sendKeys(value);
344 public static WebElement hoverOnAreaByTestId(String areaId) {
345 Actions actions = new Actions(getDriver());
346 WebElement area = getWebElementByTestID(areaId);
347 actions.moveToElement(area).perform();
352 public static WebElement hoverOnAreaByClassName(String className) {
353 Actions actions = new Actions(getDriver());
354 WebElement area = getWebElementByClassName(className);
355 actions.moveToElement(area).perform();
356 GeneralUIUtils.ultimateWait();
360 public static void clickElementUsingActions(WebElement element){
361 Actions actions = new Actions(getDriver());
363 actions.moveToElement(element);
372 public static void waitForLoader() {
373 waitForLoader(timeOut);
376 public static void waitForLoader(int timeOut) {
377 newWait(timeOut).until(ExpectedConditions.invisibilityOfElementLocated(By.className("custom-loader-background")));
380 public static void findComponentAndClick(String resourceName) throws Exception {
381 SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in homepage");
382 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
384 searchTextbox.clear();
385 searchTextbox.sendKeys(resourceName);
389 SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
395 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component from home screen", resourceName));
396 clickOnElementByTestId(resourceName);
397 GeneralUIUtils.ultimateWait();
398 getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
401 SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
407 public static String getComponentVersion(String componentName) {
408 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
411 public static void windowZoomOut() {
412 final int zoomOutFactor = 3;
413 for (int i = 0; i < zoomOutFactor; i++) {
414 if(getDriver() instanceof FirefoxDriver) {
415 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
420 public static void resetZoom(){
421 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
424 public static void windowZoomOutUltimate(){
427 // JavascriptExecutor js = (JavascriptExecutor) driver;
428 // js.executeScript("document.body.style.zoom='90%'");
431 public static void clickASDCLogo() {
432 WebDriverWait wait = newWait(15);
433 wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("ASDC")));
434 WebElement ClickASDCLogo = getDriver().findElement(By.linkText("ASDC"));
435 ClickASDCLogo.click();
436 GeneralUIUtils.waitForLoader();
439 public static void sleep(int millis) {
441 Thread.sleep(millis);
442 } catch (InterruptedException e) {
443 throw new RuntimeException(e);
447 public static void moveToStep(DataTestIdEnum.StepsEnum Stepname) {
448 moveToStep(Stepname.getValue());
449 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to %s page ", Stepname.toString()));
452 public static void moveToStep(String dataTestId) {
453 clickOnElementByTestId(dataTestId);
458 public static Select getSelectList(String item, String datatestsid) {
459 Select selectlist = new Select(getWebElementByTestID(datatestsid));
461 selectlist.selectByVisibleText(item);
462 Assert.assertThat(selectlist.getFirstSelectedOption().getText(), is(item));
467 public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
468 GeneralUIUtils.waitForLoader();
469 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
472 public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
473 GeneralUIUtils.waitForLoader();
474 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
478 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString){
479 WebDriverWait wait = newWait(timeOut);
480 GeneralUIUtils.waitForLoader();
481 return parentElement.findElement(By.cssSelector(cssString));
484 public static WebElement getElementfromElementByXPATH(WebElement parentElement, DashboardCardEnum dataTestId){
485 WebDriverWait wait = newWait(timeOut);
486 GeneralUIUtils.waitForLoader();
487 return HighlightMyElement( parentElement.findElement(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']")));
490 public static WebElement HighlightMyElement(WebElement element) {
491 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
492 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 4px solid yellow;");
496 public static boolean isOptionSelectedInMultiSelect(String dataTestId, String option) {
497 GeneralUIUtils.ultimateWait();
498 List<WebElement> selectedElements = getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']//span[@class='c-label']"));
501 for (WebElement selectedElement : selectedElements) {
502 if (selectedElement.getText().equals(option)) {
508 public static WebElement getSelectedElementFromDropDown(String dataTestId){
509 GeneralUIUtils.ultimateWait();;
510 WebElement selectedElement = new Select (getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).getFirstSelectedOption();
511 return selectedElement;
515 public static void waitForPageLoadByReadyState() {
516 newWait(30).until((ExpectedCondition<Boolean>) wd ->
517 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
521 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
522 int maxWaitingPeriodMS = 10 * 1000;
523 int napPeriodMS = 100;
524 int sumOfWaiting = 0;
525 List<WebElement> elements = null;
526 boolean isKeepWaiting = false;
527 while (!isKeepWaiting) {
528 elements = func.get();
529 isKeepWaiting = (expectedElementsCount == elements.size());
530 sleep(isKeepWaiting ? napPeriodMS : 0);
531 sumOfWaiting += napPeriodMS;
532 if (sumOfWaiting > maxWaitingPeriodMS)
538 public static String getActionDuration(Runnable func) throws Exception{
539 long startTime = System.nanoTime();
541 long estimateTime = System.nanoTime();
542 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
543 String durationString = String.format("%02d:%02d", duration / 60, duration % 60);
544 return durationString;
547 public static WebElement clickOnAreaJS(String areaId) {
548 return clickOnAreaJS(areaId, timeOut);
552 public static WebElement clickOnAreaJS(String areaId, int timeout) {
555 WebElement area = getWebElementByTestID(areaId);
556 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
557 //HighlightMyElement(area);
558 Object executeScript = javascript.executeScript("arguments[0].click();", area, "color: yellow; border: 4px solid yellow;");
559 waitForLoader(timeout);
570 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
571 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
572 //HighlightMyElement(area);
573 javascript.executeScript("arguments[0].click();", areaId, "color: yellow; border: 4px solid yellow;");
579 public static void clickSomewhereOnPage() {
580 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
583 public static void findComponentAndClickInCatalog(String resourceName) throws Exception {
584 // This method will find element by element name, don't use data-tests-id argument
585 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
586 searchTextbox.clear();
587 searchTextbox.sendKeys(resourceName);
589 clickOnElementByText(resourceName);
593 public static void clickOnElementByText(String textInElement) {
594 logger.info("clickOnElementByText: {}", textInElement);
595 WebDriverWait wait = newWait(timeOut);
596 HighlightMyElement(wait.until(
597 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
600 public static void clickOnElementByText(String textInElement, int customTimeout) {
601 logger.info("clickOnElementByText: {}", textInElement);
602 WebDriverWait wait = newWait(customTimeout);
603 HighlightMyElement(wait.until(ExpectedConditions.elementToBeClickable(searchByTextContaining(textInElement)))).click();
606 private static WebDriverWait newWait(int timeoutInSeconds) {
607 final WebDriver driver = getDriver();
608 driver.manage().timeouts().setScriptTimeout(timeoutInSeconds, TimeUnit.SECONDS);
609 return new WebDriverWait(driver, timeoutInSeconds, 120);
612 public static void clickJSOnElementByText(String textInElement) throws Exception {
613 WebDriverWait wait = newWait(timeOut);
614 clickOnAreaJS(wait.until(
615 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
618 public static void fluentWaitTestID(String dataTestId, String text) {
619 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(getDriver())
620 .withTimeout(30, TimeUnit.SECONDS)
621 .pollingEvery(50, TimeUnit.MILLISECONDS)
622 .ignoring(NoSuchElementException.class);
624 fluentWait.until(ExpectedConditions.refreshed(
625 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
628 public static void regularWait(WebElement element, String text){
629 WebDriverWait wait = newWait(timeOut);
631 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
635 public static void waitForAngular(){
636 WebDriverWait wait = newWait(90);
637 wait.until(AdditionalConditions.pageLoadWait());
638 wait.until(AdditionalConditions.angularHasFinishedProcessing());
642 public static void waitForAngular2(){
643 WebDriverWait wait = newWait(90);
644 wait.until(AdditionalConditions.pageLoadWait());
647 WebDriverWait briefWait = newWait(3);
648 briefWait.until(AdditionalConditions.angular2HasFinishedProcessing());
649 } catch (TimeoutException | org.openqa.selenium.ScriptTimeoutException e) {
650 logger.info("Ignoring TimeoutException while waiting for angular2: {}", e, e);
655 public static Object getAllElementAttributes(WebElement element) {
656 return ((JavascriptExecutor)getDriver()).executeScript("var s = []; var attrs = arguments[0].attributes; for (var l = 0; l < attrs.length; ++l) { var a = attrs[l]; s.push(a.name + ':' + a.value); } ; return s;", element);
659 public static boolean isElementReadOnly(WebElement element){
661 HighlightMyElement(element).clear();
663 } catch (Exception e) {
668 public static boolean isElementReadOnly(String dataTestId){
669 return isElementReadOnly(
670 waitForElementVisibilityByTestId(dataTestId));
673 public static boolean isElementDisabled(WebElement element){
674 return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
675 element.getAttribute("class").contains("disabled");
678 public static boolean isElementDisabled(String dataTestId){
679 return isElementDisabled(
680 waitForElementVisibilityByTestId(dataTestId));
684 public static void ultimateWait(){
685 logger.info("ultimateWait: starting");
686 long startTime = System.nanoTime();
688 GeneralUIUtils.waitForAngular();
689 logger.info("ultimateWait: waited for angular: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
691 GeneralUIUtils.waitForAngular2();
692 logger.info("ultimateWait: waited for angular2: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
694 long estimateTime = System.nanoTime();
695 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
696 if(duration > timeOut){
697 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
700 logger.info("ultimateWait: done");
703 public static WebElement makeElementVisibleWithJS(WebElement element){
704 String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
705 ((JavascriptExecutor) getDriver()).executeScript(js, element);
709 public static WebElement unhideElement(WebElement element, String attributeValue){
710 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
711 ((JavascriptExecutor) getDriver()).executeScript(js, element);
715 public static WebElement findByText(String textInElement){
716 return getDriver().findElement(searchByTextContaining(textInElement));
719 public static List<WebElement> findElementsByText(String textInElement){
720 return getDriver().findElements(searchByTextContaining(textInElement));
723 public static By searchByTextContaining(String textInElement) {
724 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
728 public static boolean findAndWaitByText(String textInElement, int timeout){
729 logger.info("findAndWaitByText: {}", textInElement);
731 WebDriverWait wait = newWait(timeout);
732 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
740 public static WebElement getClickableButtonBy(By by, int timout){
742 WebDriverWait wait = newWait(timout);
743 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
753 public static WebElement getButtonWithText(String textInButton){
755 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
764 public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
766 return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
769 public static void closeErrorMessage() {
770 WebElement okWebElement = getButtonWithText("OK");
771 if (okWebElement != null){
772 okWebElement.click();
777 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
779 return getDriver().findElement(By.cssSelector(cssString));
782 public static String getDataTestIdAttributeValue(WebElement element) {
783 return element.getAttribute("data-tests-id");
786 public static String getTextContentAttributeValue(WebElement element) {
787 return element.getAttribute("textContent");
790 public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
792 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
799 public static void clickOnElementByCSS(String cssString) throws Exception {
800 WebDriverWait wait = newWait(timeOut);
801 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
804 public static String getRandomComponentName(String prefix) {
805 return prefix + GeneralUIUtils.randomNumber();
807 public static int randomNumber() {
808 Random r = new Random();
809 return r.nextInt(10000);
812 public static void waitForUINotification() {
813 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
814 if (!notificationElements.isEmpty()){
815 notificationElements.forEach(WebElement::click);
819 public static boolean checkForDisabledAttribute(String dataTestId){
820 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
821 return elementAttributes.toString().contains("disabled");
824 public static void dragAndDropElementByY(WebElement area, int yOffset) {
825 Actions actions = new Actions(getDriver());
826 actions.dragAndDropBy(area, 10, yOffset).perform();
830 public static void acceptDeadObjectException(Runnable todo) {
833 } catch (org.openqa.selenium.WebDriverException e) {
834 if (!e.getMessage().startsWith("TypeError: can't access dead object")) {