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.aventstack.extentreports.Status;
24 import org.apache.commons.io.FileUtils;
25 import org.junit.Assert;
26 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.onap.sdc.ci.tests.datatypes.DataTestIdEnum.DashboardCardEnum;
28 import org.onap.sdc.ci.tests.execute.setup.DriverFactory;
29 import org.onap.sdc.ci.tests.execute.setup.SetupCDTest;
30 import org.openqa.selenium.*;
31 import org.openqa.selenium.firefox.FirefoxDriver;
32 import org.openqa.selenium.interactions.Actions;
33 import org.openqa.selenium.support.ui.*;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 import java.awt.event.KeyEvent;
40 import java.io.IOException;
41 import java.util.ArrayList;
42 import java.util.List;
43 import java.util.Random;
44 import java.util.UUID;
45 import java.util.concurrent.TimeUnit;
46 import java.util.function.Supplier;
48 import static org.hamcrest.Matchers.is;
51 public final class GeneralUIUtils {
53 public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
54 static final Logger logger = LoggerFactory.getLogger(GeneralUIUtils.class);
56 private static int timeOut=90;
58 // public static void setTimeOut(int time) {
67 /**************** DRIVER ****************/
69 public static WebDriver getDriver() {
71 return DriverFactory.getDriver();
78 /****************************************/
80 public static List<WebElement> getElemenetsFromTable(By by) {
81 return getDriver().findElements(by);
84 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
85 if (screenshotFilename == null) {
86 if (testName != null){
87 screenshotFilename = testName;
91 screenshotFilename = UUID.randomUUID().toString();
95 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
96 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
97 new File(dir).mkdirs();
98 FileUtils.copyFile(scrFile, filePath);
100 } catch (IOException e1) {
101 e1.printStackTrace();
106 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
107 return takeScreenshot(screenshotFilename, dir, null);
111 public static void scrollDown() {
113 Robot robot = new Robot();
114 robot.keyPress(KeyEvent.VK_DOWN);
115 robot.keyRelease(KeyEvent.VK_DOWN);
116 GeneralUIUtils.waitForLoader();
124 public static WebElement getWebElementByTestID(String dataTestId) {
125 return getWebElementByTestID(dataTestId, timeOut);
128 public static WebElement getWebElementByTestID(String dataTestId, int timeout) {
129 WebDriverWait wait = newWait(timeout);
130 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
133 public static boolean isWebElementExistByTestId(String dataTestId) {
134 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
140 public static WebElement getInputElement(String dataTestId) {
143 return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
150 public static List<WebElement> getInputElements(String dataTestId) {
152 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
156 public static WebElement getWebElementBy(By by) {
157 return getWebElementBy(by, timeOut);
160 public static WebElement getWebElementBy(By by, int timeoutInSeconds) {
161 WebDriverWait wait = newWait(timeoutInSeconds);
162 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
165 public static List<String> getWebElementListText(List<WebElement>elements) {
166 List<String>Text=new ArrayList<>();
167 for (WebElement webElement : elements) {
168 Text.add(webElement.getText());
174 public static List<WebElement> getWebElementsListBy(By by) {
175 return getWebElementsListBy(by, timeOut);
178 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
179 WebDriverWait wait = newWait(timeOut);
180 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
183 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
185 WebDriverWait wait = newWait(10);
186 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
189 return new ArrayList<WebElement>();
193 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
194 return getWebElementsListByContainsClassName(containedText, timeOut);
197 public static List<WebElement> getWebElementsListByContainsClassName(String containedText, int timeoutInSeconds) {
198 WebDriverWait wait = newWait(timeoutInSeconds);
199 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '"+containedText+"')]")));
202 public static WebElement getWebElementByContainsClassName(String containedText) {
203 return getWebElementByContainsClassName(containedText, timeOut);
206 public static WebElement getWebElementByContainsClassName(String containedText, int timeoutInSeconds) {
207 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"), timeoutInSeconds);
210 public static WebElement getWebElementByClassName(String className) {
211 return getWebElementByClassName(className, timeOut);
214 public static WebElement getWebElementByClassName(String className, int timeoutInSeconds) {
215 WebDriverWait wait = newWait(timeoutInSeconds);
216 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
219 public static List<WebElement> getWebElementsListByContainsClassNameAndText(String cssName, String text, int timeoutInSeconds) {
220 WebDriverWait wait = newWait(timeoutInSeconds);
221 String xpath = String.format("//*[contains(@class, '%s') and contains(text(),'%s')]", cssName, text);
222 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(
226 public static WebElement getWebElementByLinkText(String linkText) {
227 WebDriverWait wait = newWait(timeOut);
228 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
232 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
233 WebDriverWait wait = newWait(timeOut);
234 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
237 public static List<WebElement> getWebElementsListByClassName(String className) {
238 WebDriverWait wait = newWait(timeOut);
239 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
245 public static Boolean isElementInvisibleByTestId(String dataTestId) {
246 WebDriverWait wait = newWait(timeOut);
248 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
251 public static Boolean isElementVisibleByTestId(String dataTestId) {
253 WebDriverWait wait = newWait(timeOut);
254 if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
265 public static void clickOnElementByTestId(String dataTestId) {
266 clickOnElementByTestIdWithoutWait(dataTestId);
270 public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
271 WebDriverWait wait = newWait(timeOut);
272 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
275 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
276 WebDriverWait wait = newWait(customTimeout);
277 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
280 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
281 WebDriverWait wait = newWait(timeOut);
282 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
285 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
286 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
289 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
290 WebDriverWait wait = newWait(timeOut);
291 boolean displayed = getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).isEmpty();
293 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
300 public static Boolean waitForElementInVisibilityByTestId(By by) {
301 return waitForElementInVisibilityBy(by, timeOut);
305 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
306 WebDriverWait wait = newWait(timeOut);
307 boolean displayed = getDriver().findElements(by).isEmpty();
309 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
317 public static void setWebElementByTestId(String elementID, String value) {
318 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elementID);
319 resourceDescriptionTextbox.clear();
320 resourceDescriptionTextbox.sendKeys(value);
324 public static WebElement hoverOnAreaByTestId(String areaId) {
325 Actions actions = new Actions(getDriver());
326 WebElement area = getWebElementByTestID(areaId);
327 actions.moveToElement(area).perform();
332 public static WebElement hoverOnAreaByClassName(String className) {
333 Actions actions = new Actions(getDriver());
334 WebElement area = getWebElementByClassName(className);
335 actions.moveToElement(area).perform();
336 GeneralUIUtils.ultimateWait();
340 public static void clickElementUsingActions(WebElement element){
341 Actions actions = new Actions(getDriver());
343 actions.moveToElement(element);
352 public static void waitForLoader() {
353 waitForLoader(timeOut);
356 public static void waitForLoader(int timeOut) {
358 waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
361 public static void findComponentAndClick(String resourceName) throws Exception {
362 SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in homepage");
363 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
365 searchTextbox.clear();
366 searchTextbox.sendKeys(resourceName);
370 SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
376 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component from home screen", resourceName));
377 clickOnElementByTestId(resourceName);
378 GeneralUIUtils.ultimateWait();
379 getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
382 SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
388 public static String getComponentVersion(String componentName) {
389 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
392 public static void windowZoomOut() {
393 final int zoomOutFactor = 3;
394 for (int i = 0; i < zoomOutFactor; i++) {
395 if(getDriver() instanceof FirefoxDriver) {
396 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
401 public static void resetZoom(){
402 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
405 public static void windowZoomOutUltimate(){
408 // JavascriptExecutor js = (JavascriptExecutor) driver;
409 // js.executeScript("document.body.style.zoom='90%'");
412 public static void clickASDCLogo() {
413 WebDriverWait wait = newWait(15);
414 wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("ASDC")));
415 WebElement ClickASDCLogo = getDriver().findElement(By.linkText("ASDC"));
416 ClickASDCLogo.click();
417 GeneralUIUtils.waitForLoader();
420 public static void sleep(int millis) {
422 Thread.sleep(millis);
423 } catch (InterruptedException e) {
424 throw new RuntimeException(e);
428 public static void moveToStep(DataTestIdEnum.StepsEnum Stepname) {
429 moveToStep(Stepname.getValue());
430 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to %s page ", Stepname.toString()));
433 public static void moveToStep(String dataTestId) {
434 clickOnElementByTestId(dataTestId);
439 public static Select getSelectList(String item, String datatestsid) {
440 Select selectlist = new Select(getWebElementByTestID(datatestsid));
442 selectlist.selectByVisibleText(item);
443 Assert.assertThat(selectlist.getFirstSelectedOption().getText(), is(item));
448 public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
449 GeneralUIUtils.waitForLoader();
450 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
453 public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
454 GeneralUIUtils.waitForLoader();
455 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
459 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString){
460 WebDriverWait wait = newWait(timeOut);
461 GeneralUIUtils.waitForLoader();
462 return parentElement.findElement(By.cssSelector(cssString));
465 public static WebElement getElementfromElementByXPATH(WebElement parentElement, DashboardCardEnum dataTestId){
466 WebDriverWait wait = newWait(timeOut);
467 GeneralUIUtils.waitForLoader();
468 return HighlightMyElement( parentElement.findElement(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']")));
471 public static WebElement HighlightMyElement(WebElement element) {
472 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
473 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 4px solid yellow;");
477 public static WebElement getSelectedElementFromDropDown(String dataTestId){
478 GeneralUIUtils.ultimateWait();;
479 WebElement selectedElement = new Select (getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).getFirstSelectedOption();
480 return selectedElement;
484 public static void waitForPageLoadByReadyState() {
485 newWait(30).until((ExpectedCondition<Boolean>) wd ->
486 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
490 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
491 int maxWaitingPeriodMS = 10 * 1000;
492 int napPeriodMS = 100;
493 int sumOfWaiting = 0;
494 List<WebElement> elements = null;
495 boolean isKeepWaiting = false;
496 while (!isKeepWaiting) {
497 elements = func.get();
498 isKeepWaiting = (expectedElementsCount == elements.size());
499 sleep(isKeepWaiting ? napPeriodMS : 0);
500 sumOfWaiting += napPeriodMS;
501 if (sumOfWaiting > maxWaitingPeriodMS)
507 public static String getActionDuration(Runnable func) throws Exception{
508 long startTime = System.nanoTime();
510 long estimateTime = System.nanoTime();
511 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
512 String durationString = String.format("%02d:%02d", duration / 60, duration % 60);
513 return durationString;
516 public static WebElement clickOnAreaJS(String areaId) {
517 return clickOnAreaJS(areaId, timeOut);
521 public static WebElement clickOnAreaJS(String areaId, int timeout) {
524 WebElement area = getWebElementByTestID(areaId);
525 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
526 //HighlightMyElement(area);
527 Object executeScript = javascript.executeScript("arguments[0].click();", area, "color: yellow; border: 4px solid yellow;");
528 waitForLoader(timeout);
539 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
540 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
541 //HighlightMyElement(area);
542 javascript.executeScript("arguments[0].click();", areaId, "color: yellow; border: 4px solid yellow;");
548 public static void clickSomewhereOnPage() {
549 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
552 public static void findComponentAndClickInCatalog(String resourceName) throws Exception {
553 // This method will find element by element name, don't use data-tests-id argument
554 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
555 searchTextbox.clear();
556 searchTextbox.sendKeys(resourceName);
558 clickOnElementByText(resourceName);
562 public static void clickOnElementByText(String textInElement) {
563 logger.info("clickOnElementByText: {}", textInElement);
564 WebDriverWait wait = newWait(timeOut);
565 HighlightMyElement(wait.until(
566 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
569 public static void clickOnElementByText(String textInElement, int customTimeout) {
570 logger.info("clickOnElementByText: {}", textInElement);
571 WebDriverWait wait = newWait(customTimeout);
572 HighlightMyElement(wait.until(ExpectedConditions.elementToBeClickable(searchByTextContaining(textInElement)))).click();
575 private static WebDriverWait newWait(int timeoutInSeconds) {
576 final WebDriver driver = getDriver();
577 driver.manage().timeouts().setScriptTimeout(timeoutInSeconds, TimeUnit.SECONDS);
578 return new WebDriverWait(driver, timeoutInSeconds, 120);
581 public static void clickJSOnElementByText(String textInElement) throws Exception {
582 WebDriverWait wait = newWait(timeOut);
583 clickOnAreaJS(wait.until(
584 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
587 public static void fluentWaitTestID(String dataTestId, String text) {
588 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(getDriver())
589 .withTimeout(30, TimeUnit.SECONDS)
590 .pollingEvery(50, TimeUnit.MILLISECONDS)
591 .ignoring(NoSuchElementException.class);
593 fluentWait.until(ExpectedConditions.refreshed(
594 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
597 public static void regularWait(WebElement element, String text){
598 WebDriverWait wait = newWait(timeOut);
600 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
603 public static void waitForAngular(){
604 WebDriverWait wait = newWait(90);
605 wait.until(AdditionalConditions.pageLoadWait());
606 wait.until(AdditionalConditions.angularHasFinishedProcessing());
609 public static void waitForAngular2(){
610 WebDriverWait wait = newWait(90);
611 wait.until(AdditionalConditions.pageLoadWait());
613 WebDriverWait briefWait = newWait(2);
614 briefWait.until(AdditionalConditions.angular2HasFinishedProcessing());
615 } catch (TimeoutException | org.openqa.selenium.ScriptTimeoutException e) {
616 logger.info("Ignoring TimeoutException while waiting for angular2: {}", e, e);
620 public static Object getAllElementAttributes(WebElement element) {
621 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);
624 public static boolean isElementReadOnly(WebElement element){
626 HighlightMyElement(element).clear();
628 } catch (Exception e) {
633 public static boolean isElementReadOnly(String dataTestId){
634 return isElementReadOnly(
635 waitForElementVisibilityByTestId(dataTestId));
638 public static boolean isElementDisabled(WebElement element){
639 return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
640 element.getAttribute("class").contains("disabled");
643 public static boolean isElementDisabled(String dataTestId){
644 return isElementDisabled(
645 waitForElementVisibilityByTestId(dataTestId));
648 public static void ultimateWait(){
649 logger.info("ultimateWait: starting");
650 long startTime = System.nanoTime();
652 GeneralUIUtils.waitForAngular();
653 logger.info("ultimateWait: waited for angular: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
655 GeneralUIUtils.waitForAngular2();
656 logger.info("ultimateWait: waited for angular2: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
658 long estimateTime = System.nanoTime();
659 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
660 if(duration > timeOut){
661 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
664 logger.info("ultimateWait: done");
667 public static WebElement makeElementVisibleWithJS(WebElement element){
668 String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
669 ((JavascriptExecutor) getDriver()).executeScript(js, element);
673 public static WebElement unhideElement(WebElement element, String attributeValue){
674 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
675 ((JavascriptExecutor) getDriver()).executeScript(js, element);
679 public static WebElement findByText(String textInElement){
680 return getDriver().findElement(searchByTextContaining(textInElement));
683 public static List<WebElement> findElementsByText(String textInElement){
684 return getDriver().findElements(searchByTextContaining(textInElement));
687 public static By searchByTextContaining(String textInElement) {
688 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
692 public static boolean findAndWaitByText(String textInElement, int timeout){
693 logger.info("findAndWaitByText: {}", textInElement);
695 WebDriverWait wait = newWait(timeout);
696 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
704 public static WebElement getClickableButtonBy(By by, int timout){
706 WebDriverWait wait = newWait(timout);
707 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
717 public static WebElement getButtonWithText(String textInButton){
719 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
728 public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
730 return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
733 public static void closeErrorMessage() {
734 WebElement okWebElement = getButtonWithText("OK");
735 if (okWebElement != null){
736 okWebElement.click();
741 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
743 return getDriver().findElement(By.cssSelector(cssString));
746 public static String getDataTestIdAttributeValue(WebElement element) {
747 return element.getAttribute("data-tests-id");
750 public static String getTextContentAttributeValue(WebElement element) {
751 return element.getAttribute("textContent");
754 public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
756 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
763 public static void clickOnElementByCSS(String cssString) throws Exception {
764 WebDriverWait wait = newWait(timeOut);
765 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
768 public static String getRandomComponentName(String prefix) {
769 return prefix + GeneralUIUtils.randomNumber();
771 public static int randomNumber() {
772 Random r = new Random();
773 return r.nextInt(10000);
776 public static void waitForUINotification() {
777 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
778 if (!notificationElements.isEmpty()){
779 notificationElements.forEach(WebElement::click);
783 public static boolean checkForDisabledAttribute(String dataTestId){
784 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
785 return elementAttributes.toString().contains("disabled");
788 public static void dragAndDropElementByY(WebElement area, int yOffset) {
789 Actions actions = new Actions(getDriver());
790 actions.dragAndDropBy(area, 10, yOffset).perform();
794 public static void waitForBackLoader() {
795 waitForBackLoader(timeOut);
798 public static void waitForBackLoader(int timeOut) {
800 waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);