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.openecomp.sdc.ci.tests.utilities;
23 import com.aventstack.extentreports.Status;
24 import org.apache.commons.io.FileUtils;
25 import org.openecomp.sdc.ci.tests.datatypes.CatalogFilterTitlesEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.DashboardCardEnum;
28 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
29 import org.openecomp.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.*;
36 import java.awt.datatransfer.Clipboard;
37 import java.awt.datatransfer.StringSelection;
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;
49 public final class GeneralUIUtils {
51 public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
53 private static int timeOut=(int) (60*1.5);
55 // public static void setTimeOut(int time) {
64 /**************** DRIVER ****************/
66 public static WebDriver getDriver() {
68 return DriverFactory.getDriver();
75 /****************************************/
77 public static List<WebElement> getElemenetsFromTable(By by) {
78 return getDriver().findElements(by);
81 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
82 if (screenshotFilename == null) {
83 if (testName != null){
84 screenshotFilename = testName;
88 screenshotFilename = UUID.randomUUID().toString();
92 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
93 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
94 new File(dir).mkdirs();
95 FileUtils.copyFile(scrFile, filePath);
97 } catch (IOException e1) {
103 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
104 return takeScreenshot(screenshotFilename, dir, null);
108 public static void scrollDown() {
110 Robot robot = new Robot();
111 robot.keyPress(KeyEvent.VK_DOWN);
112 robot.keyRelease(KeyEvent.VK_DOWN);
113 GeneralUIUtils.waitForLoader();
120 public static void minimizeCatalogFilterByTitle(CatalogFilterTitlesEnum titlesEnum) {
122 switch (titlesEnum) {
124 GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
127 GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
130 GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
138 public static WebElement getWebElementByTestID(String dataTestId) {
139 return getWebElementByTestID(dataTestId, timeOut);
142 public static WebElement getWebElementByTestID(String dataTestId, int timeout) {
143 WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
144 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
147 public static boolean isWebElementExistByTestId(String dataTestId) {
148 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
154 public static boolean isWebElementExistByClass(String className) {
155 if(getDriver().findElements(By.className(className)).size() == 0) {
161 public static WebElement getInputElement(String dataTestId) {
164 return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
171 public static List<WebElement> getInputElements(String dataTestId) {
173 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
178 public static WebElement getWebElementBy(By by) {
179 return getWebElementBy(by, timeOut);
182 public static WebElement getWebElementBy(By by, int timeOut) {
183 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
184 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
187 public static List<String> getWebElementListText(List<WebElement>elements) {
188 List<String>Text=new ArrayList<>();
189 for (WebElement webElement : elements) {
190 Text.add(webElement.getText());
196 public static List<WebElement> getWebElementsListBy(By by) {
197 return getWebElementsListBy(by, timeOut);
200 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
201 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
202 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
205 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
207 WebDriverWait wait = new WebDriverWait(getDriver(), 10);
208 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
211 return new ArrayList<WebElement>();
215 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
216 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
217 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '"+containedText+"')]")));
220 public static WebElement getWebElementByContainsClassName(String containedText) {
221 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"));
224 public static WebElement getWebElementByClassName(String className) {
225 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
226 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
229 public static WebElement getWebElementByLinkText(String linkText) {
230 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
231 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
235 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
236 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
237 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
240 public static List<WebElement> getWebElementsListByClassName(String className) {
241 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
242 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
248 public static Boolean isElementInvisibleByTestId(String dataTestId) {
249 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
251 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
254 public static Boolean isElementVisibleByTestId(String dataTestId) {
256 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
257 if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
268 public static void clickOnElementByTestId(String dataTestId) {
269 clickOnElementByTestIdWithoutWait(dataTestId);
273 public static void clickOnElementByClassName(String className) {
274 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
275 wait.until(ExpectedConditions.elementToBeClickable(By.className(className))).click();
279 public static void clickOnElementById(String id) {
280 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
281 wait.until(ExpectedConditions.elementToBeClickable(By.id(id))).click();
285 public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
286 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
287 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
290 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
291 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
292 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
295 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
296 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
297 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
300 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
301 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
304 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
305 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
306 boolean displayed = getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).isEmpty();
308 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
315 public static Boolean waitForElementInVisibilityByTestId(By by) {
316 return waitForElementInVisibilityBy(by, timeOut);
320 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
321 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
322 boolean displayed = getDriver().findElements(by).isEmpty();
324 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
332 public static void setWebElementByTestId(String elemetID, String value) {
333 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
334 resourceDescriptionTextbox.clear();
335 resourceDescriptionTextbox.sendKeys(value);
339 public static WebElement hoverOnAreaByTestId(String areaId) {
340 Actions actions = new Actions(getDriver());
341 WebElement area = getWebElementByTestID(areaId);
342 actions.moveToElement(area).perform();
347 public static WebElement hoverOnAreaByClassName(String className) {
348 Actions actions = new Actions(getDriver());
349 WebElement area = getWebElementByClassName(className);
350 actions.moveToElement(area).perform();
351 GeneralUIUtils.ultimateWait();
355 public static void clickElementUsingActions(WebElement element){
356 Actions actions = new Actions(getDriver());
358 actions.moveToElement(element);
367 public static void waitForLoader() {
368 waitForLoader(timeOut);
371 public static void waitForLoader(int timeOut) {
373 waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
376 public static void findComponentAndClick(String resourceName) throws Exception {
377 SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in homepage");
378 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
380 searchTextbox.clear();
381 searchTextbox.sendKeys(resourceName);
385 SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
391 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component from home screen", resourceName));
392 clickOnElementByTestId(resourceName);
393 GeneralUIUtils.ultimateWait();
394 getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
397 SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
403 public static String getComponentVersion(String componentName) {
404 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
407 public static void windowZoomOut() {
408 final int zoomOutFactor = 3;
409 for (int i = 0; i < zoomOutFactor; i++) {
410 if(getDriver() instanceof FirefoxDriver) {
411 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
416 public static void resetZoom(){
417 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
420 public static void windowZoomOutUltimate(){
423 // JavascriptExecutor js = (JavascriptExecutor) driver;
424 // js.executeScript("document.body.style.zoom='90%'");
427 public static void clickASDCLogo() {
428 WebDriverWait wait = new WebDriverWait(getDriver(), 15);
429 wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("ASDC")));
430 WebElement ClickASDCLogo = getDriver().findElement(By.linkText("ASDC"));
431 ClickASDCLogo.click();
432 GeneralUIUtils.waitForLoader();
435 public static void sleep(int duration) {
437 Thread.sleep(duration);
438 } catch (InterruptedException e) {
439 throw new RuntimeException(e);
443 public static void moveToStep(DataTestIdEnum.StepsEnum stepName) {
444 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to %s page ", stepName.toString()));
445 moveToStep(stepName.getValue());
448 public static void moveToStep(String dataTestId) {
449 clickOnElementByTestId(dataTestId);
454 public static Select getSelectList(String item, String datatestsid) {
455 Select selectlist = new Select(getWebElementByTestID(datatestsid));
457 selectlist.selectByVisibleText(item);
462 public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
463 GeneralUIUtils.waitForLoader();
464 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
467 public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
468 GeneralUIUtils.waitForLoader();
469 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
473 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString){
474 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
475 GeneralUIUtils.waitForLoader();
476 return parentElement.findElement(By.cssSelector(cssString));
479 public static WebElement getElementfromElementByXPATH(WebElement parentElement, DashboardCardEnum dataTestId){
480 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
481 GeneralUIUtils.waitForLoader();
482 return HighlightMyElement( parentElement.findElement(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']")));
485 public static WebElement HighlightMyElement(WebElement element) {
486 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
487 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 4px solid yellow;");
491 public static WebElement getSelectedElementFromDropDown(String dataTestId){
492 GeneralUIUtils.ultimateWait();;
493 WebElement selectedElement = new Select (getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).getFirstSelectedOption();
494 return selectedElement;
498 public static void waitForPageLoadByReadyState() {
499 new WebDriverWait(getDriver(), 30).until((ExpectedCondition<Boolean>) wd ->
500 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
504 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
505 int maxWaitingPeriodMS = 10 * 1000;
506 int napPeriodMS = 100;
507 int sumOfWaiting = 0;
508 List<WebElement> elements = null;
509 boolean isKeepWaiting = false;
510 while (!isKeepWaiting) {
511 elements = func.get();
512 isKeepWaiting = (expectedElementsCount == elements.size());
514 sumOfWaiting += napPeriodMS;
515 if (sumOfWaiting > maxWaitingPeriodMS)
521 public static String getActionDuration(Runnable func) throws Exception{
522 long startTime = System.nanoTime();
524 long estimateTime = System.nanoTime();
525 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
526 String durationString = String.format("%02d:%02d", duration / 60, duration % 60);
527 return durationString;
530 public static WebElement clickOnAreaJS(String areaId) {
531 return clickOnAreaJS(areaId, timeOut);
535 public static WebElement clickOnAreaJS(String areaId, int timeout) {
538 WebElement area = getWebElementByTestID(areaId);
539 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
540 //HighlightMyElement(area);
541 Object executeScript = javascript.executeScript("arguments[0].click();", area, "color: yellow; border: 4px solid yellow;");
542 waitForLoader(timeout);
553 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
554 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
555 //HighlightMyElement(area);
556 javascript.executeScript("arguments[0].click();", areaId, "color: yellow; border: 4px solid yellow;");
562 public static void clickSomewhereOnPage() {
563 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
566 public static void findComponentAndClickInCatalog(String resourceName) throws Exception {
567 // This method will find element by element name, don't use data-tests-id argument
568 WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
569 searchTextbox.clear();
570 searchTextbox.sendKeys(resourceName);
572 clickOnElementByText(resourceName);
576 public static void clickOnElementByText(String textInElement) {
577 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
578 HighlightMyElement(wait.until(
579 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
582 public static void clickOnElementByText(String textInElement, int customTimeout) {
583 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
584 HighlightMyElement(wait.until(
585 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
588 public static void clickJSOnElementByText(String textInElement) throws Exception {
589 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
590 clickOnAreaJS(wait.until(
591 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
594 public static void fluentWaitTestID(String dataTestId, String text) {
595 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(getDriver())
596 .withTimeout(30, TimeUnit.SECONDS)
597 .pollingEvery(50, TimeUnit.MILLISECONDS)
598 .ignoring(NoSuchElementException.class);
600 fluentWait.until(ExpectedConditions.refreshed(
601 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
604 public static void regularWait(WebElement element, String text){
605 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
607 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
610 public static void waitForAngular(){
611 WebDriverWait wait = new WebDriverWait(getDriver(), 90, 100);
612 wait.until(AdditionalConditions.pageLoadWait());
613 wait.until(AdditionalConditions.angularHasFinishedProcessing());
616 public static Object getAllElementAttributes(WebElement element) {
617 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);
620 public static boolean isElementReadOnly(WebElement element){
622 HighlightMyElement(element).clear();
624 } catch (Exception e) {
629 public static boolean isElementReadOnly(String dataTestId){
630 return isElementReadOnly(
631 waitForElementVisibilityByTestId(dataTestId));
634 public static boolean isElementDisabled(WebElement element){
635 return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
636 element.getAttribute("class").contains("disabled");
639 public static boolean isElementDisabled(String dataTestId){
640 return isElementDisabled(
641 waitForElementVisibilityByTestId(dataTestId));
644 public static void ultimateWait(){
645 long startTime = System.nanoTime();
647 GeneralUIUtils.waitForLoader();
648 GeneralUIUtils.waitForBackLoader();
649 GeneralUIUtils.waitForAngular();
651 long estimateTime = System.nanoTime();
652 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
653 // System.out.println("UltimateWait took: "+ duration);
654 if(duration > timeOut){
655 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
657 // waitForUINotification();
660 public static WebElement makeElementVisibleWithJS(WebElement element){
661 String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
662 ((JavascriptExecutor) getDriver()).executeScript(js, element);
666 public static WebElement unhideElement(WebElement element, String attributeValue){
667 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
668 ((JavascriptExecutor) getDriver()).executeScript(js, element);
672 public static WebElement findByText(String textInElement){
673 return getDriver().findElement(searchByTextContaining(textInElement));
675 public static By searchByTextContaining(String textInElement) {
676 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
680 public static boolean findAndWaitByText(String textInElement, int timeout){
682 WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
683 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
691 public static WebElement getClickableButtonBy(By by, int timout){
693 WebDriverWait wait = new WebDriverWait(getDriver(), timout);
694 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
704 public static WebElement getButtonWithText(String textInButton){
706 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
715 public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
717 return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
720 public static void closeErrorMessage() {
721 WebElement okWebElement = getButtonWithText("OK");
722 if (okWebElement != null){
723 okWebElement.click();
728 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
730 return getDriver().findElement(By.cssSelector(cssString));
733 public static String getDataTestIdAttributeValue(WebElement element) {
734 return element.getAttribute("data-tests-id");
737 public static String getTextContentAttributeValue(WebElement element) {
738 return element.getAttribute("textContent");
741 public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
743 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
750 public static void clickOnElementByCSS(String cssString) throws Exception {
751 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
752 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
755 public static String getRandomComponentName(String prefix) {
756 return prefix + GeneralUIUtils.randomNumber();
758 public static int randomNumber() {
759 Random r = new Random();
760 return r.nextInt(10000);
763 public static void waitForUINotification() {
764 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
765 if (!notificationElements.isEmpty()){
766 notificationElements.forEach(WebElement::click);
770 public static boolean checkForDisabledAttribute(String dataTestId){
771 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
772 return elementAttributes.toString().contains("disabled");
775 public static void dragAndDropElementByY(WebElement area, int yOffset) {
776 Actions actions = new Actions(getDriver());
777 actions.dragAndDropBy(area, 10, yOffset).perform();
781 public static void waitForBackLoader() {
782 waitForBackLoader(timeOut);
785 public static void waitForBackLoader(int timeOut) {
787 waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);
790 public static void addStringtoClipboard(String text){
791 StringSelection selection = new StringSelection(text);
792 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
793 clipboard.setContents(selection, selection);
796 public static boolean checkForDisabledAttributeInHiddenElement(String cssString){
797 Object elementAttributes = getAllElementAttributes(getDriver().findElement(By.cssSelector(cssString)));
798 return elementAttributes.toString().contains("disabled");
801 public static void setTextInElementByDataTestID(String dataTestsID, String text)
803 WebElement webElement = GeneralUIUtils.getWebElementByTestID(dataTestsID);
805 webElement.sendKeys(text);
809 public static void selectByValueTextContained(String dataTestsId, String value) {
811 List<WebElement> options = GeneralUIUtils.getWebElementsListBy(By.xpath(String.format("//select[@data-tests-id='%s']//option[contains(@value,'%s')]",dataTestsId,value)));
813 boolean matched = false;
814 for (WebElement option : options) {
820 throw new NoSuchElementException("Cannot locate option with value: " + value);
826 public static void setTextInElementByXpath(String xPath, String text)
828 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
831 webElement.sendKeys(text);
835 public static String getTextValueFromInput(WebElement webElement)
837 return webElement.getAttribute("value");
840 public static String getTextValueFromWebElementByXpath(String Xpath)
842 WebElement webElement = getWebElementBy(By.xpath(Xpath));
843 return webElement.getAttribute("value");
846 public static void refreshPage(){
847 Actions actions = new Actions(getDriver());
848 actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();