package grid;

import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.WebDriverRunner;
import integration.IntegrationTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.selenium.GridLauncherV3;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.close;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.net.PortProber.findFreePort;

public class SeleniumGridTest extends IntegrationTest {
  @Before
  public void setUp() throws Exception {
    close();
    
    int hubPort = findFreePort();
    GridLauncherV3.main(new String[]{"-port", "" + hubPort});

    GridLauncherV3.main(new String[]{"-port", "" + findFreePort(),
        "-role", "node",
        "-hub", "http://localhost:" + hubPort + "/grid/register"
    });

    Configuration.remote = "http://localhost:" + hubPort + "/wd/hub";
  }

  @Test
  public void canUseSeleniumGrid() {
    openFile("page_with_selects_without_jquery.html");
    $$("#radioButtons input").shouldHave(size(4));
  }

  @After
  public void tearDown() {
    close();
    Configuration.remote = null;
  }
}

@@ -57,55 +57,8 @@
 on;%0A
-import com.codeborne.selenide.WebDriverRunner;%0A
 impo
@@ -380,52 +380,8 @@
 se;%0A
-import static org.junit.Assume.assumeFalse;%0A
 impo

remove unused imports