diff --git a/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java b/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java index dc242d840..267aa3f23 100644 --- a/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java +++ b/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java @@ -207,7 +207,7 @@ public enum MessageEventEnum { ACTION_SUCCESS_GETPAGESOURCE(200, "OK", "Page Source has been recorded.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), ACTION_SUCCESS_MOUSEDOWN(200, "OK", "Mouse Left Click pressed on Element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), ACTION_SUCCESS_MOUSEUP(200, "OK", "Mouse Left Click Released on Element '%ELEMENT%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), - ACTION_SUCCESS_SWITCHTOWINDOW(200, "OK", "Focus of Selenium was changed to Window '%WINDOW%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), + ACTION_SUCCESS_SWITCHTOWINDOW(200, "OK", "Focus of Selenium was changed to Window '%WINDOW%'. Initial window '%INITIALCONTEXT%'. All contexts available : '%ALLCONTEXTS%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), ACTION_SUCCESS_SWITCHTOCONTEXT(200, "OK", "Context was successfully changed to %CONTEXT%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), ACTION_SUCCESS_CLOSE_ALERT(200, "OK", "Alert popup is closed !", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), ACTION_SUCCESS_KEYPRESS_ALERT(200, "OK", "Keypress '%KEY%' done on alert popup !", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), @@ -301,7 +301,7 @@ public enum MessageEventEnum { ACTION_FAILED_SELECT_REGEX_INVALIDPATTERN(281, "FA", "Pattern '%PATTERN%' is not valid. Detailed error : %ERROR%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_MOUSEUP_NO_SUCH_ELEMENT(282, "FA", "Failed to release click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_MOUSEDOWN_NO_SUCH_ELEMENT(283, "FA", "Failed to left click because could not find element '%ELEMENT%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), - ACTION_FAILED_SWITCHTOWINDOW_NO_SUCH_ELEMENT(280, "FA", "Failed to switch to window because could not find element '%WINDOW%'!", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), + ACTION_FAILED_SWITCHTOWINDOW_NO_SUCH_ELEMENT(280, "FA", "Failed to switch to window because could not find element '%WINDOW%'! Initial window '%INITIALCONTEXT%'. All contexts available : '%ALLCONTEXTS%'", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_SWITCHTOCONTEXT_NO_SUCH_ELEMENT(280, "FA", "Failed to switch to context '%CONTEXT%' because could not find it! Available contexts are: '%CONTEXTS%'. Detailed error: %ERROR%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_CLOSE_ALERT(280, "FA", "Failed to close the alert popup ! Please either specify 'ok' or 'cancel'.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_KEYPRESS_ALERT(280, "FA", "Failed to keypress '%KEY%' on the alert popup !", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), diff --git a/source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java b/source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java index 30dfb86af..99609a830 100644 --- a/source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java +++ b/source/src/main/java/org/cerberus/core/service/webdriver/impl/WebDriverService.java @@ -1036,6 +1036,7 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i String windowTitle = identifier.getLocator(); String currentHandle; + Set handles = new HashSet(); // Current serial handle of the window. // Add try catch to handle not exist anymore window (like when popup is closed). try { @@ -1047,7 +1048,7 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i try { // Get serials handles list of all browser windows - Set handles = session.getDriver().getWindowHandles(); + handles = session.getDriver().getWindowHandles(); // Loop into each of them for (String windowHandle : handles) { @@ -1055,7 +1056,10 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i session.getDriver().switchTo().window(windowHandle); if (checkIfExpectedWindow(session, identifier.getIdentifier(), identifier.getLocator())) { message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOWINDOW); - message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle)); + message.setDescription(message.getDescription() + .replace("%WINDOW%", windowTitle) + .replace("%INITIALCONTEXT%", currentHandle) + .replace("%ALLCONTEXTS%", String.join("-", handles))); return message; } } @@ -1076,7 +1080,10 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i return parseWebDriverException(exception); } message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SWITCHTOWINDOW_NO_SUCH_ELEMENT); - message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle)); + message.setDescription(message.getDescription() + .replace("%WINDOW%", windowTitle) + .replace("%INITIALCONTEXT%", currentHandle) + .replace("%ALLCONTEXTS%", String.join("-", handles))); return message; }