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!");
}
}
Aggregations