re base code
[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.DataTestIdEnum;
26 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
27 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.openecomp.sdc.ci.tests.utils.Utils;
29 import org.openqa.selenium.*;
30 import org.openqa.selenium.firefox.FirefoxDriver;
31 import org.openqa.selenium.interactions.Actions;
32 import org.openqa.selenium.support.ui.ExpectedConditions;
33 import org.openqa.selenium.support.ui.Select;
34 import org.openqa.selenium.support.ui.WebDriverWait;
35
36 import java.awt.*;
37 import java.awt.datatransfer.Clipboard;
38 import java.awt.datatransfer.StringSelection;
39 import java.io.File;
40 import java.io.IOException;
41 import java.util.ArrayList;
42 import java.util.List;
43 import java.util.UUID;
44 import java.util.concurrent.TimeUnit;
45 import java.util.function.Supplier;
46
47 import static org.testng.AssertJUnit.assertTrue;
48
49
50 public final class GeneralUIUtils {
51
52     private static final String DATA_TESTS_ID = "//*[@data-tests-id='";
53     private static final String COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW = "color: yellow; border: 4px solid yellow;";
54
55     private static int timeOut = (int) (60 * 1.5);
56
57     public static int getTimeOut() {
58         return timeOut;
59     }
60
61     /**************** DRIVER ****************/
62
63     public static WebDriver getDriver() {
64         try {
65             return DriverFactory.getDriver();
66         } catch (Exception e) {
67             e.printStackTrace();
68         }
69         return null;
70     }
71
72     /****************************************/
73
74     public static List<WebElement> getElemenetsFromTable(By by) {
75         return getDriver().findElements(by);
76     }
77
78     public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
79         if (screenshotFilename == null) {
80             if (testName != null) {
81                 screenshotFilename = testName;
82             } else {
83                 screenshotFilename = UUID.randomUUID().toString();
84             }
85         }
86         try {
87             File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
88             File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
89             new File(dir).mkdirs();
90             FileUtils.copyFile(scrFile, filePath);
91             return filePath;
92         } catch (IOException e1) {
93             e1.printStackTrace();
94         }
95         return null;
96     }
97
98     public static File takeScreenshot(String screenshotFilename, String dir) throws IOException {
99         return takeScreenshot(screenshotFilename, dir, null);
100     }
101
102     public static WebElement getWebElementByTestID(String dataTestId) {
103         return getWebElementByTestID(dataTestId, timeOut);
104     }
105
106     public static WebElement getWebElementByTestID(String dataTestId, int timeout) {
107         WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
108         return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(DATA_TESTS_ID + dataTestId + "']")));
109     }
110
111     public static boolean isWebElementExistByTestId(String dataTestId) {
112         return getDriver().findElements(By.xpath(DATA_TESTS_ID + dataTestId + "']")).size() != 0;
113     }
114
115     public static boolean isWebElementExistByClass(String className) {
116         return getDriver().findElements(By.className(className)).size() != 0;
117     }
118
119     public static WebElement getInputElement(String dataTestId) {
120         try {
121             ultimateWait();
122             return getDriver().findElement(By.xpath(DATA_TESTS_ID + dataTestId + "']"));
123         } catch (Exception e) {
124             return null;
125         }
126     }
127
128     public static List<WebElement> getInputElements(String dataTestId) {
129         ultimateWait();
130         return getDriver().findElements(By.xpath(DATA_TESTS_ID + dataTestId + "']"));
131
132     }
133
134     public static WebElement getWebElementBy(By by) {
135         return getWebElementBy(by, timeOut);
136     }
137
138     public static WebElement getWebElementBy(By by, int timeOut) {
139         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
140         return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
141     }
142
143     public static WebElement getWebElementByPresence(By by, int timeOut) {
144         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
145         return wait.until(ExpectedConditions.presenceOfElementLocated(by));
146     }
147
148     public static List<String> getWebElementListText(List<WebElement> elements) {
149         List<String> Text = new ArrayList<>();
150         for (WebElement webElement : elements) {
151             Text.add(webElement.getText());
152         }
153         return Text;
154     }
155
156     public static List<WebElement> getWebElementsListBy(By by) {
157         return getWebElementsListBy(by, timeOut);
158     }
159
160     public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
161         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
162         return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
163     }
164
165     public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
166         try {
167             WebDriverWait wait = new WebDriverWait(getDriver(), 10);
168             return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@data-tests-id, '" + dataTestId + "')]")));
169         } catch (Exception e) {
170             return new ArrayList<WebElement>();
171         }
172     }
173
174     public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
175         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
176         return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '" + containedText + "')]")));
177     }
178
179     public static WebElement getWebElementByContainsClassName(String containedText) {
180         return getWebElementBy(By.xpath("//*[contains(@class, '" + containedText + "')]"));
181     }
182
183     public static WebElement getWebElementByClassName(String className) {
184         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
185         return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
186     }
187
188     public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
189         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
190         return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(DATA_TESTS_ID + dataTestId + "']")));
191     }
192
193     public static List<WebElement> getWebElementsListByClassName(String className) {
194         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
195         return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
196     }
197
198
199     public static Boolean isElementInvisibleByTestId(String dataTestId) {
200         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
201         return wait.until(
202                 ExpectedConditions.invisibilityOfElementLocated(By.xpath(DATA_TESTS_ID + dataTestId + "']")));
203     }
204
205     public static Boolean isElementVisibleByTestId(String dataTestId) {
206         try {
207             WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
208             return wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath(DATA_TESTS_ID + dataTestId + "']")))).isDisplayed();
209         } catch (Exception e) {
210             return false;
211         }
212     }
213
214     public static void clickOnElementByTestId(String dataTestId) {
215         clickOnElementByTestIdWithoutWait(dataTestId);
216         ultimateWait();
217     }
218
219     public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
220         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
221         wait.until(ExpectedConditions.elementToBeClickable(By.xpath(DATA_TESTS_ID + dataTestId + "']"))).click();
222     }
223
224     public static void clickOnElementByInputTestIdWithoutWait(String dataTestId) {
225         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
226         wait.until(ExpectedConditions.elementToBeClickable(By.xpath(DATA_TESTS_ID + dataTestId + "']//*"))).click();
227     }
228
229     public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
230         WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
231         wait.until(ExpectedConditions.elementToBeClickable(By.xpath(DATA_TESTS_ID + dataTestId + "']"))).click();
232     }
233
234     public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
235         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
236         return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(DATA_TESTS_ID + dataTestId + "']")));
237     }
238
239     public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
240         return waitForElementInVisibilityByTestId(dataTestId, timeOut);
241     }
242
243     public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
244         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
245         boolean displayed = getDriver().findElements(By.xpath(DATA_TESTS_ID + dataTestId + "']")).isEmpty();
246         if (!displayed) {
247             Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(DATA_TESTS_ID + dataTestId + "'])")));
248             ultimateWait();
249             return until;
250         }
251         return false;
252     }
253
254     public static Boolean waitForElementInVisibilityByTestId(By by) {
255         return waitForElementInVisibilityBy(by, timeOut);
256     }
257
258
259     public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
260         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
261         boolean displayed = getDriver().findElements(by).isEmpty();
262         if (!displayed) {
263             Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
264             sleep(1000);
265             return until;
266         }
267         return false;
268     }
269
270
271     public static void setWebElementByTestId(String elemetID, String value) {
272         WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
273         resourceDescriptionTextbox.clear();
274         resourceDescriptionTextbox.sendKeys(value);
275
276     }
277
278     public static WebElement hoverOnAreaByTestId(String areaId) {
279         Actions actions = new Actions(getDriver());
280         WebElement area = getWebElementByTestID(areaId);
281         actions.moveToElement(area).perform();
282         ultimateWait();
283         return area;
284     }
285
286     public static WebElement hoverOnAreaByClassName(String className) {
287         Actions actions = new Actions(getDriver());
288         WebElement area = getWebElementByClassName(className);
289         actions.moveToElement(area).perform();
290         GeneralUIUtils.ultimateWait();
291         return area;
292     }
293
294     public static void waitForLoader() {
295         waitForLoader(timeOut);
296     }
297
298     public static void waitForLoader(int timeOut) {
299         sleep(500);
300         waitForElementInVisibilityBy(By.className("tlv-loader"), timeOut);
301     }
302
303     public static void findComponentAndClick(String resourceName) throws Exception {
304         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in homepage");
305         WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
306         try {
307             searchTextbox.clear();
308             searchTextbox.sendKeys(resourceName);
309             ultimateWait();
310         } catch (Exception e) {
311             SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
312             e.printStackTrace();
313         }
314
315         try {
316             SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component from home screen", resourceName));
317             clickOnElementByTestId(resourceName);
318             getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
319         } catch (Exception e) {
320             SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
321             e.printStackTrace();
322         }
323     }
324
325     public static void windowZoomOut() {
326         final int zoomOutFactor = 3;
327         for (int i = 0; i < zoomOutFactor; i++) {
328             if (getDriver() instanceof FirefoxDriver) {
329                 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
330             }
331         }
332     }
333
334     public static void resetZoom() {
335         getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
336     }
337
338     public static void windowZoomOutUltimate() {
339         resetZoom();
340         windowZoomOut();
341     }
342
343     public static void sleep(int duration) {
344         try {
345             Thread.sleep(duration);
346         } catch (InterruptedException e) {
347             throw new RuntimeException(e);
348         }
349     }
350
351     public static void moveToStep(DataTestIdEnum.StepsEnum stepName) {
352         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to %s page ", stepName.toString()));
353         moveToStep(stepName.getValue());
354     }
355
356     public static void moveToStep(String dataTestId) {
357         clickOnElementByTestId(dataTestId);
358     }
359
360
361     public static Select getSelectList(String item, String datatestsid) {
362         Select selectList = new Select(getWebElementByTestID(datatestsid));
363         if (item != null) {
364             selectList.selectByVisibleText(item);
365         }
366         return selectList;
367     }
368
369     public static List<WebElement> getElementsByCSS(String cssString) /*throws InterruptedException*/ {
370         GeneralUIUtils.waitForLoader();
371         return getDriver().findElements(By.cssSelector(cssString));
372     }
373
374     public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString) {
375         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
376         GeneralUIUtils.waitForLoader();
377         return parentElement.findElement(By.cssSelector(cssString));
378     }
379
380     public static WebElement HighlightMyElement(WebElement element) {
381         JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
382         javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
383         return element;
384     }
385
386     public static WebElement getSelectedElementFromDropDown(String dataTestId) {
387         GeneralUIUtils.ultimateWait();
388         return new Select(getDriver().findElement(By.xpath(DATA_TESTS_ID + dataTestId + "']"))).getFirstSelectedOption();
389     }
390
391     public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
392         int maxWaitingPeriodMS = 10 * 1000;
393         int napPeriodMS = 100;
394         int sumOfWaiting = 0;
395         List<WebElement> elements = null;
396         boolean isKeepWaiting = false;
397         while (!isKeepWaiting) {
398             elements = func.get();
399             isKeepWaiting = (expectedElementsCount == elements.size());
400             sleep(napPeriodMS);
401             sumOfWaiting += napPeriodMS;
402             if (sumOfWaiting > maxWaitingPeriodMS)
403                 return false;
404         }
405         return true;
406     }
407
408     public static String getActionDuration(Runnable func) throws Exception {
409         long startTime = System.nanoTime();
410         func.run();
411         long estimateTime = System.nanoTime();
412         long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
413         String durationString = String.format("%02d:%02d", duration / 60, duration % 60);
414         return durationString;
415     }
416
417     public static WebElement clickOnAreaJS(String areaId) {
418         return clickOnAreaJS(areaId, timeOut);
419     }
420
421
422     public static WebElement clickOnAreaJS(String areaId, int timeout) {
423         try {
424             ultimateWait();
425             WebElement area = getWebElementByTestID(areaId);
426             JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
427             //HighlightMyElement(area);
428             Object executeScript = javascript.executeScript("arguments[0].click();", area, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
429             waitForLoader(timeout);
430             ultimateWait();
431             return area;
432         } catch (Exception e) {
433             e.printStackTrace();
434         }
435         return null;
436     }
437
438
439     public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
440         JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
441         //HighlightMyElement(area);
442         javascript.executeScript("arguments[0].click();", areaId, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
443         return areaId;
444     }
445
446
447     public static void clickSomewhereOnPage() {
448         getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
449     }
450
451     public static void clickOnElementByText(String textInElement) {
452         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
453         HighlightMyElement(wait.until(
454                 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
455     }
456
457     public static void clickOnElementByText(String textInElement, int customTimeout) {
458         WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
459         HighlightMyElement(wait.until(
460                 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
461     }
462
463     public static void clickJSOnElementByText(String textInElement) throws Exception {
464         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
465         clickOnAreaJS(wait.until(
466                 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
467     }
468
469     public static void waitForAngular() {
470         WebDriverWait wait = new WebDriverWait(getDriver(), 90, 100);
471         wait.until(AdditionalConditions.pageLoadWait());
472         wait.until(AdditionalConditions.angularHasFinishedProcessing());
473     }
474
475     public static Object getAllElementAttributes(WebElement element) {
476         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);
477     }
478
479     public static boolean isElementReadOnly(WebElement element) {
480         try {
481             HighlightMyElement(element).clear();
482             return false;
483         } catch (Exception e) {
484             return true;
485         }
486     }
487
488     public static boolean isElementReadOnly(String dataTestId) {
489         return isElementReadOnly(
490                 waitForElementVisibilityByTestId(dataTestId));
491     }
492
493     public static boolean isElementDisabled(WebElement element) {
494         return HighlightMyElement(element).getAttribute("class").contains("view-mode") ||
495                 element.getAttribute("class").contains("disabled");
496     }
497
498     public static boolean isElementDisabled(String dataTestId) {
499         return isElementDisabled(
500                 waitForElementVisibilityByTestId(dataTestId));
501     }
502
503     public static void ultimateWait() {
504         long startTime = System.nanoTime();
505
506         GeneralUIUtils.waitForLoader();
507         GeneralUIUtils.waitForBackLoader();
508         GeneralUIUtils.waitForAngular();
509
510         long estimateTime = System.nanoTime();
511         long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
512         if (duration > timeOut) {
513             SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
514         }
515     }
516
517     public static WebElement unhideElement(WebElement element, String attributeValue) {
518         String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
519         ((JavascriptExecutor) getDriver()).executeScript(js, element);
520         return element;
521     }
522
523     public static WebElement findByText(String textInElement) {
524         return getDriver().findElement(searchByTextContaining(textInElement));
525     }
526
527     public static By searchByTextContaining(String textInElement) {
528         return By.xpath("//*[contains(text(),'" + textInElement + "')]");
529     }
530
531     public static WebElement getClickableButtonBy(By by, int timout) {
532         try {
533             WebDriverWait wait = new WebDriverWait(getDriver(), timout);
534             return wait.until(ExpectedConditions.elementToBeClickable(by));
535         } catch (Exception e) {
536             return null;
537         }
538     }
539
540
541     public static WebElement getButtonWithText(String textInButton) {
542         try {
543             return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
544         } catch (Exception e) {
545             return null;
546         }
547     }
548
549     public static void closeErrorMessage() {
550         WebElement okWebElement = getButtonWithText("OK");
551         if (okWebElement != null) {
552             okWebElement.click();
553             ultimateWait();
554         }
555     }
556
557     public static WebElement getElementByCSS(String cssString) throws InterruptedException {
558         ultimateWait();
559         return getDriver().findElement(By.cssSelector(cssString));
560     }
561
562     public static String getDataTestIdAttributeValue(WebElement element) {
563         return element.getAttribute("data-tests-id");
564     }
565
566     public static String getTextContentAttributeValue(WebElement element) {
567         return element.getAttribute("textContent");
568     }
569
570     public static void clickOnElementByCSS(String cssString) throws Exception {
571         WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
572         wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
573         ultimateWait();
574     }
575
576     public static boolean checkForDisabledAttribute(String dataTestId) {
577         Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
578         return elementAttributes.toString().contains("disabled");
579     }
580
581     public static void dragAndDropElementByY(WebElement area, int yOffset) {
582         Actions actions = new Actions(getDriver());
583         actions.dragAndDropBy(area, 10, yOffset).perform();
584         ultimateWait();
585     }
586
587     public static void waitForBackLoader() {
588         waitForBackLoader(timeOut);
589     }
590
591     public static void waitForBackLoader(int timeOut) {
592         sleep(100);
593         waitForElementInVisibilityBy(By.className("tlv-loader-back"), timeOut);
594     }
595
596     public static void addStringtoClipboard(String text) {
597         StringSelection selection = new StringSelection(text);
598         Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
599         clipboard.setContents(selection, selection);
600     }
601
602     public static boolean checkForDisabledAttributeInHiddenElement(String cssString) {
603         boolean isDisabled = false;
604         for (int i = 0; i < 3; i++) {
605             Object elementAttributes = getAllElementAttributes(getWebElementByPresence(By.cssSelector(cssString), timeOut));
606             isDisabled = elementAttributes.toString().contains("disabled");
607             if (isDisabled)
608                 break;
609             ultimateWait();
610         }
611         return isDisabled;
612     }
613
614     public static void selectByValueTextContained(String dataTestsId, String value) {
615
616         List<WebElement> options = GeneralUIUtils.getWebElementsListBy(By.xpath(String.format("//select[@data-tests-id='%s']//option[contains(@value,'%s')]", dataTestsId, value)));
617
618         boolean matched = false;
619         for (WebElement option : options) {
620             option.click();
621             matched = true;
622         }
623
624         if (!matched) {
625             throw new NoSuchElementException("Cannot locate option with value: " + value);
626         }
627
628         ultimateWait();
629     }
630
631     public static void setTextInElementByXpath(String xPath, String text) {
632         WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
633         webElement.clear();
634         webElement.click();
635         webElement.sendKeys(text);
636         ultimateWait();
637     }
638
639
640     public static void clickOnElementByXpath(String xPath) {
641         WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
642         webElement.click();
643         ultimateWait();
644     }
645
646     public static String getTextValueFromWebElementByXpath(String Xpath) {
647         WebElement webElement = getWebElementBy(By.xpath(Xpath));
648         return webElement.getAttribute("value");
649     }
650
651     public static List<WebElement> findElementsByXpath(String xPath) {
652         return getDriver().findElements(By.xpath(xPath));
653     }
654
655     public static void clickOnBrowserBackButton() throws Exception {
656         SetupCDTest.getExtendTest().log(Status.INFO, "Going to press on back browser button.");
657         getDriver().navigate().back();
658         ultimateWait();
659     }
660
661     public static String copyCurrentURL() throws Exception {
662         SetupCDTest.getExtendTest().log(Status.INFO, "Copying current URL");
663         return getDriver().getCurrentUrl();
664     }
665
666     public static void navigateToURL(String url) throws Exception {
667         SetupCDTest.getExtendTest().log(Status.INFO, "Navigating to URL " + url);
668         getDriver().navigate().to(url);
669     }
670
671     public static Object getElementPositionOnCanvas(String elementName) {
672         String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n" +
673                 "var n = cy.nodes('[name=\"" + elementName + "\"]');\n" +
674                 "var nPos = n.renderedPosition();\n" +
675                 "return JSON.stringify({\n" +
676                 "\tx: nPos.x,\n" +
677                 "\ty: nPos.y\n" +
678                 "})";
679         return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
680     }
681
682     public static Object getElementGreenDotPositionOnCanvas(String elementName) {
683         String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n" +
684                 "var cyZoom = cy.zoom();\n" +
685                 "var n = cy.nodes('[name=\"" + elementName + "\"]');\n" +
686                 "var nPos = n.renderedPosition();\n" +
687                 "var nData = n.data();\n" +
688                 "var nImgSize = nData.imgWidth;\n" +
689                 "var shiftSize = (nImgSize-18)*cyZoom/2;\n" +
690                 "return JSON.stringify({\n" +
691                 "\tx: nPos.x + shiftSize,\n" +
692                 "\ty: nPos.y - shiftSize\n" +
693                 "});";
694         return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
695         }
696
697         public static Long getAndValidateActionDuration (Runnable action, int regularTestRunTime){
698                 Long actualTestRunTime = null;
699                 try {
700                         actualTestRunTime = Utils.getActionDuration(() -> {
701                                 try {
702                                         action.run();
703                                 } catch (Throwable throwable) {
704                                         throwable.printStackTrace();
705                                 }
706                         });
707                 } catch (Exception e) {
708                         e.printStackTrace();
709                 }
710                 double factor = 1.5;
711
712                 assertTrue("Expected test run time should be less than " + regularTestRunTime*factor + ", " +
713                                 "actual time is " + actualTestRunTime , regularTestRunTime*factor>actualTestRunTime);
714 //              SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is  " + actualTestRunTime + " seconds");
715                 return actualTestRunTime;
716     }
717 }