|
4 | 4 | import freemarker.template.Template; |
5 | 5 | import freemarker.template.TemplateException; |
6 | 6 | import io.github.sridharbandi.a11y.Engine; |
| 7 | +import io.github.sridharbandi.modal.htmlcs.Issues; |
7 | 8 | import io.github.sridharbandi.modal.htmlcs.Params; |
8 | 9 | import org.apache.commons.io.FilenameUtils; |
9 | 10 | import org.apache.commons.io.IOUtils; |
@@ -41,22 +42,20 @@ public A11y(WebDriver driver) { |
41 | 42 | public A11y() { |
42 | 43 | } |
43 | 44 |
|
44 | | - public void execute(Engine engine, Params params) throws URISyntaxException, IOException, TemplateException { |
| 45 | + public Object execute(Engine engine, Params params) throws IOException { |
45 | 46 | waitForLoad(); |
46 | 47 | InputStream in = this.getClass().getClassLoader().getResourceAsStream("js/" + engine.toString().toLowerCase() + ".js"); |
47 | 48 | String js = IOUtils.toString(in, StandardCharsets.UTF_8); |
48 | | - String strJson = ""; |
49 | | - if (engine.name().equals(Engine.HTMLCS.name())) { |
50 | | - ObjectMapper mapper = new ObjectMapper(); |
51 | | - strJson = mapper.writeValueAsString(params); |
52 | | - } |
53 | | - String script = engine.name().equalsIgnoreCase("axe") ? "return axeData();" + js : "return getData('" + strJson + "');" + js; |
| 49 | + ObjectMapper mapper = new ObjectMapper(); |
| 50 | + String strJson = mapper.writeValueAsString(params); |
| 51 | + String script = engine.name().equalsIgnoreCase("axe") ? "return axeData('" + strJson + "');" + js : "return getData('" + strJson + "');" + js; |
54 | 52 | Object issues = javascriptExecutor.executeScript(script); |
55 | | - ObjectMapper objectMapper = new ObjectMapper(); |
56 | | - String strResponse = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(issues); |
| 53 | + String strResponse = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(issues); |
57 | 54 | Path path = get("./target/java-a11y/" + engine.toString().toLowerCase() + "/json/" + UUID.randomUUID() + ".json"); |
58 | 55 | createDirectories(path.getParent()); |
59 | 56 | write(path, strResponse.getBytes(StandardCharsets.UTF_8)); |
| 57 | + Class<?> clazz = engine.name().equalsIgnoreCase("axe") ? io.github.sridharbandi.modal.axe.Issues.class : Issues.class; |
| 58 | + return mapper.readValue(strResponse, clazz); |
60 | 59 | } |
61 | 60 |
|
62 | 61 | private void waitForLoad() { |
|
0 commit comments