<commit_before>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2017 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.wcm.qa.galenium.verification.element;

import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;

import io.wcm.qa.galenium.interaction.Element;
import io.wcm.qa.galenium.sampling.differences.DifferentiatedDifferences;
import io.wcm.qa.galenium.sampling.differences.SelectorDifference;
import io.wcm.qa.galenium.sampling.differences.StringDifference;
import io.wcm.qa.galenium.selectors.Selector;
import io.wcm.qa.galenium.verification.base.StringVerificationBase;

/**
 * Base class encapsulating common functionality to verify aspects of elements.
 */
abstract class ElementBasedVerification extends StringVerificationBase {

  private WebElement element;
  private Selector selector;
  private int timeout;

  /**
   * @param selector to identify element
   */
  protected ElementBasedVerification(Selector selector) {
    this(selector.elementName(), selector);
  }

  /**
   * @param verificationName name to use for verification
   * @param selector to identify element
   */
  protected ElementBasedVerification(String verificationName, Selector selector) {
    super(verificationName);
    setSelector(selector);
  }

  /**
   * @param verificationName for reporting
   * @param element resolved element
   */
  protected ElementBasedVerification(String verificationName, WebElement element) {
    super(verificationName);
    setElement(element);
  }

  public WebElement getElement() {
    if (element == null) {
      element = Element.find(getSelector(), getTimeout());
    }
    return element;
  }

  /**
   * @return how long to wait in seconds
   */
  public int getTimeout() {<commit_msg>apply cache setting to element<commit_after>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2017 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.wcm.qa.galenium.verification.element;

import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;

import io.wcm.qa.galenium.interaction.Element;
import io.wcm.qa.galenium.sampling.differences.DifferentiatedDifferences;
import io.wcm.qa.galenium.sampling.differences.SelectorDifference;
import io.wcm.qa.galenium.sampling.differences.StringDifference;
import io.wcm.qa.galenium.selectors.Selector;
import io.wcm.qa.galenium.verification.base.StringVerificationBase;

/**
 * Base class encapsulating common functionality to verify aspects of elements.
 */
abstract class ElementBasedVerification extends StringVerificationBase {

  private WebElement element;
  private Selector selector;
  private int timeout;

  /**
   * @param selector to identify element
   */
  protected ElementBasedVerification(Selector selector) {
    this(selector.elementName(), selector);
  }

  /**
   * @param verificationName name to use for verification
   * @param selector to identify element
   */
  protected ElementBasedVerification(String verificationName, Selector selector) {
    super(verificationName);
    setSelector(selector);
  }

  /**
   * @param verificationName for reporting
   * @param element resolved element
   */
  protected ElementBasedVerification(String verificationName, WebElement element) {
    super(verificationName);
    setElement(element);
  }

  public WebElement getElement() {
    if (!isCaching()) {
      element = null;
    }
    if (element == null) {
      element = Element.find(getSelector(), getTimeout());
    }
    return element;
  }

  /**
   * @return how long to wait in seconds
   */
  public int getTimeout() {
{'fraction_non_alphanumeric': 0.0936361688450825, 'fraction_numerical': 0.0034283265481037067, 'mean_word_length': 4.030172413793103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3409059', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1266, 'n_words': 394}