aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/sections/InstantiationStatusPage.java
blob: e5dd1bb39c2681b1ed692d01804cb23d197308cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package vid.automation.test.sections;

import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import vid.automation.test.infra.Get;

import java.util.Map;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public abstract class InstantiationStatusPage extends VidBasePage {

    public static final String refreshButtonId = "refresh-btn";

    public static String getWebTrTdSpanElementByParentID(WebElement tr, String id, int timeout) {
            return tr.findElements(By.xpath(".//*[@id='" + id + "']//span")).get(0).getText();
    }

    public static int getNumberOfTableRows(int timeout){
        WebDriverWait wait = waitUntilDriverIsReady(timeout);
        return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[table]//tbody/tr"))).size();
    }

    public static WebElement assertInstantiationStatusRow(String spanIdSelector, Map<String, String> fieldsIdsAndExpected) {
        try {
            WebElement newTrRow = getInstantiationStatusRow(spanIdSelector);
            final Map<String, String> fieldIdAndActual = fieldsIdsAndExpected.entrySet().stream()
                    .collect(Collectors.toMap(
                            kv -> kv.getKey(),
                            kv -> getWebTrTdSpanElementByParentID(newTrRow, kv.getKey(), 1)
                    ));

            assertThat("failed comparing spanIdSelector " + spanIdSelector, fieldIdAndActual, is(fieldsIdsAndExpected));

            return newTrRow;
        } catch (Exception e) {
            throw new RuntimeException("error while assertInstantiationStatusRow with: String spanIdSelector=" +
                    spanIdSelector + ", fieldsIdsAndExpected=" + fieldsIdsAndExpected, e);
        }
    }

    public static WebElement getInstantiationStatusRow(String spanIdSelector) {
        GeneralUIUtils.ultimateWait();
        return Get.byXpath("//*[@id='" + spanIdSelector + "']/parent::*/parent::*/parent::*", 0);
    }

    public static void clickRefreshButton() {
        WebDriverWait wait = waitUntilDriverIsReady(0);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='"+ refreshButtonId + "']"))).click();
        GeneralUIUtils.ultimateWait();
    }


}