vid-automation selenium tests
[vid.git] / vid-automation / src / main / java / vid / automation / test / sections / InstantiationStatusPage.java
1 package vid.automation.test.sections;
2
3 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
4 import org.openqa.selenium.By;
5 import org.openqa.selenium.WebElement;
6 import org.openqa.selenium.support.ui.ExpectedConditions;
7 import org.openqa.selenium.support.ui.WebDriverWait;
8 import vid.automation.test.infra.Get;
9
10 import java.util.Map;
11 import java.util.stream.Collectors;
12
13 import static org.hamcrest.CoreMatchers.is;
14 import static org.hamcrest.MatcherAssert.assertThat;
15
16 public abstract class InstantiationStatusPage extends VidBasePage {
17
18     public static final String refreshButtonId = "refresh-btn";
19
20     public static String getWebTrTdSpanElementByParentID(WebElement tr, String id, int timeout) {
21             return tr.findElements(By.xpath(".//*[@id='" + id + "']//span")).get(0).getText();
22     }
23
24     public static int getNumberOfTableRows(int timeout){
25         WebDriverWait wait = waitUntilDriverIsReady(timeout);
26         return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[table]//tbody/tr"))).size();
27     }
28
29     public static WebElement assertInstantiationStatusRow(String spanIdSelector, Map<String, String> fieldsIdsAndExpected) {
30         try {
31             WebElement newTrRow = getInstantiationStatusRow(spanIdSelector);
32             final Map<String, String> fieldIdAndActual = fieldsIdsAndExpected.entrySet().stream()
33                     .collect(Collectors.toMap(
34                             kv -> kv.getKey(),
35                             kv -> getWebTrTdSpanElementByParentID(newTrRow, kv.getKey(), 1)
36                     ));
37
38             assertThat("failed comparing spanIdSelector " + spanIdSelector, fieldIdAndActual, is(fieldsIdsAndExpected));
39
40             return newTrRow;
41         } catch (Exception e) {
42             throw new RuntimeException("error while assertInstantiationStatusRow with: String spanIdSelector=" +
43                     spanIdSelector + ", fieldsIdsAndExpected=" + fieldsIdsAndExpected, e);
44         }
45     }
46
47     public static WebElement getInstantiationStatusRow(String spanIdSelector) {
48         GeneralUIUtils.ultimateWait();
49         return Get.byXpath("//*[@id='" + spanIdSelector + "']/parent::*/parent::*/parent::*", 0);
50     }
51
52     public static void clickRefreshButton() {
53         WebDriverWait wait = waitUntilDriverIsReady(0);
54         wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='"+ refreshButtonId + "']"))).click();
55         GeneralUIUtils.ultimateWait();
56     }
57
58
59 }