package integration;

import com.automation.remarks.video.annotations.Video;
import org.junit.Before;
import org.junit.Test;

import static com.codeborne.selenide.Condition.name;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.switchTo;
import static com.codeborne.selenide.WebDriverRunner.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeFalse;

public class FrameWaitTest extends IntegrationTest {
  @Before
  public void setUp() {
    openFile("page_with_frames_with_delays.html");
  }

  @Test @Video
  public void waitsUntilFrameAppears_inner() {
    switchTo().innerFrame("parentFrame");
    $("frame").shouldHave(name("childFrame_1"));
  }

  @Test @Video
  public void waitsUntilFrameAppears_byTitle() {
    switchTo().frame("leftFrame");
    $("h1").shouldHave(text("Page with dynamic select"));
  }

  @Test @Video
  public void waitsUntilFrameAppears_byIndex() {
    assumeFalse(isChrome() || isHtmlUnit());

    switchTo().frame(2);
//    assertThat(source(), containsString(isFirefox() || isChrome() ? "Hello, WinRar!" : "This is last frame!"));
    assertThat(source(), containsString("Page with JQuery"));
  }
}

@@ -271,17 +271,17 @@
 elenide.
-$
+*
 ;%0Aimport
@@ -315,25 +315,34 @@
 ide.
-Selenide.switchTo
+WebDriverRunner.isHtmlUnit
 ;%0Aim
@@ -392,17 +392,22 @@
 rRunner.
-*
+source
 ;%0Aimport
@@ -1091,22 +1091,8 @@
 lse(
-isChrome() %7C%7C 
 isHt
@@ -1132,119 +1132,21 @@
 2);%0A
-//
     
-assertThat(source(), containsString(isFirefox() %7C%7C isChrome() ? %22Hello, WinRar!%22 : %22This is last frame!%22)
+sleep(100
 );%0A 

make flaky test more stable