Search in sources :

Example 1 with JavascriptException

use of org.openqa.selenium.JavascriptException in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class DataLayerIT method testDataLayerInitialized.

@Test
public void testDataLayerInitialized() throws InterruptedException {
    editorPage.enterPreviewMode();
    Commons.switchContext("ContentFrame");
    final WebDriver webDriver = WebDriverRunner.getWebDriver();
    Object adobeDataLayer = ((JavascriptExecutor) webDriver).executeScript("return window.adobeDataLayer;");
    assertNotNull(adobeDataLayer, "adobeDataLayer is undefined!");
    try {
        // check if adobeDataLayer is initialized i.e. getState() function is defined
        Object state = ((JavascriptExecutor) webDriver).executeScript("return window.adobeDataLayer.getState();");
        // check if returned state object is not empty
        assertNotNull(state, "adobeDataLayer.getState(): returned state object is null!");
        Map<?, ?> stateMap = (Map) (state);
        // check some basic properties of the state object
        assertNotNull(stateMap.get("page"), "returned State is missing 'page' property!");
        assertNotNull(stateMap.get("component"), "returned State is missing 'component' property!");
        Map<?, ?> components = (Map) stateMap.get("component");
        assertEquals(2, components.size(), "returned state.components should have 2 entries!");
    } catch (JavascriptException e) {
        // this would return 'window.adobeDataLayer.getState() is not a function'
        fail(e);
    } catch (ClassCastException e) {
        fail("returned State object is not properly initialized!");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) JavascriptException(org.openqa.selenium.JavascriptException) Map(java.util.Map) Test(org.junit.jupiter.api.Test) AdminBaseUITest(com.adobe.cq.wcm.core.components.it.seljup.AdminBaseUITest)

Aggregations

AdminBaseUITest (com.adobe.cq.wcm.core.components.it.seljup.AdminBaseUITest)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 JavascriptException (org.openqa.selenium.JavascriptException)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebDriver (org.openqa.selenium.WebDriver)1