<commit_before>package com.seleniumtests.driver.web;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.log4j.Logger;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import com.seleniumtests.controller.Context;
import com.seleniumtests.controller.ContextManager;
import com.seleniumtests.controller.Logging;
import com.seleniumtests.exception.WebSessionTerminatedException;
import com.seleniumtests.helper.FileHelper;
import com.seleniumtests.helper.URLHelper;

public class ScreenshotUtil {
	private static final Logger logger = Logger.getLogger(ScreenshotUtil.class);

	public static String captureEntirePageScreenshotToString(WebDriver driver,
			String arg0) {
		if (driver == null)
			return "";
		try {
			// Don't capture snapshot for htmlunit
			if (WebUXDriver.getWebUXDriver().getBrowser()
					.equalsIgnoreCase(BrowserType.HtmlUnit.getType()))
				return null;
			// Opera has bug after upgrade selenium
			// 2.33.0,https://code.google.com/p/selenium/issues/detail?id=847
			if (WebUXDriver.getWebUXDriver().getBrowser()
					.equalsIgnoreCase(BrowserType.Opera.getType()))
				return null;

			TakesScreenshot screenShot = (TakesScreenshot) driver;
			return screenShot.getScreenshotAs(OutputType.BASE64);
		} catch (Exception ex) {
			// Ignore all exceptions
			ex.printStackTrace();
		}
		return "";
	}

	private String suiteName;
	private String outputDirectory;
	private WebDriver driver;
	private String filename;

	public ScreenshotUtil() {
		suiteName = getSuiteName();
		outputDirectory = getOutputDirectory();
		this.driver = WebUXDriver.getWebDriver();
	}

	public ScreenshotUtil(WebDriver driver) {
		suiteName = getSuiteName();
		outputDirectory = getOutputDirectory();
		this.driver = driver;
	}

	private static String getSuiteName() {
		String suiteName = null;

		suiteName = ContextManager.getGlobalContext().getTestNGContext()
				.getSuite().getName();

		return suiteName;
	}

	private static String getOutputDirectory() {
		String outputDirectory = null;
		outputDirectory = ContextManager.getGlobalContext().getTestNGContext()
				.getOutputDirectory();

		return outputDirectory;
	}

	private void handleSource(String htmlSource, ScreenShot screenShot) {
		if (htmlSource == null) {
			// driver.switchTo().defaultContent();
			htmlSource = driver.getPageSource();
		}

		if (htmlSource != null) {
			try {
				FileHelper.writeToFile(outputDirectory + "/htmls/" + filename
						+ ".html", htmlSource);
				screenShot.setHtmlSourcePath(suiteName + "/htmls/" + filename
						+ ".html");
			} catch (IOException e) {
				logger.warn("Ex", e);
			}

		}
		String rlogId = null;
		String pageId = null;
		try {
			int startIndex = htmlSource.indexOf("RlogId ");
			if (startIndex != -1) {
				int endIndex1 = htmlSource.substring(startIndex).indexOf("-->");
				int endIndex2 = htmlSource.substring(startIndex).indexOf('"');
				int endIndex = 0;
				if (endIndex1 != -1)
					endIndex = endIndex1;
				if (endIndex2 != -1 && endIndex2 < endIndex)
					endIndex = endIndex2;

				if (endIndex != -1) {
					rlogId = htmlSource.substring(startIndex + 7, startIndex
							+ endIndex);
					screenShot.setRlogId(rlogId);
				}
			}
		} catch (Throwable e) {
		}// KEEPME

		// get pageid value on the page source
		try {
			int startIndex = htmlSource.indexOf("GlobalTags:p=");
			if (startIndex != -1) {
				int endIndex1 = htmlSource.substring(startIndex).indexOf(
						"\nGlobalTags:");
				// int endIndex2 =
				// htmlSource.substring(startIndex).indexOf("\nGlobalTags:");
				int endIndex = 0;
				if (endIndex1 != -1)
					endIndex = endIndex1;

				if (endIndex != -1) {
					pageId = htmlSource.substring(startIndex + 13, startIndex
							+ endIndex);
				}
			}
		} catch (Throwable e) {
			e.printStackTrace();
		}// KEEPME

	}

