diff --git a/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java b/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java index b662394af..84c234927 100644 --- a/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java +++ b/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java @@ -405,9 +405,9 @@ public List recordScreenshot(TestCaseExecution execution, newImage = this.sikuliService.takeScreenShotFile(execution.getSession()); } + long maxSizeParam = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", 1048576); if (newImage != null) { try { - long maxSizeParam = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", 1048576); Recorder recorder = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, fileName, "png", false); LOG.debug("{}FullPath {}", logPrefix, recorder.getFullPath()); @@ -439,36 +439,45 @@ public List recordScreenshot(TestCaseExecution execution, LOG.debug("{}Temp file deleted with success {}", logPrefix, newImage.getName()); LOG.debug("{}Screenshot done in : {}", logPrefix, recorder.getRelativeFilenameURL()); - if (newImageDesktop != null) { - Recorder recorderDestop = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, fileName + "-desktop", "png", false); - LOG.debug("{}FullPath {}", logPrefix, recorderDestop.getFullPath()); - - // Getting the max size of the screenshot. - fileDesc = "Desktop " + fileDescription; - if (maxSizeParam < newImageDesktop.length()) { - LOG.warn("{}Screenshot size exceeds the maximum defined in configurations ({}>={}) {} destination: {}", logPrefix, newImageDesktop.length(), maxSizeParam, newImageDesktop.getName(), recorderDestop.getRelativeFilenameURL()); - fileDesc = "Desktop Screenshot Too Big !!"; - } else { - // Copies the temp file to the execution file - FileUtils.moveFile(newImageDesktop, new File(recorderDestop.getFullFilename())); - LOG.debug("{}Moving file finished with success - source: {} destination: {}", logPrefix, newImageDesktop.getName(), recorderDestop.getRelativeFilenameURL()); - LOG.info("File saved : {}", recorderDestop.getFullFilename()); - } + } catch (IOException | CerberusException ex) { + LOG.error("{}{}", logPrefix, ex.toString(), ex); + } + } else { + LOG.warn("{}Screenshot returned null.", logPrefix); + } - // Index file created to database. - object = testCaseExecutionFileFactory.create(0, execution.getId(), recorderDestop.getLevel(), fileDesc, recorderDestop.getRelativeFilenameURL(), "PNG", "", null, "", null); - objectList.add(object); - testCaseExecutionFileService.save(object); + if (newImageDesktop != null) { + + try { + + Recorder recorderDestop = this.initFilenames(runId, test, testCase, step, index, sequence, controlString, null, 0, fileName + "-desktop", "png", false); + LOG.debug("{}FullPath {}", logPrefix, recorderDestop.getFullPath()); - //deletes the temporary file - LOG.debug("{}Desktop Screenshot done in : {}", logPrefix, recorderDestop.getRelativeFilenameURL()); + // Getting the max size of the screenshot. + String fileDesc = "Desktop " + fileDescription; + if (maxSizeParam < newImageDesktop.length()) { + LOG.warn("{}Screenshot size exceeds the maximum defined in configurations ({}>={}) {} destination: {}", logPrefix, newImageDesktop.length(), maxSizeParam, newImageDesktop.getName(), recorderDestop.getRelativeFilenameURL()); + fileDesc = "Desktop Screenshot Too Big !!"; + } else { + // Copies the temp file to the execution file + FileUtils.moveFile(newImageDesktop, new File(recorderDestop.getFullFilename())); + LOG.debug("{}Moving file finished with success - source: {} destination: {}", logPrefix, newImageDesktop.getName(), recorderDestop.getRelativeFilenameURL()); + LOG.info("File saved : {}", recorderDestop.getFullFilename()); } + + // Index file created to database. + object = testCaseExecutionFileFactory.create(0, execution.getId(), recorderDestop.getLevel(), fileDesc, recorderDestop.getRelativeFilenameURL(), "PNG", "", null, "", null); + objectList.add(object); + testCaseExecutionFileService.save(object); + + //deletes the temporary file + LOG.debug("{}Desktop Screenshot done in : {}", logPrefix, recorderDestop.getRelativeFilenameURL()); } catch (IOException | CerberusException ex) { LOG.error("{}{}", logPrefix, ex.toString(), ex); } - } else { - LOG.warn("{}Screenshot returned null.", logPrefix); + } + return objectList; } diff --git a/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java b/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java index 391f4b63a..5315b89ca 100644 --- a/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java +++ b/source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java @@ -1130,36 +1130,36 @@ private MessageEvent doActionMouseMove(TestCaseExecution tCExecution, String val return message; } - private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) { + private MessageEvent doActionSwitchToWindow(TestCaseExecution execution, String object, String property) { String element; try { /** * Get element to use String object if not empty, String property if * object empty, throws Exception if both empty) */ - element = getElementToUse(object, property, "switchToWindow", tCExecution); + element = getElementToUse(object, property, "switchToWindow", execution); /** * Get Identifier (identifier, locator) */ Identifier identifier = identifierService.convertStringToIdentifier(element); //identifierService.checkWebElementIdentifier(identifier.getIdentifier()); - if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) { - return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier); + if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) { + return webdriverService.doSeleniumActionSwitchToWindow(execution.getSession(), identifier); - } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) { - return androidAppiumService.switchToContext(tCExecution.getSession(), identifier); + } else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) { + return androidAppiumService.switchToContext(execution.getSession(), identifier); - } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) { - return iosAppiumService.switchToContext(tCExecution.getSession(), identifier); + } else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) { + return iosAppiumService.switchToContext(execution.getSession(), identifier); - } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { - return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator()); + } else if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) { + return sikuliService.doSikuliActionSwitchApp(execution.getSession(), identifier.getLocator()); } else { return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION) .resolveDescription("ACTION", "SwitchToWindow") - .resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType()); + .resolveDescription("APPLICATIONTYPE", execution.getApplicationObj().getType()); } } catch (CerberusEventException ex) { LOG.fatal("Error doing Action SwitchToWindow :" + ex); 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 d818bfd7e..cabf5853e 100644 --- a/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java +++ b/source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java @@ -247,6 +247,7 @@ public enum MessageEventEnum { ACTION_FAILED_WITHDETAIL(250, "FA", "Action Error : %DETAIL%", true, true, false, MessageGeneralEnum.EXECUTION_FA), ACTION_FAILED_CLICK(251, "FA", "Failed to click on '%ELEMENT%'. %MESS%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_SELENIUM_CONNECTIVITY(252, "CA", "The test case is cancelled due to lost connection to Selenium Server! Detailed error : %ERROR%", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), + ACTION_FAILED_SELENIUM_EXCEPTION(252, "FA", "Action failed due to Selenium Exception! Detailed error : '%ERROR%'", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_NO_SUCH_ELEMENT(253, "FA", "Identifier '%IDENTIFIER%=' isn't recognized! Use: id=, name=, class=, css= , xpath= , link= , picture= or data-cerberus=.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_UNKOWN_IDENTIFIER_SIKULI(253, "FA", "Identifier '%IDENTIFIER%=' isn't recognized! Use: picture= or text=.", true, true, true, MessageGeneralEnum.EXECUTION_FA_ACTION), ACTION_FAILED_UNKOWN_IDENTIFIER_SELENIUM(253, "FA", "Identifier '%IDENTIFIER%=' isn't recognized! Use: id=, name=, class=, css= , xpath= , link= , coord=, picture= or data-cerberus=.", 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 e34868488..2f89d3160 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 @@ -136,7 +136,7 @@ private By getBy(Identifier identifier) { return by; } - public AnswerItem getWebElement(Session session, Identifier identifier, boolean random, int rank){ + public AnswerItem getWebElement(Session session, Identifier identifier, boolean random, int rank) { AnswerItem answer = new AnswerItem<>(); MessageEvent msg; @@ -147,32 +147,32 @@ public AnswerItem getWebElement(Session session, Identifier identifi Instant now = Instant.now(); Instant stop = now.plus(session.getCerberus_selenium_wait_element(), ChronoUnit.MILLIS); - while(stop.isAfter(Instant.now()) && element==null) { + while (stop.isAfter(Instant.now()) && element == null) { try { - //Find all elements retrieved - List elements = session.getDriver().findElements(this.getBy(identifier)); + //Find all elements retrieved + List elements = session.getDriver().findElements(this.getBy(identifier)); - // If random, overide rank with one random int from 1 to the size of the result - if (random) { - Random r = new Random(); - rank = r.nextInt(elements.size()); - } - // -1 because default value is 1 - element = (WebElement) elements.get(rank); + // If random, overide rank with one random int from 1 to the size of the result + if (random) { + Random r = new Random(); + rank = r.nextInt(elements.size()); + } + // -1 because default value is 1 + element = (WebElement) elements.get(rank); } catch (Exception ex) { LOG.debug("ELEMENT NOT FOUND : ", identifier.getIdentifier() + "=" + identifier.getLocator() + " : TRYING AGAIN"); } } - if (element == null){ + if (element == null) { msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT); msg.resolveDescription("ELEMENT", identifier.getIdentifier() + "=" + identifier.getLocator()); } else { answer.setItem(element); msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT); - msg.resolveDescription("ELEMENT", identifier.getIdentifier() + "=" + identifier.getLocator() ); + msg.resolveDescription("ELEMENT", identifier.getIdentifier() + "=" + identifier.getLocator()); } answer.setResultMessage(msg); @@ -432,7 +432,7 @@ private AnswerItem getSeleniumElement(Session session, Identifier id Integer numberOfElement = 0; try { numberOfElement = this.getNumberOfElements(session, identifier); - } catch(Exception ex){ + } catch (Exception ex) { //No element found } msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT); @@ -549,7 +549,7 @@ public String getElements(Session session, Identifier identifier) { List result = new ArrayList(); List elements = driver.findElements(this.getBy(identifier)); - for(WebElement element : elements){ + for (WebElement element : elements) { result.add(element.getAttribute("innerHTML").toString()); } @@ -562,7 +562,7 @@ public String getElementsValues(Session session, Identifier identifier) { List result = new ArrayList(); List elements = driver.findElements(this.getBy(identifier)); - for(WebElement webElement : elements){ + for (WebElement webElement : elements) { if (webElement != null) { if (webElement.getTagName().equalsIgnoreCase("select")) { Select select = (Select) webElement; @@ -642,7 +642,7 @@ public String getValueFromJS(Session session, String script) { } @Override - public String getAttributeFromHtml(Session session, Identifier identifier, String attribute, boolean random, Integer rank) { + public String getAttributeFromHtml(Session session, Identifier identifier, String attribute, boolean random, Integer rank) { String result = null; try { AnswerItem answer = this.getWebElement(session, identifier, random, rank); @@ -1044,7 +1044,7 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i // Add try catch to handle not exist anymore window (like when popup is closed). try { currentWindowId = session.getDriver().getWindowHandle(); - initialContext = "URL:"+session.getDriver().getCurrentUrl()+" | Title:"+session.getDriver().getTitle(); + initialContext = "URL:" + session.getDriver().getCurrentUrl() + " | Title:" + session.getDriver().getTitle(); } catch (NoSuchWindowException exception) { currentWindowId = null; initialContext = "Page has been closed."; @@ -1059,18 +1059,18 @@ public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier i String targetHandle = null; for (String windowHandle : handles) { //if (!windowHandle.equals(currentWindowId)) { - session.getDriver().switchTo().window(windowHandle); - allContexts.add("URL:"+session.getDriver().getCurrentUrl()+" | Title:"+session.getDriver().getTitle()); + session.getDriver().switchTo().window(windowHandle); + allContexts.add("URL:" + session.getDriver().getCurrentUrl() + " | Title:" + session.getDriver().getTitle()); - if (checkIfExpectedWindow(session, identifier.getIdentifier(), identifier.getLocator())) { - targetHandle = windowHandle; - targetContext = "URL:"+session.getDriver().getCurrentUrl()+" | Title:"+session.getDriver().getTitle(); - } + if (checkIfExpectedWindow(session, identifier.getIdentifier(), identifier.getLocator())) { + targetHandle = windowHandle; + targetContext = "URL:" + session.getDriver().getCurrentUrl() + " | Title:" + session.getDriver().getTitle(); + } //} LOG.debug("windowHandle=" + windowHandle); } - if (!StringUtil.isEmptyOrNull(targetHandle)){ + if (!StringUtil.isEmptyOrNull(targetHandle)) { session.getDriver().switchTo().window(targetHandle); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOWINDOW); message.setDescription(message.getDescription() @@ -1226,7 +1226,7 @@ private boolean checkIfExpectedWindow(Session session, String identifier, String } @Override - public MessageEvent doSeleniumActionDoubleClick(Session session, Identifier identifier, Integer hOffset, Integer vOffset, boolean waitForVisibility, boolean waitForClickability) { + public MessageEvent doSeleniumActionDoubleClick(Session session, Identifier identifier, Integer hOffset, Integer vOffset, boolean waitForVisibility, boolean waitForClickability) { MessageEvent message; try { AnswerItem answer = this.getSeleniumElement(session, identifier, waitForVisibility, waitForClickability); @@ -1312,7 +1312,7 @@ public MessageEvent doSeleniumActionMouseOver(Session session, Identifier identi actions.build().perform(); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER); message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator())); - message.setDescription(message.getDescription().replace("%OFFSET%", "("+hOffset+","+vOffset+")")); + message.setDescription(message.getDescription().replace("%OFFSET%", "(" + hOffset + "," + vOffset + ")")); return message; } } @@ -1321,7 +1321,7 @@ public MessageEvent doSeleniumActionMouseOver(Session session, Identifier identi } catch (NoSuchElementException exception) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT); message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator())); - message.setDescription(message.getDescription().replace("%OFFSET%", "("+hOffset+","+vOffset+")")); + message.setDescription(message.getDescription().replace("%OFFSET%", "(" + hOffset + "," + vOffset + ")")); LOG.debug(exception.toString()); return message; } catch (TimeoutException exception) { @@ -2046,7 +2046,7 @@ public MessageEvent doSeleniumActionRightClick(Session session, Identifier ident private MessageEvent parseWebDriverException(WebDriverException exception) { MessageEvent mes; LOG.fatal(exception.toString()); - mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY); + mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_EXCEPTION); mes.setDescription(mes.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0])); return mes; } diff --git a/source/src/main/resources/documentation/D1/include/en/testmanagement_tcactions_en.adoc b/source/src/main/resources/documentation/D1/include/en/testmanagement_tcactions_en.adoc index 19a802acc..edec5ab9f 100644 --- a/source/src/main/resources/documentation/D1/include/en/testmanagement_tcactions_en.adoc +++ b/source/src/main/resources/documentation/D1/include/en/testmanagement_tcactions_en.adoc @@ -135,6 +135,11 @@ identifier can be **__title__**, **__url__**, *_regexUrl_* or *_regexTitle_* title=titleOfThisNewWindow ==== +.By Regex Tittle +==== +regexTitle=.\*ThisNewWindow.* +==== + .By Url ==== url=http://url_of_this_new_window diff --git a/source/src/main/webapp/js/pages/TestCaseExecutionList.js b/source/src/main/webapp/js/pages/TestCaseExecutionList.js index 55a3c5c44..fa5302532 100644 --- a/source/src/main/webapp/js/pages/TestCaseExecutionList.js +++ b/source/src/main/webapp/js/pages/TestCaseExecutionList.js @@ -180,7 +180,7 @@ function aoColumnsFunc() { "sName": "exe.start", "like": true, "title": doc.getDocOnline("page_executiondetail", "start"), - "sWidth": "70px", + "sWidth": "110px", "sDefaultContent": "", "mRender": function (data, type, obj) { return new Date(obj.start).toLocaleString();