/**
 * Created by artemr on 11/25/2016.
 */

package by.stqa.pft.addressbook.appmanager;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.util.concurrent.TimeUnit;

public class ApplicationManager {
  WebDriver wd;
  private ContactHelper contactHelper;
  private NavigationHelper navigationHelper;
  private GroupHelper groupHelper;
  private SessionHelper sessionHelper;
  private String browser;

  public ApplicationManager(String browser) {
    this.browser = browser;
  }

  public void init() {
    DesiredCapabilities caps = new DesiredCapabilities();
    if (browser == BrowserType.FIREFOX) {
      FirefoxBinary bin = new FirefoxBinary(new File("c:\\Program Files (x86)\\Mozilla Firefox ESR\\firefox.exe"));
      wd = new FirefoxDriver(bin, new FirefoxProfile(), caps);

    } else if (browser == BrowserType.CHROME) {
      wd = new ChromeDriver(caps);
    } else if (browser == BrowserType.IE) {
      wd = new InternetExplorerDriver(caps);
    }

    wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    wd.get("http://localhost/addressbook/");
    groupHelper = new GroupHelper(wd);
    contactHelper = new ContactHelper(wd);
    navigationHelper = new NavigationHelper(wd);
    sessionHelper = new SessionHelper(wd);
    sessionHelper.login("admin", "secret");
  }

  public void stop() {
    wd.quit();
  }

  public GroupHelper getGroupHelper() {
    return groupHelper;
  }

  public NavigationHelper getNavigationHelper() {
    return navigationHelper;
  }

  public ContactHelper getContactHelper() {
    return contactHelper;
  }

  public SessionHelper getSessionHelper() {
    return sessionHelper;
  }

}

@@ -495,24 +495,50 @@
 va.io.File;%0A
+import java.util.Objects;%0A
 import java.
@@ -966,36 +966,40 @@
 %0A    if (browser
- == 
+.equals(
 BrowserType.FIRE
@@ -1002,16 +1002,17 @@
 FIREFOX)
+)
  %7B%0A     
@@ -1200,36 +1200,40 @@
 else if (browser
- == 
+.equals(
 BrowserType.CHRO
@@ -1235,16 +1235,17 @@
 .CHROME)
+)
  %7B%0A     
@@ -1300,12 +1300,16 @@
 wser
- == 
+.equals(
 Brow
@@ -1319,16 +1319,17 @@
 Type.IE)
+)
  %7B%0A     

change == to equals