<commit_before>package com.atlassian.webdriver.utils;

import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import java.util.List;


/**
 * Utilities for doing simple checks on a page.
 */
public final class Check
{

    private Check()
    {
        throw new AssertionError(Check.class.getName() + " is not supposed to be instantiated");
    }

    /**
     * Checks that an element that matches the by param exists within another element.
     */
    public static boolean elementExists(By by, SearchContext el)
    {

        try
        {
            el.findElement(by);
        }
        catch (NoSuchElementException e)
        {
            return false;
        }

        return true;
    }

    public static boolean elementIsVisible(By by, SearchContext context)
    {
        try
        {
            WebElement lookFor = context.findElement(by);
            return lookFor.isDisplayed();
        }
        catch (NoSuchElementException e)
        {
            return false;
        }
    }

    public static boolean elementsAreVisible(By by, SearchContext context)
    {
        List<WebElement> elements = context.findElements(by);

        if (elements.size() > 0)
        {
            for (WebElement lookFor : elements)
            {
                if (!lookFor.isDisplayed())
                {
                    return false;
                }
            }

            return true;
        }

        return false;
    }

    /**
     * Checks to see if a specified element contains a specific class of not. The check is case-insensitive.
     *
     * @param className CSS class name to check for
     * @param element element to check
     * @return <code>true</code>, if <tt>element</tt> has CSS class with given <tt>className</tt><commit_msg>SELENIUM-195<commit_after>package com.atlassian.webdriver.utils;

import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.*;

import java.util.List;


/**
 * Utilities for doing simple checks on a page.
 *
 * @since 2.0
 */
public final class Check
{

    private Check()
    {
        throw new AssertionError(Check.class.getName() + " is not supposed to be instantiated");
    }

    /**
     * Checks that an element that matches the by param exists within another element.
     */
    public static boolean elementExists(By by, SearchContext el)
    {
        try
        {
            el.findElement(by);
        }
        catch (NoSuchElementException e)
        {
            return false;
        }
        return true;
    }

    public static boolean elementIsVisible(By by, SearchContext context)
    {
        try
        {
            WebElement lookFor = context.findElement(by);
            return isVisible(lookFor);
        }
        catch (NoSuchElementException e)
        {
            return false;
        }
    }

    public static boolean elementsAreVisible(By by, SearchContext context)
    {
        List<WebElement> elements = context.findElements(by);

        if (elements.size() > 0)
        {
            for (WebElement lookFor : elements)
            {
                if (!isVisible(lookFor))
                {
                    return false;
                }
            }

            return true;
        }

        return false;
    }

    private static boolean isVisible(WebElement webElement)
    {
        try
        {
            return webElement.isDisplayed();
        }
        catch (StaleElementReferenceException e)
        {
            // element got stale since it's been retrieve, just return false naively
            return false;
        }
    }

    /**
     * Checks to see if a specified element contains a specific class of not. The check is case-insensitive.
     *
     * @param className CSS class name to check for
     * @param element element to check
     * @return <code>true</code>, if <tt>element</tt> has CSS class with given <tt>className</tt>
{'fraction_non_alphanumeric': 0.08343588481417671, 'fraction_numerical': 0.0017228648781688408, 'mean_word_length': 1.7969717825189264, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '3146382', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1063, 'n_words': 317}