Merge automation from ECOMP's repository
[vid.git] / vid-automation / src / main / java / org / onap / sdc / ci / tests / utilities / GeneralUIUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.sdc.ci.tests.utilities;
22
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;
36
37 import java.awt.*;
38 import java.awt.event.KeyEvent;
39 import java.io.File;
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;
47
48 import static org.hamcrest.Matchers.is;
49
50
51 public final class GeneralUIUtils {
52
53         public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
54         static final Logger logger = LoggerFactory.getLogger(GeneralUIUtils.class);
55
56         private static int timeOut=90;
57
58 //      public static void setTimeOut(int time) {
59 //              if (time>0) {
60 //                      timeOut=time;
61 //              }
62 //              else {
63 //                      timeOut=timeOut;
64 //              }
65 //      }
66
67         /**************** DRIVER ****************/
68
69         public static WebDriver getDriver() {
70                 try{
71                         return DriverFactory.getDriver();
72                 }
73                 catch(Exception e){
74                         e.printStackTrace();
75                 }
76                 return null;
77         }
78         /****************************************/
79
80         public static List<WebElement> getElemenetsFromTable(By by) {
81                 return getDriver().findElements(by);
82         }
83
84         public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
85                 if (screenshotFilename == null) {
86                         if (testName != null){
87                                 screenshotFilename = testName;
88                         }
89                         else
90                         {
91                                 screenshotFilename = UUID.randomUUID().toString();
92                         }
93                 }
94                 try {
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);
99                         return filePath;
100                 } catch (IOException e1) {
101                         e1.printStackTrace();
102                 }
103                 return null;
104         }
105
106         public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
107                 return takeScreenshot(screenshotFilename, dir, null);
108         }
109
110
111         public static void scrollDown() {
112                 try{
113                         Robot robot = new Robot();
114                         robot.keyPress(KeyEvent.VK_DOWN);
115                         robot.keyRelease(KeyEvent.VK_DOWN);
116                         GeneralUIUtils.waitForLoader();
117                 }
118                 catch(Exception e){
119                         e.printStackTrace();
120                 }
121         }
122
123
124         public static WebElement getWebElementByTestID(String dataTestId) {
125                 return getWebElementByTestID(dataTestId, timeOut);
126         }
127
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 + "']")));
131         }
132
133         public static boolean isWebElementExistByTestId(String dataTestId) {
134                 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
135                         return false;
136                 }
137                 return true;
138         }
139
140         public static WebElement getInputElement(String dataTestId) {
141                 try{
142                         ultimateWait();
143                         return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
144                 }
145                 catch(Exception e){
146                         return null;
147                 }
148         }
149
150         public static List<WebElement> getInputElements(String dataTestId) {
151                 ultimateWait();
152                 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
153
154         }
155
156         public static WebElement getWebElementBy(By by) {
157                 return getWebElementBy(by, timeOut);
158         }
159
160         public static WebElement getWebElementBy(By by, int timeoutInSeconds) {
161                 WebDriverWait wait = newWait(timeoutInSeconds);
162                 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
163         }
164
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());
169                 }
170                 return Text;
171         }
172
173
174         public static List<WebElement> getWebElementsListBy(By by) {
175                 return getWebElementsListBy(by, timeOut);
176         }
177
178         public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
179                 WebDriverWait wait = newWait(timeOut);
180                 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
181         }
182
183         public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
184                 try{
185                         WebDriverWait wait = newWait(10);
186                         return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
187                 }
188                 catch(Exception e){
189                         return new ArrayList<WebElement>();
190                 }
191         }
192
193         public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
194                 return getWebElementsListByContainsClassName(containedText, timeOut);
195         }
196
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+"')]")));
200         }
201
202         public static WebElement getWebElementByContainsClassName(String containedText) {
203                 return getWebElementByContainsClassName(containedText, timeOut);
204         }
205
206         public static WebElement getWebElementByContainsClassName(String containedText, int timeoutInSeconds) {
207                 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"), timeoutInSeconds);
208         }
209
210         public static WebElement getWebElementByClassName(String className) {
211                 return getWebElementByClassName(className, timeOut);
212         }
213
214         public static WebElement getWebElementByClassName(String className, int timeoutInSeconds) {
215                 WebDriverWait wait = newWait(timeoutInSeconds);
216                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
217         }
218
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(
223                 By.xpath(xpath)));
224     }
225
226         public static WebElement getWebElementByLinkText(String linkText) {
227                 WebDriverWait wait = newWait(timeOut);
228                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
229         }
230
231
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 + "']")));
235         }
236
237         public static List<WebElement> getWebElementsListByClassName(String className) {
238                 WebDriverWait wait = newWait(timeOut);
239                 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
240         }
241
242
243
244
245         public static Boolean isElementInvisibleByTestId(String dataTestId) {
246                 WebDriverWait wait = newWait(timeOut);
247                 return wait.until(
248                                 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
249         }
250
251         public static Boolean isElementVisibleByTestId(String dataTestId) {
252                 try{
253                         WebDriverWait wait = newWait(timeOut);
254                         if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
255                                 return true;
256                         }else {
257                                 return false;
258                         }
259                 }
260                 catch(Exception e){
261                         return false;
262                 }
263         }
264
265         public static void clickOnElementByTestId(String dataTestId) {
266                 clickOnElementByTestIdWithoutWait(dataTestId);
267                 ultimateWait();
268         }
269
270         public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
271                 WebDriverWait wait = newWait(timeOut);
272                 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']"))).click();
273         }
274
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();
278         }
279
280         public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
281                 WebDriverWait wait = newWait(timeOut);
282                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
283         }
284
285         public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
286                 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
287         }
288
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();
292                 if (!displayed){
293                         Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
294                         ultimateWait();
295                         return until;
296                 }
297                 return false;
298         }
299
300         public static Boolean waitForElementInVisibilityByTestId(By by) {
301                 return waitForElementInVisibilityBy(by, timeOut);
302         }
303
304
305         public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
306                 WebDriverWait wait = newWait(timeOut);
307                 boolean displayed = getDriver().findElements(by).isEmpty();
308                 if (!displayed){
309                         Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
310                         sleep(1);
311                         return until;
312                 }
313                 return false;
314         }
315
316
317         public static void setWebElementByTestId(String elementID, String value) {
318                 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elementID);
319                 resourceDescriptionTextbox.clear();
320                 resourceDescriptionTextbox.sendKeys(value);
321
322         }
323
324         public static WebElement hoverOnAreaByTestId(String areaId) {
325                 Actions actions = new Actions(getDriver());
326                 WebElement area = getWebElementByTestID(areaId);
327                 actions.moveToElement(area).perform();
328                 ultimateWait();
329                 return area;
330         }
331
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();
337                 return area;
338         }
339
340         public static void clickElementUsingActions(WebElement element){
341                 Actions actions = new Actions(getDriver());
342
343                 actions.moveToElement(element);
344                 actions.perform();
345
346                 actions.click();
347                 actions.perform();
348
349                 ultimateWait();
350         }
351
352         public static void waitForLoader() {
353                 waitForLoader(timeOut);
354         }
355
356         public static void waitForLoader(int timeOut) {
357                 sleep(1);
358                 waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
359         }
360
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());
364                 try{
365                         searchTextbox.clear();
366                         searchTextbox.sendKeys(resourceName);
367                         ultimateWait();
368                 }
369                 catch(Exception e){
370                         SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
371                         e.printStackTrace();
372                 }
373
374
375                 try{
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());
380                 }
381                 catch(Exception e){
382                         SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
383                         e.printStackTrace();
384                 }
385         }
386
387
388         public static String getComponentVersion(String componentName) {
389                 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
390         }
391
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));
397                                 }
398                 }
399         }
400
401         public static void resetZoom(){
402                 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
403         }
404
405         public static void windowZoomOutUltimate(){
406                 resetZoom();
407                 windowZoomOut();
408 //              JavascriptExecutor js = (JavascriptExecutor) driver;
409 //              js.executeScript("document.body.style.zoom='90%'");
410         }
411
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();
418         }
419
420         public static void sleep(int millis) {
421                 try {
422                         Thread.sleep(millis);
423                 } catch (InterruptedException e) {
424                         throw new RuntimeException(e);
425                 }
426         }
427
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()));
431         }
432
433         public static void moveToStep(String dataTestId) {
434                 clickOnElementByTestId(dataTestId);
435                 ultimateWait();
436         }
437
438
439         public static Select getSelectList(String item, String datatestsid) {
440                 Select selectlist = new Select(getWebElementByTestID(datatestsid));
441                 if (item != null) {
442                         selectlist.selectByVisibleText(item);
443                         Assert.assertThat(selectlist.getFirstSelectedOption().getText(), is(item));
444                 }
445                 return selectlist;
446         }
447
448         public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
449                 GeneralUIUtils.waitForLoader();
450                 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
451         }
452
453     public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
454                 GeneralUIUtils.waitForLoader();
455                 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
456                 return assets;
457         }
458
459     public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString){
460         WebDriverWait wait = newWait(timeOut);
461         GeneralUIUtils.waitForLoader();
462         return parentElement.findElement(By.cssSelector(cssString));
463     }
464
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() + "']")));
469     }
470
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;");
474            return element;
475     }
476
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;
481     }
482
483
484     public static void waitForPageLoadByReadyState() {
485         newWait(30).until((ExpectedCondition<Boolean>) wd ->
486                 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
487     }
488
489
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)
502                                 return false;
503                 }
504                 return true;
505         }
506
507         public static String getActionDuration(Runnable func) throws Exception{
508                 long startTime = System.nanoTime();
509                 func.run();
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;
514         }
515
516     public static WebElement clickOnAreaJS(String areaId) {
517         return clickOnAreaJS(areaId, timeOut);
518     }
519
520
521     public static WebElement clickOnAreaJS(String areaId, int timeout) {
522         try{
523                 ultimateWait();
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);
529                 return area;
530         }
531         catch (Exception e){
532                 e.printStackTrace();
533         }
534                 return null;
535     }
536
537
538
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;");
543         return areaId;
544     }
545
546
547
548     public static void clickSomewhereOnPage() {
549         getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
550         }
551
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);
557                 ultimateWait();
558                 clickOnElementByText(resourceName);
559                 ultimateWait();
560         }
561
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();
567         }
568
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();
573         }
574
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);
579         }
580
581         public static void clickJSOnElementByText(String textInElement) throws Exception {
582                 WebDriverWait wait = newWait(timeOut);
583                 clickOnAreaJS(wait.until(
584                                 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
585         }
586
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);
592
593                 fluentWait.until(ExpectedConditions.refreshed(
594                                 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
595     }
596
597     public static void regularWait(WebElement element, String text){
598         WebDriverWait wait = newWait(timeOut);
599
600                 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
601     }
602
603     public static void waitForAngular(){
604         WebDriverWait wait = newWait(90);
605         wait.until(AdditionalConditions.pageLoadWait());
606         wait.until(AdditionalConditions.angularHasFinishedProcessing());
607     }
608
609     public static void waitForAngular2(){
610         WebDriverWait wait = newWait(90);
611         wait.until(AdditionalConditions.pageLoadWait());
612         try {
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);
617                 }
618     }
619
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);
622         }
623
624     public static boolean isElementReadOnly(WebElement element){
625         try {
626                 HighlightMyElement(element).clear();
627                         return false;
628                 } catch (Exception e) {
629                         return true;
630                 }
631     }
632
633     public static boolean isElementReadOnly(String dataTestId){
634         return isElementReadOnly(
635                         waitForElementVisibilityByTestId(dataTestId));
636     }
637
638     public static boolean isElementDisabled(WebElement element){
639         return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
640                         element.getAttribute("class").contains("disabled");
641     }
642
643     public static boolean isElementDisabled(String dataTestId){
644         return isElementDisabled(
645                         waitForElementVisibilityByTestId(dataTestId));
646     }
647
648     public static void ultimateWait(){
649                 logger.info("ultimateWait: starting");
650         long startTime = System.nanoTime();
651
652                 GeneralUIUtils.waitForAngular();
653                 logger.info("ultimateWait: waited for angular: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
654
655                 GeneralUIUtils.waitForAngular2();
656                 logger.info("ultimateWait: waited for angular2: {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime));
657
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));
662                 }
663
664                 logger.info("ultimateWait: done");
665     }
666
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);
670         return element;
671     }
672
673     public static WebElement unhideElement(WebElement element, String attributeValue){
674         String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
675         ((JavascriptExecutor) getDriver()).executeScript(js, element);
676         return element;
677     }
678
679     public static WebElement findByText(String textInElement){
680         return getDriver().findElement(searchByTextContaining(textInElement));
681     }
682
683         public static List<WebElement> findElementsByText(String textInElement){
684                 return getDriver().findElements(searchByTextContaining(textInElement));
685         }
686
687     public static By searchByTextContaining(String textInElement) {
688                 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
689         }
690
691
692     public static boolean findAndWaitByText(String textInElement, int timeout){
693                 logger.info("findAndWaitByText: {}", textInElement);
694         try{
695                 WebDriverWait wait = newWait(timeout);
696                 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
697                 return true;
698         }
699         catch(Exception e){
700                 return false;
701         }
702     }
703
704     public static WebElement getClickableButtonBy(By by, int timout){
705         try{
706                 WebDriverWait wait = newWait(timout);
707                 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
708                 return element;
709         }
710         catch(Exception e){
711                 return null;
712         }
713     }
714
715
716
717     public static WebElement getButtonWithText(String textInButton){
718         try{
719                 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
720         }
721         catch(Exception e)
722         {
723                 return null;
724         }
725     }
726
727
728     public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
729         ultimateWait();
730         return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
731     }
732
733         public static void closeErrorMessage() {
734                 WebElement okWebElement = getButtonWithText("OK");
735                 if (okWebElement != null){
736                         okWebElement.click();
737                         ultimateWait();
738                 }
739         }
740
741     public static WebElement getElementByCSS(String cssString) throws InterruptedException {
742                 ultimateWait();
743                 return getDriver().findElement(By.cssSelector(cssString));
744         }
745
746     public static String getDataTestIdAttributeValue(WebElement element) {
747                 return element.getAttribute("data-tests-id");
748         }
749
750     public static String getTextContentAttributeValue(WebElement element) {
751                 return element.getAttribute("textContent");
752         }
753
754     public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
755         try{
756                 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
757         }
758         catch(Exception e){
759                 return null;
760         }
761         }
762
763     public static void clickOnElementByCSS(String cssString) throws Exception {
764                 WebDriverWait wait = newWait(timeOut);
765                 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
766                 ultimateWait();
767         }
768         public static String getRandomComponentName(String prefix) {
769                 return prefix + GeneralUIUtils.randomNumber();
770         }
771         public static int randomNumber() {
772                 Random r = new Random();
773                 return r.nextInt(10000);
774         }
775
776         public static void waitForUINotification() {
777                 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
778                 if (!notificationElements.isEmpty()){
779                         notificationElements.forEach(WebElement::click);
780                 }
781         }
782
783         public static boolean checkForDisabledAttribute(String  dataTestId){
784                 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
785                 return elementAttributes.toString().contains("disabled");
786         }
787
788         public static void dragAndDropElementByY(WebElement area, int yOffset) {
789                 Actions actions = new Actions(getDriver());
790                 actions.dragAndDropBy(area, 10, yOffset).perform();
791                 ultimateWait();
792         }
793
794         public static void waitForBackLoader() {
795                 waitForBackLoader(timeOut);
796         }
797
798         public static void waitForBackLoader(int timeOut) {
799                 sleep(1);
800                 waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);
801         }
802
803 }