Sync Integ to Master
[sdc.git] / ui-ci / src / main / java / org / openecomp / 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.openecomp.sdc.ci.tests.utilities;
22
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.*;
34
35 import java.awt.*;
36 import java.awt.datatransfer.Clipboard;
37 import java.awt.datatransfer.StringSelection;
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
49 public final class GeneralUIUtils {
50
51         public static final String FILE_NAME = "Valid_tosca_Mycompute.yml";
52         
53         private static int timeOut=(int) (60*1.5);
54         
55 //      public static void setTimeOut(int time) {
56 //              if (time>0) {
57 //                      timeOut=time;   
58 //              }
59 //              else {
60 //                      timeOut=timeOut;
61 //              }
62 //      }
63
64         /**************** DRIVER ****************/
65         
66         public static WebDriver getDriver() {
67                 try{
68                         return DriverFactory.getDriver();
69                 }
70                 catch(Exception e){
71                         e.printStackTrace();
72                 }
73                 return null;
74         }
75         /****************************************/
76         
77         public static List<WebElement> getElemenetsFromTable(By by) {
78                 return getDriver().findElements(by);
79         }
80
81         public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
82                 if (screenshotFilename == null) {
83                         if (testName != null){
84                                 screenshotFilename = testName;
85                         }
86                         else
87                         {
88                                 screenshotFilename = UUID.randomUUID().toString();
89                         }
90                 }
91                 try {
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);
96                         return filePath;
97                 } catch (IOException e1) {
98                         e1.printStackTrace();
99                 }
100                 return null;
101         }
102         
103         public static File takeScreenshot(String screenshotFilename, String dir) throws IOException{
104                 return takeScreenshot(screenshotFilename, dir, null);
105         }
106
107
108         public static void scrollDown() {
109                 try{
110                         Robot robot = new Robot();
111                         robot.keyPress(KeyEvent.VK_DOWN);
112                         robot.keyRelease(KeyEvent.VK_DOWN);
113                         GeneralUIUtils.waitForLoader();
114                 }
115                 catch(Exception e){
116                         e.printStackTrace();
117                 }
118         }
119
120         public static void minimizeCatalogFilterByTitle(CatalogFilterTitlesEnum titlesEnum) {
121
122                 switch (titlesEnum) {
123                 case CATEGORIES:
124                         GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
125                         break;
126                 case STATUS:
127                         GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
128                         break;
129                 case TYPE:
130                         GeneralUIUtils.getWebElementByTestID(titlesEnum.getValue()).click();
131                         break;
132                 default:
133                         break;
134                 }
135         
136         }
137
138         public static WebElement getWebElementByTestID(String dataTestId) {
139                 return getWebElementByTestID(dataTestId, timeOut);
140         }
141         
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 + "']")));
145         }
146         
147         public static boolean isWebElementExistByTestId(String dataTestId) {
148                 if(getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']")).size() == 0) {
149                         return false;
150                 }
151                 return true;
152         }
153
154         public static boolean isWebElementExistByClass(String className) {
155                 if(getDriver().findElements(By.className(className)).size() == 0) {
156                         return false;
157                 }
158                 return true;
159         }
160
161         public static WebElement getInputElement(String dataTestId) {
162                 try{
163                         ultimateWait();
164                         return getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
165                 }
166                 catch(Exception e){
167                         return null;
168                 }
169         }
170
171         public static List<WebElement> getInputElements(String dataTestId) {
172                 ultimateWait();
173                 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
174
175         }
176         
177         
178         public static WebElement getWebElementBy(By by) {
179                 return getWebElementBy(by, timeOut);
180         }
181         
182         public static WebElement getWebElementBy(By by, int timeOut) {
183                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
184                 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
185         }
186         
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());
191                 }
192                 return Text;
193         }
194         
195         
196         public static List<WebElement> getWebElementsListBy(By by) {
197                 return getWebElementsListBy(by, timeOut);
198         }
199         
200         public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
201                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
202                 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
203         }
204         
205         public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
206                 try{
207                         WebDriverWait wait = new WebDriverWait(getDriver(), 10);
208                         return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '"+dataTestId+"')]")));
209                 }
210                 catch(Exception e){
211                         return new ArrayList<WebElement>();
212                 }
213         }
214         
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+"')]")));
218         }
219         
220         public static WebElement getWebElementByContainsClassName(String containedText) {
221                 return getWebElementBy(By.xpath("//*[contains(@class, '"+containedText+"')]"));
222         }
223         
224         public static WebElement getWebElementByClassName(String className) {
225                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
226                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
227         }
228         
229         public static WebElement getWebElementByLinkText(String linkText) {
230                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
231                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='" + linkText + "']")));
232         }
233         
234         
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 + "']")));
238         }
239         
240         public static List<WebElement> getWebElementsListByClassName(String className) {
241                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
242                 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
243         }
244         
245         
246
247
248         public static Boolean isElementInvisibleByTestId(String dataTestId) {
249                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
250                 return wait.until(
251                                 ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
252         }
253         
254         public static Boolean isElementVisibleByTestId(String dataTestId) {
255                 try{
256                         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
257                         if(wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//*[@data-tests-id='" + dataTestId + "']")))).isDisplayed()){
258                                 return true;
259                         }else {
260                                 return false;
261                         }
262                 }
263                 catch(Exception e){
264                         return false;
265                 }
266         }
267         
268         public static void clickOnElementByTestId(String dataTestId) {
269                 clickOnElementByTestIdWithoutWait(dataTestId);
270                 ultimateWait();
271         }
272
273         public static void clickOnElementByClassName(String className) {
274                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
275                 wait.until(ExpectedConditions.elementToBeClickable(By.className(className))).click();
276                 ultimateWait();
277         }
278
279         public static void clickOnElementById(String id) {
280                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
281                 wait.until(ExpectedConditions.elementToBeClickable(By.id(id))).click();
282                 ultimateWait();
283         }
284         
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();
288         }
289         
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();
293         }
294
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 + "']")));
298         }
299         
300         public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
301                 return waitForElementInVisibilityByTestId(dataTestId, timeOut);
302         }
303         
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();
307                 if (!displayed){
308                         Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + dataTestId + "'])")));
309                         ultimateWait();
310                         return until;
311                 }
312                 return false;
313         }
314         
315         public static Boolean waitForElementInVisibilityByTestId(By by) {
316                 return waitForElementInVisibilityBy(by, timeOut);
317         }
318         
319         
320         public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
321                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
322                 boolean displayed = getDriver().findElements(by).isEmpty();
323                 if (!displayed){
324                         Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
325                         sleep(1000);
326                         return until;
327                 }
328                 return false;
329         }
330         
331         
332         public static void setWebElementByTestId(String elemetID, String value) {
333                 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
334                 resourceDescriptionTextbox.clear();
335                 resourceDescriptionTextbox.sendKeys(value);
336                 
337         }
338         
339         public static WebElement hoverOnAreaByTestId(String areaId) {
340                 Actions actions = new Actions(getDriver());
341                 WebElement area = getWebElementByTestID(areaId);
342                 actions.moveToElement(area).perform();
343                 ultimateWait();
344                 return area;
345         }
346         
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();
352                 return area;
353         }
354         
355         public static void clickElementUsingActions(WebElement element){
356                 Actions actions = new Actions(getDriver());
357                 
358                 actions.moveToElement(element);
359                 actions.perform();
360                 
361                 actions.click();
362                 actions.perform();
363                 
364                 ultimateWait();
365         }
366         
367         public static void waitForLoader() {
368                 waitForLoader(timeOut);
369         }
370         
371         public static void waitForLoader(int timeOut) {
372                 sleep(500);
373                 waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
374         }
375         
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());
379                 try{
380                         searchTextbox.clear();
381                         searchTextbox.sendKeys(resourceName);
382                         ultimateWait();
383                 }
384                 catch(Exception e){
385                         SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
386                         e.printStackTrace();
387                 }
388                 
389                 
390                 try{
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());
395                 }
396                 catch(Exception e){
397                         SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
398                         e.printStackTrace();
399                 }
400         }
401         
402         
403         public static String getComponentVersion(String componentName) {
404                 return GeneralUIUtils.getWebElementByTestID(componentName + "Version").getText();
405         }
406         
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));
412                                 }
413                 }
414         }
415         
416         public static void resetZoom(){
417                 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
418         }
419         
420         public static void windowZoomOutUltimate(){
421                 resetZoom();
422                 windowZoomOut();
423 //              JavascriptExecutor js = (JavascriptExecutor) driver;
424 //              js.executeScript("document.body.style.zoom='90%'");
425         }
426         
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();
433         }
434         
435         public static void sleep(int duration) {
436                 try {
437                         Thread.sleep(duration);
438                 } catch (InterruptedException e) {
439                         throw new RuntimeException(e);
440                 }
441         }
442         
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());
446         }
447
448         public static void moveToStep(String dataTestId) {
449                 clickOnElementByTestId(dataTestId);
450                 ultimateWait();
451         }
452         
453         
454         public static Select getSelectList(String item, String datatestsid) {
455                 Select selectlist = new Select(getWebElementByTestID(datatestsid));
456                 if (item != null) {
457                         selectlist.selectByVisibleText(item);
458                 }
459                 return selectlist;
460         }       
461         
462         public static List<WebElement> waitForElementsListVisibilityTestMethod(DashboardCardEnum dataTestId) {
463                 GeneralUIUtils.waitForLoader();
464                 return getDriver().findElements(By.xpath("//*[@data-tests-id='" + dataTestId.getValue() + "']"));
465         }
466         
467     public static List<WebElement> getElementsByCSS(String cssString) throws InterruptedException {
468                 GeneralUIUtils.waitForLoader();
469                 List<WebElement> assets = getDriver().findElements(By.cssSelector(cssString));
470                 return assets;
471         }
472    
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));
477     }
478     
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() + "']")));
483     }
484     
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;");
488            return element;
489     } 
490     
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;
495     }
496     
497     
498     public static void waitForPageLoadByReadyState() {
499         new WebDriverWait(getDriver(), 30).until((ExpectedCondition<Boolean>) wd ->     
500                 ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
501     }
502     
503
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());
513                         sleep(napPeriodMS);
514                         sumOfWaiting += napPeriodMS;
515                         if (sumOfWaiting > maxWaitingPeriodMS)
516                                 return false;
517                 }
518                 return true;
519         }
520         
521         public static String getActionDuration(Runnable func) throws Exception{
522                 long startTime = System.nanoTime();
523                 func.run();
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;
528         }
529         
530     public static WebElement clickOnAreaJS(String areaId) {
531         return clickOnAreaJS(areaId, timeOut);
532     }
533     
534     
535     public static WebElement clickOnAreaJS(String areaId, int timeout) {
536         try{
537                 ultimateWait();
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);      
543                 return area;
544         }
545         catch (Exception e){
546                 e.printStackTrace();
547         }
548                 return null;
549     }
550
551     
552     
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;");
557         return areaId;
558     }
559     
560     
561     
562     public static void clickSomewhereOnPage() {
563         getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
564         }
565     
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);
571                 ultimateWait();
572                 clickOnElementByText(resourceName);
573                 ultimateWait();
574         }
575     
576         public static void clickOnElementByText(String textInElement) {
577                 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
578                 HighlightMyElement(wait.until(
579                                 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
580         }
581         
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();
586         }
587     
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))));
592         }
593         
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);
599
600                 fluentWait.until(ExpectedConditions.refreshed(
601                                 ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@data-tests-id='" + dataTestId + "']"), text)));
602     }    
603     
604     public static void regularWait(WebElement element, String text){
605         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
606
607                 wait.until(ExpectedConditions.textToBePresentInElementValue(element, text));
608     }
609     
610     public static void waitForAngular(){
611         WebDriverWait wait = new WebDriverWait(getDriver(), 90, 100);
612         wait.until(AdditionalConditions.pageLoadWait());
613         wait.until(AdditionalConditions.angularHasFinishedProcessing());
614     }
615     
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);
618         }
619     
620     public static boolean isElementReadOnly(WebElement element){
621         try {
622                 HighlightMyElement(element).clear();
623                         return false;
624                 } catch (Exception e) {
625                         return true;
626                 }       
627     }
628     
629     public static boolean isElementReadOnly(String dataTestId){
630         return isElementReadOnly(
631                         waitForElementVisibilityByTestId(dataTestId));
632     }
633     
634     public static boolean isElementDisabled(WebElement element){
635         return HighlightMyElement(element).getAttribute("class").contains("view-mode") || 
636                         element.getAttribute("class").contains("disabled");
637     }
638     
639     public static boolean isElementDisabled(String dataTestId){
640         return isElementDisabled(
641                         waitForElementVisibilityByTestId(dataTestId));
642     }
643     
644     public static void ultimateWait(){
645         long startTime = System.nanoTime();                    
646
647         GeneralUIUtils.waitForLoader();
648         GeneralUIUtils.waitForBackLoader();
649                 GeneralUIUtils.waitForAngular();
650                 
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));
656                 }
657 //              waitForUINotification();
658     }
659     
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);
663         return element;         
664     }
665     
666     public static WebElement unhideElement(WebElement element, String attributeValue){
667         String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
668         ((JavascriptExecutor) getDriver()).executeScript(js, element);
669         return element;         
670     }   
671          
672     public static WebElement findByText(String textInElement){
673         return getDriver().findElement(searchByTextContaining(textInElement));
674     }
675     public static By searchByTextContaining(String textInElement) {
676                 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
677         }
678     
679     
680     public static boolean findAndWaitByText(String textInElement, int timeout){
681         try{
682                 WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
683                 wait.until(ExpectedConditions.presenceOfElementLocated(searchByTextContaining(textInElement)));
684                 return true;
685         }
686         catch(Exception e){
687                 return false;
688         }
689     }
690     
691     public static WebElement getClickableButtonBy(By by, int timout){
692         try{
693                 WebDriverWait wait = new WebDriverWait(getDriver(), timout);
694                 WebElement element = wait.until(ExpectedConditions.elementToBeClickable(by));
695                 return element;
696         }
697         catch(Exception e){
698                 return null;
699         }
700     }
701     
702     
703     
704     public static WebElement getButtonWithText(String textInButton){
705         try{
706                 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
707         }
708         catch(Exception e)
709         {
710                 return null;
711         }
712     }
713     
714     
715     public static List<WebElement> getElementsByDataTestsIdStartWith(String startWithString){
716         ultimateWait();
717         return getDriver().findElements(By.xpath("//*[starts-with(@data-tests-id,'" + startWithString + "')]"));
718     }
719     
720         public static void closeErrorMessage() {
721                 WebElement okWebElement = getButtonWithText("OK");
722                 if (okWebElement != null){
723                         okWebElement.click();
724                         ultimateWait();
725                 }
726         }
727     
728     public static WebElement getElementByCSS(String cssString) throws InterruptedException {
729                 ultimateWait();
730                 return getDriver().findElement(By.cssSelector(cssString));
731         }
732     
733     public static String getDataTestIdAttributeValue(WebElement element) {
734                 return element.getAttribute("data-tests-id");
735         }
736     
737     public static String getTextContentAttributeValue(WebElement element) {
738                 return element.getAttribute("textContent");
739         }
740     
741     public static WebElement getElementInsideElementByDataTestsId(WebElement element, String dataTestId) {
742         try{
743                 return element.findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
744         }
745         catch(Exception e){
746                 return null;
747         }
748         }
749     
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();
753                 ultimateWait();
754         }
755         public static String getRandomComponentName(String prefix) {
756                 return prefix + GeneralUIUtils.randomNumber();
757         }
758         public static int randomNumber() {
759                 Random r = new Random();
760                 return r.nextInt(10000);
761         }
762         
763         public static void waitForUINotification() {
764                 List<WebElement> notificationElements = getDriver().findElements(By.className("ui-notification"));
765                 if (!notificationElements.isEmpty()){
766                         notificationElements.forEach(WebElement::click);
767                 }
768         }
769         
770         public static boolean checkForDisabledAttribute(String  dataTestId){
771                 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
772                 return elementAttributes.toString().contains("disabled");
773         }
774         
775         public static void dragAndDropElementByY(WebElement area, int yOffset) {
776                 Actions actions = new Actions(getDriver());
777                 actions.dragAndDropBy(area, 10, yOffset).perform();
778                 ultimateWait();
779         }
780         
781         public static void waitForBackLoader() {
782                 waitForBackLoader(timeOut);
783         }
784         
785         public static void waitForBackLoader(int timeOut) {
786                 sleep(100);
787                 waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);
788         }
789         
790         public static void addStringtoClipboard(String text){
791                 StringSelection selection = new StringSelection(text);
792             Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
793             clipboard.setContents(selection, selection);
794         }
795         
796         public static boolean checkForDisabledAttributeInHiddenElement(String  cssString){
797                 Object elementAttributes = getAllElementAttributes(getDriver().findElement(By.cssSelector(cssString)));
798                 return elementAttributes.toString().contains("disabled");
799         }
800
801         public static void setTextInElementByDataTestID(String dataTestsID, String text)
802         {
803                 WebElement webElement = GeneralUIUtils.getWebElementByTestID(dataTestsID);
804                 webElement.clear();
805                 webElement.sendKeys(text);
806                 ultimateWait();
807         }
808
809         public static void selectByValueTextContained(String dataTestsId, String value) {
810
811                 List<WebElement> options = GeneralUIUtils.getWebElementsListBy(By.xpath(String.format("//select[@data-tests-id='%s']//option[contains(@value,'%s')]",dataTestsId,value)));
812
813                 boolean matched = false;
814                 for (WebElement option : options) {
815                         option.click();
816                         matched = true;
817                 }
818
819                 if (!matched) {
820                         throw new NoSuchElementException("Cannot locate option with value: " + value);
821                 }
822
823                 ultimateWait();
824         }
825
826         public static void setTextInElementByXpath(String xPath, String text)
827         {
828                 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
829                 webElement.clear();
830                 webElement.click();
831                 webElement.sendKeys(text);
832                 ultimateWait();
833         }
834
835         public static String getTextValueFromInput(WebElement webElement)
836         {
837                 return webElement.getAttribute("value");
838         }
839
840         public static String getTextValueFromWebElementByXpath(String Xpath)
841         {
842                 WebElement webElement = getWebElementBy(By.xpath(Xpath));
843                 return webElement.getAttribute("value");
844         }
845         
846         public static void refreshPage(){
847                 Actions actions = new Actions(getDriver());
848                 actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();
849         }
850
851
852
853
854     
855 }