aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/sections/SideMenu.java
blob: 0ba49f2d8fc53a85e7c3f85765916ebf5df4041a (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
60
61
62
63
64
65
66
67
68
69
70
71
72
package vid.automation.test.sections;

import org.junit.Assert;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.ElementClickInterceptedException;
import org.openqa.selenium.UnhandledAlertException;
import vid.automation.test.Constants;

public class SideMenu {
    public static void navigateToBrowseASDCPage() {
        navigateToPage(Constants.SideMenu.BROWSE_ASDC_SERVICE_MODELS);
    }

    public static void navigateToSearchExistingPage() {
        navigateToPage(Constants.SideMenu.SEARCH_EXISTING_SERVICE);
    }

    public static void navigateToCreateNewServicePage() {
        navigateToPage(Constants.SideMenu.CREATE_NEW_SERVICE);
    }

    public static void navigateToTestEnvironmentsPage() {
        navigateToPage(Constants.SideMenu.TEST_ENVIRONMENTS);
    }

    public static void navigateToMacroInstantiationStatus() {
        navigateToPage("Macro Instantiation Status");
        new VidBasePage().goToIframe();
    }

    private static void navigateToPage(String PageName) {

        boolean findAndWaitByText = GeneralUIUtils.findAndWaitByText(PageName, 30);

        if (!findAndWaitByText) {
            doEvenIfAlertIsShown(SideMenu::navigateToWelcomePage);
            findAndWaitByText = GeneralUIUtils.findAndWaitByText(PageName, 10);
        }

        Assert.assertTrue(findAndWaitByText);
        doEvenIfAlertIsShown(() -> {
            try {
                GeneralUIUtils.clickOnElementByText(PageName, 50);
            } catch (ElementClickInterceptedException e) {
                navigateToWelcomePage();
                GeneralUIUtils.clickOnElementByText(PageName, 100);
            }
        });
        GeneralUIUtils.ultimateWait();
    }

    public static void navigateToWelcomePage() {
        doEvenIfAlertIsShown(() -> {
            VidBasePage base = new VidBasePage();
            base.navigateTo("welcome.htm");
        });
    }

    private static void doEvenIfAlertIsShown(Runnable runnable) {
        try {
            runnable.run();
        } catch (UnhandledAlertException e) {
            // an alert popup was shown; dismiss it if it's still there
            try {
                GeneralUIUtils.getDriver().switchTo().alert().dismiss();
            } catch (org.openqa.selenium.NoAlertPresentException e2) {
                // YOLO
            }
            runnable.run();
        }
    }
}