<commit_before>package com.stratio.data;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;

import com.google.common.collect.Lists;

public class BrowsersDataProvider {

    @DataProvider(parallel = true)
    public static Iterator<String[]> availableBrowsers(ITestContext context, Constructor<?> testConstructor)
            throws Exception {

        ArrayList<String> browsers = gridBrowsers();
        List<String[]> lData = Lists.newArrayList();

        for (String s : browsers) {
            lData.add(new String[] { s });
        }

        if (lData.size() == 0) {
            lData.add(new String[] { "" });
        }

        return lData.iterator();
    }

    private static ArrayList<String> gridBrowsers() throws IOException {
        ArrayList<String> response = new ArrayList<String>();

        String grid = System.getProperty("SELENIUM.GRID", "127.0.0.1:4444");
        grid = "http://" + grid + "/grid/console";
        Document doc = Jsoup.connect(grid).timeout(20000).get();

        Elements slaves = (Elements) doc.select("div.proxy");

        for (Element slave : slaves) {
            String slaveStatus = slave.select("p.proxyname").first().text();
            if (!slaveStatus.contains("Connection") && !slaveStatus.contains("Conexión")) {
                Integer iBusy = 0;
                Elements browserList = slave.select("div.content_detail").select("*[title]");
                Elements busyBrowserList = slave.select("div.content_detail").select("p > .busy");
                for (Element browserDetails : browserList) {
                    if (browserDetails.attr("title").startsWith("{")) {
                        Pattern pat = Pattern.compile("browserName=(.*?),.*?(version=(.*?))?}");<commit_msg>Thrown exception if no selenium grid can be found<commit_after>package com.stratio.data;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;

import com.google.common.collect.Lists;

public class BrowsersDataProvider {

    private static final Logger logger = LoggerFactory.getLogger(BrowsersDataProvider.class);

    @DataProvider(parallel = true)
    public static Iterator<String[]> availableBrowsers(ITestContext context, Constructor<?> testConstructor)
            throws Exception {

        ArrayList<String> browsers = gridBrowsers();
        List<String[]> lData = Lists.newArrayList();

        for (String s : browsers) {
            lData.add(new String[] { s });
        }

        if (lData.size() == 0) {
            lData.add(new String[] { "" });
        }

        return lData.iterator();
    }

    private static ArrayList<String> gridBrowsers() {
        ArrayList<String> response = new ArrayList<String>();

        String grid = System.getProperty("SELENIUM.GRID", "127.0.0.1:4444");
        grid = "http://" + grid + "/grid/console";
        Document doc;
        try {
            doc = Jsoup.connect(grid).timeout(20000).get();
        } catch (IOException e) {
            logger.error("Exception on connecting to Selenium grid: {}", e.getMessage());
            return response;
        }

        Elements slaves = (Elements) doc.select("div.proxy");

        for (Element slave : slaves) {
            String slaveStatus = slave.select("p.proxyname").first().text();
            if (!slaveStatus.contains("Connection") && !slaveStatus.contains("Conexión")) {
                Integer iBusy = 0;
                Elements browserList = slave.select("div.content_detail").select("*[title]");
                Elements busyBrowserList = slave.select("div.content_detail").select("p > .busy");
                for (Element browserDetails : browserList) {
                    if (browserDetails.attr("title").startsWith("{")) {
                        Pattern pat = Pattern.compile("browserName=(.*?),.*?(version=(.*?))?}");
{'fraction_non_alphanumeric': 0.1382219338092148, 'fraction_numerical': 0.007787151200519144, 'mean_word_length': 2.9054054054054053, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4438213', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1282, 'n_words': 269}