<commit_before>package integration;

import com.codeborne.selenide.SelenideElement;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.executeJavaScript;

public class CollectionWaitTest extends IntegrationTest {
  @Before
  public void openTestPage() {
    openFile("collection_with_delays.html");
  }

  @Test
  public void waitsUntilNthElementAppears() {
    $$("#collection li").get(5).shouldBe(visible);
    $$("#collection li").get(33).shouldBe(visible);
    $$("#collection li").get(49).shouldBe(visible);

    $$("#collection li").first().shouldBe(visible).shouldHave(text("Element #0"));
    $$("#collection li").last().shouldBe(visible).shouldHave(text("Element #49"));
  }

  @Test
  public void reproduceStaleElementException_priorToSelenide33() {
    List<SelenideElement> elements = new ArrayList<>($$("h1"));
    
    executeJavaScript("window.location.reload();");

    elements.get(0).shouldBe(visible).shouldHave(text("Elements will appear soon"));
  }


  @Test(expected = AssertionError.class)
  public void failsIfWrongSize() {
    $$("#collection li").shouldHave(size(-1));
  }

  @Test
  public void canDetermineSize() {
    $$("#collection li").shouldHave(size(50));
  }
}<commit_msg>#696 reload collection elements on every call<commit_after>package integration;

import org.junit.Before;
import org.junit.Test;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$$;

public class CollectionWaitTest extends IntegrationTest {
  @Before
  public void openTestPage() {
    openFile("collection_with_delays.html");
  }

  @Test
  public void waitsUntilNthElementAppears() {
    $$("#collection li").get(5).shouldBe(visible);
    $$("#collection li").get(33).shouldBe(visible);
    $$("#collection li").get(49).shouldBe(visible);

    $$("#collection li").first().shouldBe(visible).shouldHave(text("Element #0"));
    $$("#collection li").last().shouldBe(visible).shouldHave(text("Element #49"));
  }

  @Test(expected = AssertionError.class)
  public void failsIfWrongSize() {
    $$("#collection li").shouldHave(size(-1));
  }

  @Test
  public void canDetermineSize() {
    $$("#collection li").shouldHave(size(50));
  }
}
{'fraction_non_alphanumeric': 0.15691489361702127, 'fraction_numerical': 0.011018237082066869, 'mean_word_length': 5.4376528117359415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6954081', 'n_tokens_mistral': 820, 'n_tokens_neox': 786, 'n_words': 142}