Search in sources :

Example 31 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class TextEmptinessCheckerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mockTextElementBuilder = createMock(TextElementBuilder.class);
    mockSSPHandler = createMock(SSPHandler.class);
    elements = new Elements();
    element = new Element(Tag.valueOf("div"), "");
    mockTestSolutionHandler = createMock(TestSolutionHandler.class);
    mockProcessRemarkService = createMock(ProcessRemarkService.class);
}
Also used : TextElementBuilder(org.asqatasun.rules.textbuilder.TextElementBuilder) Element(org.jsoup.nodes.Element) SSPHandler(org.asqatasun.processor.SSPHandler) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) Elements(org.jsoup.select.Elements) ProcessRemarkService(org.asqatasun.service.ProcessRemarkService)

Example 32 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class ImageElementSelector method excludeLinksFromSelection.

/**
     * 
     * @param elementHandler 
     */
private void excludeLinksFromSelection(ElementHandler<Element> elementHandler) {
    if (!excludeCompositeLink && !excludeImageLink) {
        return;
    }
    ElementHandler<Element> linkHandler = new ElementHandlerImpl();
    for (Element el : elementHandler.get()) {
        Element link = el.parents().select(A_ELEMENT).first();
        if (excludeImageLink && isImageLink(link, el)) {
            linkHandler.add(el);
        } else if (excludeCompositeLink && isCompositeLink(link, el)) {
            linkHandler.add(el);
        }
    }
    elementHandler.removeAll(linkHandler);
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl)

Example 33 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class DeepTextElementBuilder method buildTextFromElement.

@Override
public String buildTextFromElement(Element element) {
    StringBuilder elementText = new StringBuilder();
    if (element.hasAttr(ALT_ATTR)) {
        elementText.append(SPACER);
        elementText.append(altAttrTextBuilder.buildTextFromElement(element));
    }
    for (Node child : element.childNodes()) {
        if (child instanceof TextNode && !((TextNode) child).isBlank()) {
            elementText.append(SPACER);
            elementText.append(StringUtils.trim(((TextNode) child).text()));
        } else if (child instanceof Element) {
            elementText.append(SPACER);
            elementText.append(buildTextFromElement((Element) child));
        }
    }
    return StringUtils.trim(elementText.toString());
}
Also used : Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode)

Example 34 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class TextNotIdenticalToAttributeCheckerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mockTextElementBuilder = createMock(TextElementBuilder.class);
    mockSSPHandler = createMock(SSPHandler.class);
    elements = new Elements();
    element = new Element(Tag.valueOf("div"), "");
    element.attr(AttributeStore.ALT_ATTR, "test");
    mockTestSolutionHandler = createMock(TestSolutionHandler.class);
    mockProcessRemarkService = createMock(ProcessRemarkService.class);
}
Also used : TextElementBuilder(org.asqatasun.rules.textbuilder.TextElementBuilder) Element(org.jsoup.nodes.Element) SSPHandler(org.asqatasun.processor.SSPHandler) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) Elements(org.jsoup.select.Elements) ProcessRemarkService(org.asqatasun.service.ProcessRemarkService)

Example 35 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class ElementPresenceCheckerTest method testCheckDefaultDetectedUnicityFailedOverrideSolutionResult1.

/**
     * Test of doCheck method, of class ElementPresenceChecker.
     * @throws java.io.IOException
     */
public void testCheckDefaultDetectedUnicityFailedOverrideSolutionResult1() throws IOException {
    LOGGER.debug("elementPresenceChecker-check-default-detection-unicity-failed-override-solution-result1");
    Document doc = Jsoup.parse(new File("src/test/resources/presenceChecker/presence-checker-unique-1.html"), Charset.defaultCharset().displayName());
    ElementHandler<Element> elementHandler = new ElementHandlerImpl();
    elementHandler.addAll(doc.select(HtmlElementStore.DIV_ELEMENT));
    initMockContext((Elements) elementHandler.get(), TestSolution.NEED_MORE_INFO, "detected");
    TestSolutionHandler testSolutionHandler = new TestSolutionHandlerImpl();
    ElementPresenceChecker instance = new ElementPresenceChecker(true, TestSolution.NEED_MORE_INFO, TestSolution.NOT_APPLICABLE, "detected", "notDetected", null);
    instance.check(mockSspHandler, elementHandler, testSolutionHandler);
    assertEquals(TestSolution.NEED_MORE_INFO, testSolutionHandler.getTestSolution());
    verifyMockContext();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) Document(org.jsoup.nodes.Document) File(java.io.File)

Aggregations

Element (org.jsoup.nodes.Element)400 Document (org.jsoup.nodes.Document)164 Elements (org.jsoup.select.Elements)120 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)87 IOException (java.io.IOException)66 File (java.io.File)62 Test (org.junit.Test)62 ArrayList (java.util.ArrayList)56 Configuration (com.vaadin.addon.charts.model.Configuration)22 DesignContext (com.vaadin.ui.declarative.DesignContext)22 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)21 URL (java.net.URL)16 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)15 SimpleElementSelector (org.asqatasun.rules.elementselector.SimpleElementSelector)13 TestSolution (org.asqatasun.entity.audit.TestSolution)11 InputStream (java.io.InputStream)9 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)9 HashMap (java.util.HashMap)8 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)8 GradientColor (com.vaadin.addon.charts.model.style.GradientColor)7