package pl.stqa.pft.addressbook.appmanager;

import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import pl.stqa.pft.addressbook.model.GroupData;

import java.util.concurrent.TimeUnit;

public class ApplicationManager {
  FirefoxDriver wd;

  public static boolean isAlertPresent(FirefoxDriver wd) {
      try {
          wd.switchTo().alert();
          return true;
      } catch (NoAlertPresentException e) {
          return false;
      }
  }

  public void init() {
    //wd = new FirefoxDriver();
    wd = new FirefoxDriver(new FirefoxOptions().setLegacy(true).setBinary("C:/Program Files/Mozilla Firefox/firefox.exe"));
    wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    wd.get("http://localhost/addressbook/addressbook/group.php");
    login("admin", "secret");
  }

  public void login(String username, String password) {
      wd.findElement(By.name("user")).click();
      wd.findElement(By.name("user")).clear();
      wd.findElement(By.name("user")).sendKeys(username);
      wd.findElement(By.name("pass")).click();
      wd.findElement(By.name("pass")).clear();
      wd.findElement(By.name("pass")).sendKeys(password);
      wd.findElement(By.xpath("//form[@id='LoginForm']/input[3]")).click();
  }

  public void returnToGroupPage() {
      wd.findElement(By.linkText("group page")).click();
  }

  public void submitGroupCreation() {
      wd.findElement(By.name("submit")).click();
  }

  public void fillGroupForm(GroupData groupData) {
      wd.findElement(By.name("group_name")).click();
      wd.findElement(By.name("group_name")).clear();
      wd.findElement(By.name("group_name")).sendKeys(groupData.getName());
      wd.findElement(By.name("group_header")).click();
      wd.findElement(By.name("group_header")).clear();
      wd.findElement(By.name("group_header")).sendKeys(groupData.getHeader());
      wd.findElement(By.name("group_footer")).click();
      wd.findElement(By.name("group_footer")).clear();
      wd.findElement(By.name("group_footer")).sendKeys(groupData.getFooter());
  }

  public void initGroupCreation() {
      wd.findElement(By.name("new")).click();
  }

  public void goToGroupPage() {
      wd.findElement(By.linkText("groups")).click();
  }

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

  public void deleteSelectedGroup() {
      wd.findElement(By.name("delete")).click();
  }

  public void selectGroup() {
      if (!wd.findElement(By.name("selected[]")).isSelected()) {
          wd.findElement(By.name("selected[]")).click();
      }
  }
}

@@ -568,37 +568,40 @@
       %7D%0A  %7D%0A%0A  p
-ublic
+rotected
  void init() %7B%0A 
@@ -920,29 +920,30 @@
 %22);%0A  %7D%0A%0A  p
-ublic
+rivate
  void login(
@@ -1362,29 +1362,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void return
@@ -1463,29 +1463,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void submit
@@ -1558,29 +1558,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void fillGr
@@ -2176,29 +2176,32 @@
 ));%0A  %7D%0A%0A  p
-ublic
+rotected
  void initGr
@@ -2266,29 +2266,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void goToGr
@@ -2359,29 +2359,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void stop()
@@ -2405,29 +2405,32 @@
 ();%0A  %7D%0A%0A  p
-ublic
+rotected
  void delete
@@ -2504,21 +2504,24 @@
   %7D%0A%0A  p
-ublic
+rotected
  void se

Revert "Revert "Revert "change private to public in AppManager"""