	private void handleImage(ScreenShot screenShot) {
		try {
			String screenshotString = captureEntirePageScreenshotToString(
					WebUXDriver.getWebDriver(), "");

			if (screenshotString != null
					&& !screenshotString.equalsIgnoreCase("")) {
				byte[] byteArray = screenshotString.getBytes();
				FileHelper.writeImage(outputDirectory + "/screenshots/"
						+ filename + ".png", byteArray);
				screenShot.setImagePath(suiteName + "/screenshots/" + filename
						+ ".png");<commit_msg>remove page id logging<commit_after>package com.seleniumtests.driver.web;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.log4j.Logger;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import com.seleniumtests.controller.Context;
import com.seleniumtests.controller.ContextManager;
import com.seleniumtests.controller.Logging;
import com.seleniumtests.exception.WebSessionTerminatedException;
import com.seleniumtests.helper.FileHelper;
import com.seleniumtests.helper.URLHelper;

public class ScreenshotUtil {
	private static final Logger logger = Logger.getLogger(ScreenshotUtil.class);

	public static String captureEntirePageScreenshotToString(WebDriver driver,
			String arg0) {
		if (driver == null)
			return "";
		try {
			// Don't capture snapshot for htmlunit
			if (WebUXDriver.getWebUXDriver().getBrowser()
					.equalsIgnoreCase(BrowserType.HtmlUnit.getType()))
				return null;
			// Opera has bug after upgrade selenium
			// 2.33.0,https://code.google.com/p/selenium/issues/detail?id=847
			if (WebUXDriver.getWebUXDriver().getBrowser()
					.equalsIgnoreCase(BrowserType.Opera.getType()))
				return null;

			TakesScreenshot screenShot = (TakesScreenshot) driver;
			return screenShot.getScreenshotAs(OutputType.BASE64);
		} catch (Exception ex) {
			// Ignore all exceptions
			ex.printStackTrace();
		}
		return "";
	}

	private String suiteName;
	private String outputDirectory;
	private WebDriver driver;
	private String filename;

	public ScreenshotUtil() {
		suiteName = getSuiteName();
		outputDirectory = getOutputDirectory();
		this.driver = WebUXDriver.getWebDriver();
	}

	public ScreenshotUtil(WebDriver driver) {
		suiteName = getSuiteName();
		outputDirectory = getOutputDirectory();
		this.driver = driver;
	}

	private static String getSuiteName() {
		String suiteName = null;

		suiteName = ContextManager.getGlobalContext().getTestNGContext()
				.getSuite().getName();

		return suiteName;
	}

	private static String getOutputDirectory() {
		String outputDirectory = null;
		outputDirectory = ContextManager.getGlobalContext().getTestNGContext()
				.getOutputDirectory();

		return outputDirectory;
	}

	private void handleSource(String htmlSource, ScreenShot screenShot) {
		if (htmlSource == null) {
			// driver.switchTo().defaultContent();
			htmlSource = driver.getPageSource();
		}

		if (htmlSource != null) {
			try {
				FileHelper.writeToFile(outputDirectory + "/htmls/" + filename
						+ ".html", htmlSource);
				screenShot.setHtmlSourcePath(suiteName + "/htmls/" + filename
						+ ".html");
			} catch (IOException e) {
				logger.warn("Ex", e);
			}

		}
		String rlogId = null;
		try {
			int startIndex = htmlSource.indexOf("RlogId ");
			if (startIndex != -1) {
				int endIndex1 = htmlSource.substring(startIndex).indexOf("-->");
				int endIndex2 = htmlSource.substring(startIndex).indexOf('"');
				int endIndex = 0;
				if (endIndex1 != -1)
					endIndex = endIndex1;
				if (endIndex2 != -1 && endIndex2 < endIndex)
					endIndex = endIndex2;

				if (endIndex != -1) {
					rlogId = htmlSource.substring(startIndex + 7, startIndex
							+ endIndex);
					screenShot.setRlogId(rlogId);
				}
			}
		} catch (Throwable e) {
		}// KEEPME

		// get pageid value on the page source
		try {
			int startIndex = htmlSource.indexOf("GlobalTags:p=");
			if (startIndex != -1) {
				int endIndex1 = htmlSource.substring(startIndex).indexOf(
						"\nGlobalTags:");
				// int endIndex2 =
				// htmlSource.substring(startIndex).indexOf("\nGlobalTags:");
				int endIndex = 0;
				if (endIndex1 != -1)
					endIndex = endIndex1;

				if (endIndex != -1) {
				}
			}
		} catch (Throwable e) {
			e.printStackTrace();
		}// KEEPME

	}

	private void handleImage(ScreenShot screenShot) {
		try {
			String screenshotString = captureEntirePageScreenshotToString(
					WebUXDriver.getWebDriver(), "");

			if (screenshotString != null
					&& !screenshotString.equalsIgnoreCase("")) {
				byte[] byteArray = screenshotString.getBytes();
				FileHelper.writeImage(outputDirectory + "/screenshots/"
						+ filename + ".png", byteArray);
				screenShot.setImagePath(suiteName + "/screenshots/" + filename
						+ ".png");
{'fraction_non_alphanumeric': 0.12160919540229885, 'fraction_numerical': 0.007586206896551724, 'mean_word_length': 3.858179787828029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4626121', 'n_tokens_mistral': 3218, 'n_tokens_neox': 2664, 'n_words': 558}