<commit_before>package im.mange.flakeless.examples

import im.mange.flakeless._
import org.openqa.selenium.{By, WebDriver, WebElement}

object MigrationGuide extends App {
  //given
  val webDriver: WebDriver = ???
  val element: WebElement = ???


  //(1) Replace side effecting actions on webElements e.g. .click(), .sendKeys() with corresponding primitive Click(), SendKeys()

    //e.g.
    element.findElement(By.id("container")).click()
    //becomes
    Click(element, By.id("container"))

    //e.g.
    element.findElement(By.id("container")).sendKeys("foo")
    //becomes
    SendKeys(element, By.id("container"), List("foo"))


  //(2) Replace all state querying on webElements with corresponding assertions

    //e.g.
    element.findElement(By.id("value")).getText == "expected"
    //becomes
    AssertElementTextEquals(element, By.id("value"), "expected")

    //e.g.
    element.findElement(By.id("value")).getText.contains("contains")
    //becomes
    AssertElementTextContains(element, By.id("value"), "contains")


  //(3) Repeat (1) and (2) until there are no usages of .findElement and .findElements

  //(4) Stop holding onto webElements they could be stale, always start from webDriver, if nesting is required use a Path

    //e.g.
    val parentElement = element.findElement(By.id("parent"))
    val childElement = parentElement.findElement(By.id("child"))
    childElement.click()
    //becomes
    val parentPath = Path(By.id("parent"))
    Click(webDriver, parentPath.extend(By.id("child")))
    //or
    Click(webDriver, Path(By.id("parent"), By.id("child")))


  //(5) That's it!

}
<commit_msg>yet more guide ...<commit_after>package im.mange.flakeless.examples

import im.mange.flakeless._
import org.openqa.selenium.{By, WebDriver, WebElement}

object MigrationGuide extends App {
  //given
  val webDriver: WebDriver = ???
  val element: WebElement = ???


  //(1) Replace side effecting actions on webElements e.g. .click(), .sendKeys() with corresponding primitive Click(), SendKeys()

    //unsafe
    element.findElement(By.id("container")).click()
    //safe
    Click(element, By.id("container"))

    //unsafe
    element.findElement(By.id("container")).sendKeys("foo")
    //safe
    SendKeys(element, By.id("container"), List("foo"))


  //(2) Replace all state querying on webElements with corresponding assertions

    //unsafe
    element.findElement(By.id("value")).getText == "expected"
    //safe
    AssertElementTextEquals(element, By.id("value"), "expected")

    //unsafe
    element.findElement(By.id("value")).getText.contains("contains")
    //safe
    AssertElementTextContains(element, By.id("value"), "contains")


  //(3) Repeat (1) and (2) until there are no usages of .findElement and .findElements

  //(4) Stop holding onto webElements they could be stale, always start from webDriver, if nesting is required use a Path

    //unsafe
    val parentElement = element.findElement(By.id("parent"))
    val childElement = parentElement.findElement(By.id("child"))
    childElement.click()
    //safe
    val parentPath = Path(By.id("parent"))
    Click(webDriver, parentPath.extend(By.id("child")))
    //or
    Click(webDriver, Path(By.id("parent"), By.id("child")))


  //(5) That's it!

}

{'fraction_non_alphanumeric': 0.15519360786724032, 'fraction_numerical': 0.0043023970497848806, 'mean_word_length': 3.6433666191155494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '532941', 'n_tokens_mistral': 1050, 'n_tokens_neox': 991, 'n_words': 249}