package info.bowkett.joxy.stepdefs;

import cucumber.api.PendingException;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Before;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 * Created by IntelliJ IDEA.
 * User: jbowkett
 * Date: Jul 22, 2013
 * Time: 10:22:24 AM
 * To change this template use File | Settings | File Templates.
 */
public class ServerStartupStepDefs {


  protected WebDriver driver = new ChromeDriver();

//    @Before
//    public void setUp() {
//        driver = new ChromeDriver();
//    }


  @Given("^a joxy server is started$")
  public void a_joxy_server_is_started() throws Throwable {
    // Express the Regexp above with the code you wish you had
//        throw new PendingException();
  }

  @Given("^a web browser configured to use joxy$")
  public void a_web_browser_configured_to_use_joxy() throws Throwable {
    // Express the Regexp above with the code you wish you had
//        throw new PendingException();
  }

  @When("^I navigate to a website$")
  public void I_navigate_to_a_website() throws Throwable {
    // Express the Regexp above with the code you wish you had
    driver.get("http://www.google.co.uk");
  }

  @Then("^I will see that website in the browser$")
  public void I_will_see_that_website_in_the_browser() throws Throwable {
    final String title = driver.getTitle();
    System.out.println("title = " + title);
    // Express the Regexp above with the code you wish you had
//        throw new PendingException();
  }

  @After
  public void tearDown() {
    driver.close();
  }


}

@@ -34,46 +34,8 @@
 s;%0A%0A
-import cucumber.api.PendingException;%0A
 impo
@@ -58,24 +58,24 @@
 java.After;%0A
+
 import cucum
@@ -161,24 +161,57 @@
 va.en.When;%0A
+import info.bowkett.joxy.Server;%0A
 import org.j
@@ -215,22 +215,22 @@
 g.junit.
-Before
+Assert
 ;%0Aimport
@@ -308,16 +308,97 @@
 eDriver;
+%0Aimport org.openqa.selenium.remote.DesiredCapabilities;%0A%0Aimport java.util.Arrays;
 %0A%0A/**%0A *
@@ -601,15 +601,13 @@
   pr
-otec
+iva
 te
-d
  Web
@@ -619,37 +619,94 @@
 r driver
- = new ChromeDriver()
+;%0A  private Server server;%0A  private static final int PROXY_SERVER_PORT = 4443
 ;%0A%0A//   
@@ -898,103 +898,64 @@
     
-// Express the Regexp above with the code you wish you had%0A//        throw new PendingException
+server = new Server(PROXY_SERVER_PORT);%0A    server.start
 ();%0A
@@ -1090,103 +1090,230 @@
     
-// Express the Regexp above with the code you wish you had%0A//        throw new PendingException
+final DesiredCapabilities capabilities = DesiredCapabilities.chrome();%0A    capabilities.setCapability(%22chrome.switches%22, Arrays.asList(%22--proxy-server=http://localhost:%22 + PROXY_SERVER_PORT));%0A    driver = new ChromeDriver
 ();%0A
@@ -1417,71 +1417,8 @@
 e %7B%0A
-    // Express the Regexp above with the code you wish you had%0A
     
@@ -1639,148 +1639,129 @@
     
-System.out.println(%22title = %22 + title);%0A    // Express the Regexp above with the code you wish you had%0A//        throw new PendingException(
+//todo: need a much better assertion here - document not null, or check the specific title%0A    Assert.assertNotNull(title
 );%0A 
@@ -1820,16 +1820,14 @@
 lose();%0A
+
   %7D%0A
-%0A%0A
 %7D%0A

add startup server