package ru.stqa.addressbook.appmanager;

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

import java.util.concurrent.TimeUnit;

/**
 * Created by user on 05.05.2016.
 */
public class ApplicationManager {

    private final String browser;
    WebDriver wd;

    private SessionHelper sessionHelper;
    private NavigationHelper navigationHelper;
    private ContactHelper contactHelper;

    private GroupHelper groupHelper;

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

    public void init() {
        if (browser == BrowserType.FIREFOX){
            wd = new FirefoxDriver();
        } else if (browser == BrowserType.CHROME) {
            wd = new ChromeDriver();
        } else if (browser == BrowserType.IE) {
            wd = new InternetExplorerDriver();
        }

        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 ContactHelper getContactHelper() {
        return contactHelper;
    }

    public NavigationHelper getNavigationHelper() {
        return navigationHelper;
    }
}

@@ -272,16 +272,42 @@
 rType;%0A%0A
+import java.util.Objects;%0A
 import j
@@ -754,32 +754,47 @@
 %0A        if 
+(Objects.equals
 (browser
  == BrowserT
@@ -773,35 +773,33 @@
 s.equals(browser
- ==
+,
  BrowserType.FIR
@@ -803,16 +803,17 @@
 FIREFOX)
+)
 %7B%0A      
@@ -858,32 +858,47 @@
   %7D else if 
+(Objects.equals
 (browser
  == BrowserT
@@ -877,35 +877,33 @@
 s.equals(browser
- ==
+,
  BrowserType.CHR
@@ -906,16 +906,17 @@
 .CHROME)
+)
  %7B%0A     
@@ -965,24 +965,39 @@
 else if 
+(Objects.equals
 (browser
  == Brow
@@ -992,11 +992,9 @@
 wser
- ==
+,
  Bro
@@ -1005,16 +1005,17 @@
 Type.IE)
+)
  %7B%0A     

Add crossbrowsing2