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;
24 import com.aventstack.extentreports.Status;
25 import org.apache.commons.io.FileUtils;
26 import org.junit.Assert;
27 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum;
28 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum.DashboardCardEnum;
29 import org.onap.sdc.ci.tests.execute.setup.DriverFactory;
30 import org.onap.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openqa.selenium.*;
32 import org.openqa.selenium.firefox.FirefoxDriver;
33 import org.openqa.selenium.interactions.Actions;
34 import org.openqa.selenium.support.ui.*;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 import java.awt.event.KeyEvent;
41 import java.io.IOException;
42 import java.util.ArrayList;
43 import java.util.List;
44 import java.util.Random;
45 import java.util.UUID;
46 import java.util.concurrent.TimeUnit;
47 import java.util.function.Supplier;
49 import static org.hamcrest.Matchers.is;
52 public final class GeneralUIUtils {
54 public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
55 static final Logger logger = LoggerFactory.getLogger(GeneralUIUtils.class);
57 private static int timeOut=90;
59 // public static void setTimeOut(int time) {
68 /**************** DRIVER ****************/
70 public static WebDriver getDriver() {
72 return DriverFactory.getDriver();
79 /****************************************/
81 public static List<WebElement> getElemenetsFromTable(By by) {
82 return getDriver().findElements(by);
85 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
86 if (screenshotFilename == null) {
87 if (testName != null){
88 screenshotFilename = testName;
92 screenshotFilename = UUID.randomUUID().toString();
96 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
97 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
98 new File(dir).mkdirs();
99 FileUtils.copyFile(scrFile, filePath);
101 } catch (IOException e1) {
102 e1.printStackTrace();
107 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
108 return takeScreenshot(screenshotFilename, dir, null);
112 public static void scrollDown() {
114 Robot robot = new Robot();
115 robot.keyPress(KeyEvent.VK_DOWN);
116 robot.keyRelease(KeyEvent.VK_DOWN);
117 GeneralUIUtils.waitForLoader();
125 public static WebElement getWebElementByTestID(String dataTestId) {
126 return getWebElementByTestID(dataTestId, timeOut);
129 public static WebElement getWebElementByTestID(String dataTestId, int timeout) {
130 WebDriverWait wait = newWait(timeout);
131 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
134 public static boolean isWebElementExistByTestId(String dataTestId) {
135 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
141 public static WebElement getInputElement(String dataTestId) {
144 return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
151 public static List<WebElement> getInputElements(String dataTestId) {
153 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
157 public static WebElement getWebElementBy(By by) {
158 return getWebElementBy(by, timeOut);
161 public static WebElement getWebElementBy(By by, int timeoutInSeconds) {
162 WebDriverWait wait = newWait(timeoutInSeconds);
163 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
166 public static List<String> getWebElementListText(List<WebElement>elements) {
167 List<String>Text=new ArrayList<>();
168 for (WebElement webElement : elements) {
169 Text.add(webElement.getText());
175 public static List<WebElement> getWebElementsListBy(By by) {
176 return getWebElementsListBy(by, timeOut);
179 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
180 WebDriverWait wait = newWait(timeOut);
181 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
184 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
186 WebDriverWait wait = newWait(10);
187 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
190 return new ArrayList<WebElement>();
194 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
195 return getWebElementsListByContainsClassName(containedText, timeOut);
198 public static List<WebElement> getWebElementsListByContainsClassName(String containedText, int timeoutInSeconds) {
199 WebDriverWait wait = newWait(timeoutInSeconds);
200 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '"+containedText+"')]")));
203 public static WebElement getWebElementByContainsClassName(String containedText) {
204 return getWebElementByContainsClassName(containedText, timeOut);
207 public static WebElement getWebElementByContainsClassName(String containedText, int timeoutInSeconds) {
208 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"), timeoutInSeconds);
211 public static WebElement getWebElementByClassName(String className) {
212 return getWebElementByClassName(className, timeOut);
215 public static WebElement getWebElementByClassName(String className, int timeoutInSeconds) {
216 WebDriverWait wait = newWait(timeoutInSeconds);
217 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
220 public static List<WebElement> getWebElementsListByContainsClassNameAndText(String cssName, String text, int timeoutInSeconds) {
221 WebDriverWait wait = newWait(timeoutInSeconds);
222 String xpath = String.format("//*[contains(@class, '%s') and contains(text(),'%s')]", cssName, text);
223 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(
227 public static WebElement getWebElementByLinkText(String linkText) {
228 WebDriverWait wait = newWait(timeOut);
229 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
233 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
234 WebDriverWait wait = newWait(timeOut);
235 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
238 public static List<WebElement> getWebElementsListByClassName(String className) {
239 WebDriverWait wait = newWait(timeOut);
240 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
246 public static Boolean isElementInvisibleByTestId(String dataTestId) {
247 WebDriverWait wait = newWait(timeOut);
249 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
252 public static Boolean isElementVisibleByTestId(String dataTestId) {
254 WebDriverWait wait = newWait(timeOut);
255 if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
266 public static void clickOnElementByTestId(String dataTestId) {
267 clickOnElementByTestIdWithoutWait(dataTestId);
271 public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
272 WebDriverWait wait = newWait(timeOut);
273 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
276 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
277 WebDriverWait wait = newWait(customTimeout);
278 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
281 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
282 WebDriverWait wait = newWait(timeOut);
283 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
286 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
287 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
290 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
291 WebDriverWait wait = newWait(timeOut);
292 boolean displayed = getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).isEmpty();
294 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
301 public static Boolean waitForElementInVisibilityByTestId(By by) {
302 return waitForElementInVisibilityBy(by, timeOut);
306 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
307 WebDriverWait wait = newWait(timeOut);
308 boolean displayed = getDriver().findElements(by).isEmpty();
310 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
318 public static void setWebElementByTestId(String elementID, String value) {
319 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elementID);
320 resourceDescriptionTextbox.clear();
321 resourceDescriptionTextbox.sendKeys(value);
325 public static WebElement hoverOnAreaByTestId(String areaId) {
326 Actions actions = new Actions(getDriver());
327 WebElement area = getWebElementByTestID(areaId);
328 actions.moveToElement(area).perform();
333 public static WebElement hoverOnAreaByClassName(String className) {
334 Actions actions = new Actions(getDriver());
335 WebElement area = getWebElementByClassName(className);
336 actions.moveToElement(area).perform();
337 GeneralUIUtils.ultimateWait();
341 public static void clickElementUsingActions(WebElement element){
342 Actions actions = new Actions(getDriver());
344 actions.moveToElement(element);
353 public static void waitForLoader() {
354 waitForLoader(timeOut);
357 public static void waitForLoader(int timeOut) {
359 waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
362 public static void findComponentAndClick(String resourceName) throws Exception {
363 SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in homepage");
364 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
366 searchTextbox.clear();
367 searchTextbox.sendKeys(resourceName);
371 SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
377 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component from home screen", resourceName));
378 clickOnElementByTestId(resourceName);
379 GeneralUIUtils.ultimateWait();
380 getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
383 SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
389 public static String getComponentVersion(String componentName) {
390 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
393 public static void windowZoomOut() {
394 final int zoomOutFactor = 3;
395 for (int i = 0; i < zoomOutFactor; i++) {
396 if(getDriver() instanceof FirefoxDriver) {
397 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
402 public static void resetZoom(){
403 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
406 public static void windowZoomOutUltimate(){
409 // JavascriptExecutor js = (JavascriptExecutor) driver;
410 // js.executeScript("document.body.style.zoom='90%'");
413 public static void clickASDCLogo() {
414 WebDriverWait wait = newWait(15);
415 wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("ASDC")));
416 WebElement ClickASDCLogo = getDriver().findElement(By.linkText("ASDC"));
417 ClickASDCLogo.click();
418 GeneralUIUtils.waitForLoader();
421 public static void sleep(int millis) {
423 Thread.sleep(millis);
424 } catch (InterruptedException e) {
425 throw new RuntimeException(e);
429 public static void moveToStep(DataTestIdEnum.StepsEnum Stepname) {
430 moveToStep(Stepname.getValue());
431 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to %s page ", Stepname.toString()));
434 public static void moveToStep(String dataTestId) {
435 clickOnElementByTestId(dataTestId);
440 public static Select getSelectList(String item, String datatestsid) {
441 Select selectlist = new Select(getWebElementByTestID(datatestsid));
443 selectlist.selectByVisibleText(item);
444 Assert.assertThat(selectlist.getFirstSelectedOption().getText(), is(item));
449 public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
450 GeneralUIUtils.waitForLoader();
451 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
454 public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
455 GeneralUIUtils.waitForLoader();
456 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
460 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString){
461 WebDriverWait wait = newWait(timeOut);
462 GeneralUIUtils.waitForLoader();
463 return parentElement.findElement(By.cssSelector(cssString));
466 public static WebElement getElementfromElementByXPATH(WebElement parentElement, DashboardCardEnum dataTestId){
467 WebDriverWait wait = newWait(timeOut);
468 GeneralUIUtils.waitForLoader();
469 return HighlightMyElement( parentElement.findElement(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']")));
472 public static WebElement HighlightMyElement(WebElement element) {
473 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
474 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 4px solid yellow;");
478 public static WebElement getSelectedElementFromDropDown(String dataTestId){
479 GeneralUIUtils.ultimateWait();;
480 WebElement selectedElement = new Select (getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).getFirstSelectedOption();
481 return selectedElement;
485 public static void waitForPageLoadByReadyState() {
486 newWait(30).until((ExpectedCondition<Boolean>) wd ->
487 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
491 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
492 int maxWaitingPeriodMS = 10 * 1000;
493 int napPeriodMS = 100;
494 int sumOfWaiting = 0;
495 List<WebElement> elements = null;
496 boolean isKeepWaiting = false;
497 while (!isKeepWaiting) {
498 elements = func.get();
499 isKeepWaiting = (expectedElementsCount == elements.size());
500 sleep(isKeepWaiting ? napPeriodMS : 0);
501 sumOfWaiting += napPeriodMS;
502 if (sumOfWaiting > maxWaitingPeriodMS)
508 public static String getActionDuration(Runnable func) throws Exception{
509 long startTime = System.nanoTime();
511 long estimateTime = System.nanoTime();
512 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
513 String durationString = String.format("%02d:%02d", duration / 60, duration % 60);
514 return durationString;
517 public static WebElement clickOnAreaJS(String areaId) {
518 return clickOnAreaJS(areaId, timeOut);
522 public static WebElement clickOnAreaJS(String areaId, int timeout) {
525 WebElement area = getWebElementByTestID(areaId);
526 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
527 //HighlightMyElement(area);
528 Object executeScript = javascript.executeScript("arguments[0].click();", area, "color: yellow; border: 4px solid yellow;");
529 waitForLoader(timeout);
540 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
541 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
542 //HighlightMyElement(area);
543 javascript.executeScript("arguments[0].click();", areaId, "color: yellow; border: 4px solid yellow;");
549 public static void clickSomewhereOnPage() {
550 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
553 public static void findComponentAndClickInCatalog(String resourceName) throws Exception {
554 // This method will find element by element name, don't use data-tests-id argument
555 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
556 searchTextbox.clear();
557 searchTextbox.sendKeys(resourceName);
559 clickOnElementByText(resourceName);
563 public static void clickOnElementByText(String textInElement) {
564 logger.info("clickOnElementByText: {}", textInElement);
565 WebDriverWait wait = newWait(timeOut);
566 HighlightMyElement(wait.until(
567 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
570 public static void clickOnElementByText(String textInElement, int customTimeout) {
571 logger.info("clickOnElementByText: {}", textInElement);
572 WebDriverWait wait = newWait(customTimeout);
573 HighlightMyElement(wait.until(ExpectedConditions.elementToBeClickable(searchByTextContaining(textInElement)))).click();
576 private static WebDriverWait newWait(int timeoutInSeconds) {
577 final WebDriver driver = getDriver();
578 driver.manage().timeouts().setScriptTimeout(timeoutInSeconds, TimeUnit.SECONDS);
579 return new WebDriverWait(driver, timeoutInSeconds, 120);
582 public static void clickJSOnElementByText(String textInElement) throws Exception {
583 WebDriverWait wait = newWait(timeOut);
584 clickOnAreaJS(wait.until(
585 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
588 public static void fluentWaitTestID(String dataTestId, String text) {
589 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(getDriver())
590 .withTimeout(30, TimeUnit.SECONDS)
591 .pollingEvery(50, TimeUnit.MILLISECONDS)
592 .ignoring(NoSuchElementException.class);
594 fluentWait.until(ExpectedConditions.refreshed(
595 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
598 public static void regularWait(WebElement element, String text){
599 WebDriverWait wait = newWait(timeOut);
601 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
605 public static void waitForAngular(){
606 WebDriverWait wait = newWait(90);
607 wait.until(AdditionalConditions.pageLoadWait());
608 wait.until(AdditionalConditions.angularHasFinishedProcessing());
612 public static void waitForAngular2(){
613 WebDriverWait wait = newWait(90);
614 wait.until(AdditionalConditions.pageLoadWait());
616 WebDriverWait briefWait = newWait(2);
617 briefWait.until(AdditionalConditions.angular2HasFinishedProcessing());
618 } catch (TimeoutException | org.openqa.selenium.ScriptTimeoutException e) {
619 logger.info("Ignoring TimeoutException while waiting for angular2: {}", e, e);
623 public static Object getAllElementAttributes(WebElement element) {
624 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);
627 public static boolean isElementReadOnly(WebElement element){
629 HighlightMyElement(element).clear();
631 } catch (Exception e) {
636 public static boolean isElementReadOnly(String dataTestId){
637 return isElementReadOnly(
638 waitForElementVisibilityByTestId(dataTestId));
641 public static boolean isElementDisabled(WebElement element){
642 return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
643 element.getAttribute("class").contains("disabled");
646 public static boolean isElementDisabled(String dataTestId){
647 return isElementDisabled(
648 waitForElementVisibilityByTestId(dataTestId));
652 public static void ultimateWait(){
653 logger.info("ultimateWait: starting");
654 long startTime = System.nanoTime();
656 GeneralUIUtils.waitForAngular();
657 logger.info("ultimateWait: waited for angular: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
659 GeneralUIUtils.waitForAngular2();
660 logger.info("ultimateWait: waited for angular2: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
662 long estimateTime = System.nanoTime();
663 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
664 if(duration > timeOut){
665 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
668 logger.info("ultimateWait: done");
671 public static WebElement makeElementVisibleWithJS(WebElement element){
672 String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
673 ((JavascriptExecutor) getDriver()).executeScript(js, element);
677 public static WebElement unhideElement(WebElement element, String attributeValue){
678 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
679 ((JavascriptExecutor) getDriver()).executeScript(js, element);
683 public static WebElement findByText(String textInElement){
684 return getDriver().findElement(searchByTextContaining(textInElement));
687 public static List<WebElement> findElementsByText(String textInElement){
688 return getDriver().findElements(searchByTextContaining(textInElement));
691 public static By searchByTextContaining(String textInElement) {
692 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
696 public static boolean findAndWaitByText(String textInElement, int timeout){
697 logger.info("findAndWaitByText: {}", textInElement);
699 WebDriverWait wait = newWait(timeout);
700 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
708 public static WebElement getClickableButtonBy(By by, int timout){
710 WebDriverWait wait = newWait(timout);
711 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
721 public static WebElement getButtonWithText(String textInButton){
723 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
732 public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
734 return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
737 public static void closeErrorMessage() {
738 WebElement okWebElement = getButtonWithText("OK");
739 if (okWebElement != null){
740 okWebElement.click();
745 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
747 return getDriver().findElement(By.cssSelector(cssString));
750 public static String getDataTestIdAttributeValue(WebElement element) {
751 return element.getAttribute("data-tests-id");
754 public static String getTextContentAttributeValue(WebElement element) {
755 return element.getAttribute("textContent");
758 public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
760 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
767 public static void clickOnElementByCSS(String cssString) throws Exception {
768 WebDriverWait wait = newWait(timeOut);
769 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
772 public static String getRandomComponentName(String prefix) {
773 return prefix + GeneralUIUtils.randomNumber();
775 public static int randomNumber() {
776 Random r = new Random();
777 return r.nextInt(10000);
780 public static void waitForUINotification() {
781 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
782 if (!notificationElements.isEmpty()){
783 notificationElements.forEach(WebElement::click);
787 public static boolean checkForDisabledAttribute(String dataTestId){
788 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
789 return elementAttributes.toString().contains("disabled");
792 public static void dragAndDropElementByY(WebElement area, int yOffset) {
793 Actions actions = new Actions(getDriver());
794 actions.dragAndDropBy(area, 10, yOffset).perform();
798 public static void waitForBackLoader() {
799 waitForBackLoader(timeOut);
802 public static void waitForBackLoader(int timeOut) {
804 waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);