Skip to content

Commit

Permalink
#2474 Add control verifyElementChecked and verifyElementNotChecked
Browse files Browse the repository at this point in the history
  • Loading branch information
bcivel committed Aug 5, 2023
1 parent dc97c72 commit 341407a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class TestCaseStepActionControl {
public static final String CONTROL_VERIFYELEMENTNOTPRESENT = "verifyElementNotPresent";
public static final String CONTROL_VERIFYELEMENTVISIBLE = "verifyElementVisible";
public static final String CONTROL_VERIFYELEMENTNOTVISIBLE = "verifyElementNotVisible";
public static final String CONTROL_VERIFYELEMENTCHECKED = "verifyElementChecked";
public static final String CONTROL_VERIFYELEMENTNOTCHECKED = "verifyElementNotChecked";
public static final String CONTROL_VERIFYELEMENTEQUALS = "verifyElementEquals";
public static final String CONTROL_VERIFYELEMENTDIFFERENT = "verifyElementDifferent";
public static final String CONTROL_VERIFYELEMENTINELEMENT = "verifyElementInElement";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExe
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:
res = this.verifyElementNotVisible(execution, value1);
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCHECKED:
res = this.verifyElementChecked(execution, value1);
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCHECKED:
res = this.verifyElementNotChecked(execution, value1);
break;
case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:
res = this.verifyElementEquals(execution, value1, controlExecution.getValue2());
break;
Expand Down Expand Up @@ -914,6 +920,66 @@ private MessageEvent verifyElementNotVisible(TestCaseExecution tCExecution, Stri
return mes;
}

private MessageEvent verifyElementChecked(TestCaseExecution tCExecution, String html) {
LOG.debug("Control: verifyElementChecked on: {}", html);
MessageEvent mes;
if (!StringUtil.isEmptyOrNullValue(html)) {
if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)
|| tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)
|| tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {

try {
Identifier identifier = identifierService.convertStringToIdentifier(html);
if (this.webdriverService.isElementChecked(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CHECKED);
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CHECKED);
}
mes.resolveDescription("STRING1", html);
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTCHECKED);
mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CHECKED_NULL);
}
return mes;
}

private MessageEvent verifyElementNotChecked(TestCaseExecution tCExecution, String html) {
LOG.debug("Control: verifyElementNotChecked on: {}", html);
MessageEvent mes;
if (!StringUtil.isEmptyOrNullValue(html)) {
if (tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_GUI)
|| tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_APK)
|| tCExecution.getAppTypeEngine().equalsIgnoreCase(Application.TYPE_IPA)) {

try {
Identifier identifier = identifierService.convertStringToIdentifier(html);
if (this.webdriverService.isElementNotChecked(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTCHECKED);
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCHECKED);
}
mes.resolveDescription("STRING1", html);
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.resolveDescription("CONTROL", TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCHECKED);
mes.resolveDescription("APPLICATIONTYPE", tCExecution.getAppTypeEngine());
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTCHECKED_NULL);
}
return mes;
}

private MessageEvent verifyElementEquals(TestCaseExecution tCExecution, String xpath, String expectedElement) {
LOG.debug("Control: verifyElementEquals on: {} expected Element: {}", xpath, expectedElement);
MessageEvent mes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ public enum MessageEventEnum {
CONTROL_SUCCESS_NOTPRESENT(300, "OK", "Element '%STRING1%' is not present on the message/page/screen.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_VISIBLE(300, "OK", "Element '%STRING1%' is visible on the page.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_NOTVISIBLE(300, "OK", "Element '%STRING1%' is present and not visible on the page.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_CHECKED(300, "OK", "Element '%STRING1%' is checked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_NOTCHECKED(300, "OK", "Element '%STRING1%' is not checked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_ELEMENTTEXTEQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is equal to %VALUE% (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is different than %VALUE% (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
CONTROL_SUCCESS_ELEMENTTEXTCONTAINS(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' contains '%VALUE%' (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
Expand Down Expand Up @@ -418,8 +420,12 @@ public enum MessageEventEnum {
CONTROL_FAILED_NOTPRESENT_NULL(364, "KO", "Value1 is 'null'. This is mandatory in order to perform the control verify element not present", true, false, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_VISIBLE(365, "KO", "Element '%STRING1%' not visible on the page.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_NOTVISIBLE(365, "KO", "Element '%STRING1%' is visible on the page.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_CHECKED(365, "KO", "Element '%STRING1%' is detected as not checked.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_NOTCHECKED(365, "KO", "Element '%STRING1%' is detected as checked.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_VISIBLE_NULL(366, "KO", "Value1 is 'null'. This is mandatory in order to perform the control verify element visible", true, false, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_NOTVISIBLE_NULL(366, "KO", "Value1 is 'null'. This is mandatory in order to perform the control verify element not visible", true, false, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_CHECKED_NULL(366, "KO", "Value1 is 'null'. This is mandatory in order to perform the control verify element checked", true, false, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_NOTCHECKED_NULL(366, "KO", "Value1 is 'null'. This is mandatory in order to perform the control verify element not checked", true, false, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_ELEMENT_NULL(368, "KO", "Found Element '%ELEMENT%' but can not find text or value.", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_ELEMENT_NOSUCHELEMENT(369, "KO", "Could not find element '%ELEMENT%'", true, true, true, MessageGeneralEnum.EXECUTION_KO),
CONTROL_FAILED_ELEMENTTEXTEQUAL(367, "KO", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is not equal to %VALUE% (%CASESENSITIVE%).", true, true, true, MessageGeneralEnum.EXECUTION_KO),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public interface IWebDriverService {

boolean isElementNotVisible(Session session, Identifier identifier);

boolean isElementChecked(Session session, Identifier identifier);

boolean isElementNotChecked(Session session, Identifier identifier);

boolean isElementInElement(Session session, Identifier identifier, Identifier childIdentifier);

boolean isElementNotClickable(Session session, Identifier identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,36 @@ public boolean isElementNotVisible(Session session, Identifier identifier) {
}
}

@Override
public boolean isElementChecked(Session session, Identifier identifier) {
try {
AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);
if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement webElement = (WebElement) answer.getItem();
return webElement != null && webElement.isSelected();
}

} catch (NoSuchElementException exception) {
LOG.warn(exception.toString());
}
return false;
}

@Override
public boolean isElementNotChecked(Session session, Identifier identifier) {
try {
AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);
if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement webElement = (WebElement) answer.getItem();
return webElement != null && !webElement.isSelected();
}

} catch (NoSuchElementException exception) {
LOG.warn(exception.toString());
}
return false;
}

@Override
public String getPageSource(Session session) {
return session.getDriver().getPageSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
| getPageSource | Force the page source to be retrieved and stored to be checked for detailed analysis. |
| takeScreenshot | Force to take a screenshot. Image can be automatically crop when taking the screenshot allowing to automatize clean application or web site screenshot (without Operating system header or footer elements). |
| verifyElementClickable | *[green]#OK#* if *[red]#Element#* is clickable. |
| verifyElementChecked | *[green]#OK#* if *[red]#Checkbox#* is checked. |
| verifyElementNotChecked | *[green]#OK#* if *[red]#Checkbox#* is not checked. |
| verifyElementDifferent | TBD |
| verifyElementEquals | TBD |
| verifyElementinElement | *[green]#OK#* if *[red]#Sub Element#* is inside *[red]#Master Element#*. That can be used to check if an option is available inside a select box. |
Expand Down
8 changes: 7 additions & 1 deletion source/src/main/webapp/js/testcase/control.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 341407a

Please sign in to comment.