Skip to content

Commit

Permalink
#593: correct UT
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Mar 13, 2024
1 parent 515a5d5 commit 04d7b19
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 313 deletions.
26 changes: 23 additions & 3 deletions core/src/main/java/com/seleniumtests/core/aspects/LogAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,14 @@ public static String buildArgString(JoinPoint joinPoint, List<String> stringToRe
// add arguments to the name of the method
if (arg instanceof Object[]) {
argValue.append("[");
for (Object obj: (Object[])arg) {
for (Object obj : (Object[]) arg) {
argValue.append(obj.toString() + ",");
}
argValue.append("]");
} else if (arg instanceof Element) {
argValue.append(((Element) arg).toString());
} else if (arg instanceof WebElement) {
argValue.append(new SeleniumElement((WebElement)arg).getName());
} else {
argValue.append((arg == null ? "null": arg.toString()));
}
Expand Down Expand Up @@ -653,8 +657,8 @@ public void logCompositeAction(JoinPoint joinPoint) {
targetClass = targetElement.getOriginClass();
// for Selenium WebElement
} else if (joinPoint.getArgs().length > 0 && (joinPoint.getArgs()[0] instanceof WebElement)) {
targetElement = new SeleniumElement((WebElement)joinPoint.getTarget());
targetClass = ((PageObject)joinPoint.getTarget()).getClass();
targetElement = new SeleniumElement((WebElement)joinPoint.getArgs()[0]);
targetClass = ((PageObject)joinPoint.getThis()).getClass();
}

TestAction currentAction = new TestAction(actionName, false, pwdToReplace, joinPoint.getSignature().getName(), targetElement, targetClass);
Expand Down Expand Up @@ -695,6 +699,22 @@ public Object logPerformCompositeAction(ProceedingJoinPoint joinPoint) throws Th
} finally {
if (compositeActionStep != null) {
compositeActionStep.setFailed(actionFailed);

// change the name of composite action
StringBuilder name = new StringBuilder(TestStep.COMPOSITE_STEP_PREFIX);
Element mainElement = null; // the last element on which we act

for (TestAction action: compositeActionStep.getStepActions()) {
name.append(action.getAction() + ",");
if (action.getElement() != null) {
mainElement = action.getElement();
}
action.setFailed(actionFailed);
}
String elementName = mainElement instanceof SeleniumElement ? mainElement.getName(): mainElement.toString();
name.append("on element '" + elementName + "'");
compositeActionStep.setName(name.toString());

scenarioLogger.logActionError(currentException);
TestStepManager.setParentTestStep((TestStep)compositeActionStep.getParent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TestAction {


protected static final Logger logger = SeleniumRobotLogger.getLogger(TestAction.class);

protected String name;
protected TestAction parent = null;
protected int position = 0;
Expand Down Expand Up @@ -136,6 +136,10 @@ public String getName() {
return newName;
}

public void setName(String name) {
this.name = name;
}

public LocalDateTime getTimestamp() {
return timestamp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ private String getElementLocator(WebElement el) {

if (el.toString().contains("->")) {
try {
return el.toString().split("->")[1].replace("]", "").replace("}", "");
return el.toString().split("->")[1].replace("]", "").replace("}", "").trim();
} catch (IndexOutOfBoundsException e) {
// we should never go here
}
}
return el.toString();
}

@Override
public String toString() {
return webElement.toString();
}

@Override
protected void findElement(boolean waitForVisibility) {

Expand Down
Loading

0 comments on commit 04d7b19

Please sign in to comment.