package com.codeborne.selenide.integrationtests;

import com.codeborne.selenide.ex.DialogTextMismatch;
import com.codeborne.selenide.junit.ScreenShooter;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.By;

import java.util.Arrays;
import java.util.List;

import static com.codeborne.selenide.Condition.empty;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.WebDriverRunner.isHeadless;
import static java.lang.Thread.currentThread;
import static org.junit.Assert.fail;

@RunWith(Parameterized.class)
public class ConfirmTest {
  @Parameterized.Parameters
  public static List<Object[]> names() {
    return Arrays.asList(new Object[]{"John McClane"}, new String[]{"Lucie"});
  }

  @Rule
  public ScreenShooter failedTests = ScreenShooter.failedTests();

  private final String userName;

  public ConfirmTest(String userName) {
    this.userName = userName;
  }

  @Before
  public void openTestPage() {
    open(currentThread().getContextClassLoader().getResource("page_with_alerts.html"));
    $("h1").shouldHave(text("Page with alerts"));
    $(By.name("username")).val(userName);
  }

  @Test
  public void canSubmitConfirmDialog() {
    onConfirmReturn(true);
    $(byText("Confirm button")).click();
    confirm("Get out of this page, " + userName + '?');
    $("h1").shouldHave(text("Page with JQuery"));
  }

  @Test
  public void canCancelConfirmDialog() {
    onConfirmReturn(false);
    $(byText("Confirm button")).click();
    dismiss("Get out of this page, " + userName + '?');
    $("#message").shouldHave(text("Stay here, " + userName));
    $("#container").shouldNotBe(empty);
  }

  @Test
  public void selenideChecksDialogText() {
    $(byText("Confirm button")).click();
    try {
      confirm("Get out of this page, Maria?");
    }
    catch (DialogTextMismatch expected) {
      return;
    }
    if (!isHeadless()) {
      fail("Should throw DialogTextMismatch for mismatching text");
    }
  }
}

@@ -648,16 +648,86 @@
 adless;%0A
+import static com.codeborne.selenide.junit.ScreenShooter.failedTests;%0A
 import s
@@ -974,16 +974,17 @@
 %22John Mc
+'
 Clane%22%7D,
@@ -1003,14 +1003,40 @@
 %5D%7B%22L
+ 
 ucie%22%7D
+, new String%5B%5D%7B%22%D0%A1%D0%B5%D1%80%D0%B0%D1%84%D0%B8%D0%BC%22%7D
 );%0A 
@@ -1074,40 +1074,43 @@
 ter 
-failedTests = ScreenShooter.fail
+screenshots = failedTests().succeed
 edTe

Test confirm dialog with cyrillic text