Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/com/seleniumboot/migrator/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
Expand All @@ -33,6 +34,8 @@
/** Read-only static analysis: parses Java sources and reports patterns that map onto Selenium Boot. */
public final class Analyzer {

private static final Set<String> EXTENT_TYPES = Set.of("ExtentReports", "ExtentTest", "ExtentSparkReporter");

private static final Set<String> DRIVER_LIFECYCLE_ANNOTATIONS = Set.of(
"BeforeMethod", "AfterMethod", "BeforeClass", "AfterClass", "BeforeTest", "AfterTest",
"BeforeSuite", "AfterSuite", "Before", "After", "BeforeEach", "AfterEach", "BeforeAll", "AfterAll");
Expand Down Expand Up @@ -151,6 +154,19 @@ private void scan(CompilationUnit cu, String file, List<Finding> out, LocatorSta
.filter(c -> c.getNameAsString().endsWith("DriverManager") || c.getNameAsString().endsWith("DriverFactory"))
.forEach(c -> out.add(new Finding("MIG-015", MANUAL, file, line(c), c.getNameAsString(),
"Custom driver lifecycle: review, then replace with BaseTest.")));
// MIG-018: ExtentReports usage (flag only; Selenium Boot writes its own HTML report)
cu.findAll(ObjectCreationExpr.class).stream()
.filter(e -> EXTENT_TYPES.contains(e.getType().getNameAsString()))
.forEach(e -> out.add(new Finding("MIG-018", MANUAL, file, line(e),
"new " + e.getType().getNameAsString() + "(...)",
"ExtentReports: Selenium Boot generates an HTML report out of the box; remove after migrating custom logging to StepLogger.")));
cu.findAll(VariableDeclarator.class).stream()
.filter(v -> v.getType().isClassOrInterfaceType()
&& EXTENT_TYPES.contains(v.getType().asClassOrInterfaceType().getNameAsString()))
.filter(v -> v.getInitializer().map(init -> !init.isObjectCreationExpr()).orElse(true))
.forEach(v -> out.add(new Finding("MIG-018", MANUAL, file, line(v),
v.getType().asString() + " " + v.getNameAsString(),
"ExtentReports: Selenium Boot generates an HTML report out of the box; remove after migrating custom logging to StepLogger.")));
// MIG-017: driver lifecycle managed in TestNG or JUnit setup/teardown methods
cu.findAll(MethodDeclaration.class).stream()
.filter(this::isDriverLifecycleMethod)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/seleniumboot/migrator/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private static String ruleLabel(String ruleId) {
case "MIG-010" -> "MIG-010 (Page objects)";
case "MIG-011" -> "MIG-011 (@FindBy fields)";
case "MIG-012" -> "MIG-012 (PageFactory.initElements calls)";
case "MIG-018" -> "MIG-018 (ExtentReports usage)";
default -> ruleId;
};
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/seleniumboot/migrator/AnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ class P { void m() throws Exception {
assertTrue(r.containsAll(List.of("MIG-003", "MIG-014", "MIG-016")));
}

@Test
void detectsExtentReportsUsage() {
var r = rules("""
import com.aventstack.extentreports.ExtentReports;
class Reporting {
private ExtentReports extent = new ExtentReports();
ExtentSparkReporter spark = new ExtentSparkReporter("target/extent.html");
void m() {
ExtentTest test = extent.createTest("login");
test.pass("ok");
}
}""");
assertTrue(r.contains("MIG-018"));
// each creation or declaration is flagged once: extent (creation), spark (creation), test (declaration)
assertEquals(3, r.stream().filter("MIG-018"::equals).count());

var clean = rules("""
class Plain { void m() { System.out.println("no reporting here"); } }""");
assertFalse(clean.contains("MIG-018"));
}

@Test
void detectsRetryAndScreenshotListener() {
var r = rules("""
Expand Down