package com.crawljax.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.crawljax.browser.EmbeddedBrowser;
import com.crawljax.browser.WebDriverFirefox;
import com.crawljax.condition.eventablecondition.EventableConditionChecker;
import com.crawljax.util.PropertyHelper;

public class CandidateElementExtractorTest {

	private static EmbeddedBrowser browser;
	private static String url = "http://spci.st.ewi.tudelft.nl/demo/crawljax/";

	@BeforeClass
	public static void startup() {
		browser = new WebDriverFirefox();

		try {
			browser.goToUrl(url);
		} catch (CrawljaxException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}

		try {
			Thread.sleep(400);
		} catch (InterruptedException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	@Test
	public void testExtract() {
		CandidateElementExtractor extractor =
		        new CandidateElementExtractor(browser, new EventableConditionChecker());
		assertNotNull(extractor);
		try {

			String inc = "a:{}";
			TagElement tagElementInc = PropertyHelper.parseTagElements(inc);
			List<TagElement> includes = new ArrayList<TagElement>();
			includes.add(tagElementInc);

			List<CandidateElement> candidates =
			        extractor.extract(includes, new ArrayList<TagElement>(), true);

			assertNotNull(candidates);
			assertEquals(15, candidates.size());

		} catch (CrawljaxException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	@Test
	public void testExtractExclude() {
		CandidateElementExtractor extractor =
		        new CandidateElementExtractor(browser, new EventableConditionChecker());
		assertNotNull(extractor);

		try {

			String inc = "a:{}";
			TagElement tagElementInc = PropertyHelper.parseTagElements(inc);
			List<TagElement> includes = new ArrayList<TagElement>();
			includes.add(tagElementInc);

			// now exclude some elements
			String exc = "div:{id=menubar}";

			List<TagElement> excludes = new ArrayList<TagElement>();
			TagElement tagElementExc = PropertyHelper.parseTagElements(exc);
			excludes.add(tagElementExc);

			List<CandidateElement> candidates = extractor.extract(includes, excludes, true);

			assertNotNull(candidates);
			assertEquals(11, candidates.size());

		} catch (CrawljaxException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	@AfterClass
	public static void closeup() {
		browser.close();
	}
}

Make it possible to recursively exclude elements from candidates. This means an element will be excluded even when an ancestor is marked for exclusion.
Make it possible to recursively exclude elements from candidates. This means an element will be excluded even when an ancestor is marked for exclusion.

also moved all the static stuff (from PropertiesHelper) out of the CanidateElementExtractor, and wrote a unit test class that tests the new functionality.

git-svn-id: 6e5f6f61bd1b925b71fe8065f445f9178a317ca5@55 7701cf9b-ed3c-0410-a7c3-1ff289697e89
