Skip to content

Commit 6dcb762

Browse files
authored
fix: Correct class imports when custom element filter uses containsElement (#233)
1 parent 843080a commit 6dcb762

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

utam-compiler/src/main/java/utam/compiler/representation/CustomElementMethod.java

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ public Filtered(
167167
parametersTracker.setMethodParameters(locatorParameters);
168168
parametersTracker.setMethodParameters(applyParameters);
169169
parametersTracker.setMethodParameters(matcherParameters);
170+
parametersTracker
171+
.getMethodParameters()
172+
.forEach(param -> ParameterUtils.setImport(classImports, param.getType()));
170173
String locationCode = getElementLocationCode(componentName, locatorParameters);
171174
String predicate =
172175
getPredicateCode(applyMethod, applyParameters, matcherType, matcherParameters);

utam-compiler/src/test/java/utam/compiler/representation/ElementMethodTests.java

+22
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,26 @@ public void testFilterWithContainsElementSelectorArgument() {
350350
expected.addImpliedImportedTypes("utam.core.selenium.element.LocatorBy");
351351
PageObjectValidationTestHelper.validateMethod(method, expected);
352352
}
353+
354+
@Test
355+
public void testFilterCustomElementWithContainsElementSelectorArgument() {
356+
TranslationContext context =
357+
new DeserializerUtilities().getContext("filter/customWithFilterContainsElement");
358+
PageObjectMethod method = context.getMethod(ELEMENT_METHOD_NAME);
359+
assertThat(method.getDeclaration().getCodeLine(), is(equalTo("Custom getTest(String value)")));
360+
MethodInfo expected = new MethodInfo(ELEMENT_METHOD_NAME, "Custom");
361+
expected.addParameter(new MethodParameterInfo("value", "String"));
362+
expected.addParameter(
363+
new MethodParameterInfo(
364+
"LocatorBy.byCss(String.format(\"input[value='%s']\", value))", "LocatorBy"));
365+
expected.addCodeLine("BasicElement root = this.getRootElement()");
366+
expected.addCodeLine(
367+
"return custom(root, this.test).build(Custom.class, elm ->"
368+
+ " Boolean.TRUE.equals(elm.containsElement(LocatorBy.byCss(String.format(\"input[value='%s']\","
369+
+ " value)))))");
370+
expected.addImpliedImportedTypes("utam.custom.pageobjects.Custom");
371+
expected.addImpliedImportedTypes("utam.core.element.BasicElement");
372+
expected.addImpliedImportedTypes("utam.core.selenium.element.LocatorBy");
373+
PageObjectValidationTestHelper.validateMethod(method, expected);
374+
}
353375
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"elements": [
3+
{
4+
"name": "test",
5+
"public": true,
6+
"type": "utam-custom/pageObjects/custom",
7+
"selector": {
8+
"css": "my-custom-element[with-attribute='attr-value']",
9+
"returnAll": true
10+
},
11+
"filter": {
12+
"apply": "containsElement",
13+
"args": [
14+
{
15+
"type": "locator",
16+
"value": {
17+
"css": "input[value='%s']",
18+
"args": [
19+
{
20+
"name": "value",
21+
"type": "string"
22+
}
23+
]
24+
}
25+
}
26+
],
27+
"findFirst": true,
28+
"matcher": {
29+
"type": "isTrue"
30+
}
31+
}
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)