<commit_before>package com.xebia.incubator.xebium;

import static org.apache.commons.lang.StringUtils.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriverCommandProcessor;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.thoughtworks.selenium.CommandProcessor;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.thoughtworks.selenium.SeleniumException;

public class SeleniumDriverFixture {

	private static final String REGEXP = "regexp:";

	private static Logger LOG = Logger.getLogger(SeleniumDriverFixture.class);

	private CommandProcessor commandProcessor;

	private long timeout = 30000;
	
	// TODO: decide: move to method or move to separate fixture.
	static {
		BasicConfigurator.configure();
	}

	public CommandProcessor detectWebDriverCommandProcessor(final String browser, String browserUrl) {
		browserUrl = FitNesseUtil.removeAnchorTag(browserUrl);
		Capabilities capabilities;

		if ("firefox".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.firefox();
		} else if ("iexplore".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.internetExplorer();
		} else if ("chrome".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.chrome();
		} else if ("htmlUnit".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.htmlUnit();
		} else {
			throw new RuntimeException("Unknown browser type. Should be one of 'firefox', 'iexplore', 'chrome' or 'htmlUnit'");
		}
		return new WebDriverCommandProcessor(browserUrl, capabilities);
	}

	public void startBrowserOnUrl(final String browser, final String browserUrl) {
		commandProcessor = detectWebDriverCommandProcessor(browser, browserUrl);
		commandProcessor.start();
		LOG.debug("Started command processor");
	}

	public void startBrowserOnHostOnPortOnUrl(final String browserStartCommand, final String serverHost, final int serverPort, final String browserUrl) {
		commandProcessor = new HttpCommandProcessor(serverHost, serverPort, browserStartCommand, FitNesseUtil.removeAnchorTag(browserUrl));
		commandProcessor.start();
		LOG.debug("Started HTML command processor");
	}

	public boolean doOn(final String command, final String target) {
		LOG.info("Performing | " + command + " | " + target + " |");
		return executeDoCommand(command, new String[] { target });
	}

	public boolean doOnWith(final String command, final String target, final String value) {
		LOG.info("Performing | " + command + " | " + target + " | " + value + " |");
		return executeDoCommand(command, new String[] { target, value });
	}

	public String is(final String command) {
		return executeCommand(command, new String[] { });
	}

	public String isOn(final String command, final String target) {
		return executeCommand(command, new String[] { target });
	}

	private String executeCommand(final String methodName, final String[] values) {
		return executeCommand(new ExtendedSeleniumCommand(methodName), values);
	}

	private boolean executeDoCommand(final String methodName, final String[] values) {
		final ExtendedSeleniumCommand command = new ExtendedSeleniumCommand(methodName);
		final String output = executeCommand(command, values);

		if (command.isVerifyCommand() || command.isWaitForCommand()) {
			return checkResult(output, command, values[values.length - 1]);
		} else if (command.isAssertCommand()) {
			if (!checkResult(output, command, values[values.length - 1])) {<commit_msg>Added "pause" command.<commit_after>package com.xebia.incubator.xebium;

import static org.apache.commons.lang.StringUtils.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriverCommandProcessor;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.thoughtworks.selenium.CommandProcessor;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.thoughtworks.selenium.SeleniumException;

public class SeleniumDriverFixture {

	private static final String REGEXP = "regexp:";

	private static Logger LOG = Logger.getLogger(SeleniumDriverFixture.class);

	private CommandProcessor commandProcessor;

	private long timeout = 30000;
	
	// TODO: decide: move to method or move to separate fixture.
	static {
		BasicConfigurator.configure();
	}

	public CommandProcessor detectWebDriverCommandProcessor(final String browser, String browserUrl) {
		browserUrl = FitNesseUtil.removeAnchorTag(browserUrl);
		Capabilities capabilities;

		if ("firefox".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.firefox();
		} else if ("iexplore".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.internetExplorer();
		} else if ("chrome".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.chrome();
		} else if ("htmlUnit".equalsIgnoreCase(browser)) {
			capabilities = DesiredCapabilities.htmlUnit();
		} else {
			throw new RuntimeException("Unknown browser type. Should be one of 'firefox', 'iexplore', 'chrome' or 'htmlUnit'");
		}
		return new WebDriverCommandProcessor(browserUrl, capabilities);
	}

	public void startBrowserOnUrl(final String browser, final String browserUrl) {
		commandProcessor = detectWebDriverCommandProcessor(browser, browserUrl);
		commandProcessor.start();
		LOG.debug("Started command processor");
	}

	public void startBrowserOnHostOnPortOnUrl(final String browserStartCommand, final String serverHost, final int serverPort, final String browserUrl) {
		commandProcessor = new HttpCommandProcessor(serverHost, serverPort, browserStartCommand, FitNesseUtil.removeAnchorTag(browserUrl));
		commandProcessor.start();
		LOG.debug("Started HTML command processor");
	}

	public boolean doOn(final String command, final String target) {
		LOG.info("Performing | " + command + " | " + target + " |");
		return executeDoCommand(command, new String[] { target });
	}

	public boolean doOnWith(final String command, final String target, final String value) {
		LOG.info("Performing | " + command + " | " + target + " | " + value + " |");
		return executeDoCommand(command, new String[] { target, value });
	}

	public String is(final String command) {
		return executeCommand(command, new String[] { });
	}

	public String isOn(final String command, final String target) {
		return executeCommand(command, new String[] { target });
	}

	private String executeCommand(final String methodName, final String[] values) {
		return executeCommand(new ExtendedSeleniumCommand(methodName), values);
	}

	private boolean executeDoCommand(final String methodName, final String[] values) {
		
		if ("pause".equals(methodName)) {
			try {
				Thread.sleep(Integer.parseInt(values[0]));
			} catch (Exception e) {
				LOG.warn("Pause command interrupted", e);
			}
			return true;
		}
		
		final ExtendedSeleniumCommand command = new ExtendedSeleniumCommand(methodName);
		final String output = executeCommand(command, values);

		if (command.isVerifyCommand() || command.isWaitForCommand()) {
			return checkResult(output, command, values[values.length - 1]);
		} else if (command.isAssertCommand()) {
			if (!checkResult(output, command, values[values.length - 1])) {
{'fraction_non_alphanumeric': 0.10641075858467162, 'fraction_numerical': 0.003003003003003003, 'mean_word_length': 5.689956331877729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7151166', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2110, 'n_words': 535}