package jc.sas.adressbook;

import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

public class GroupCreationTests {
    FirefoxDriver wd;

    @BeforeMethod
    public void setUp() throws Exception {
        wd = new FirefoxDriver();
        wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        wd.get("http://localhost/addressbook/");
        login("admin", "secret");
        openGroup();
    }

    @Test
    public void testGroups() {
        createGroup();
        fillGroupData(new GroupData("TestName", "TestHeader", "TestFooter"));
        submit();
        backToGroups();
    }

    private void fillGroupData(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());
    }

    private 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();
    }

    private void backToGroups() {
        wd.findElement(By.linkText("group page")).click();
    }

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

    private void createGroup() {
        wd.findElement(By.name("new")).click();
    }

    private void openGroup() {
        wd.findElement(By.linkText("groups")).click();
    }

    @AfterMethod
    public void tearDown() {
        wd.quit();
    }

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

@@ -605,25 +605,8 @@
 gin(
-%22admin%22, %22secret%22
 );%0A 
@@ -665,32 +665,34 @@
  testGroups() %7B%0A
+%0A%0A
         createGr
@@ -710,755 +710,118 @@
     
-fillGroupData(new GroupData(%22TestName%22, %22TestHeader%22, %22TestFooter%22));%0A        submit();%0A        backToGroups();%0A    %7D%0A%0A    private void fillGroupData(GroupData groupData) %7B%0A        wd.findElement(By.name(%22group_name%22)).click();%0A        wd.findElement(By.name(%22group_name%22)).clear();%0A        wd.findElement(By.name(%22group_name%22)).sendKeys(groupData.getName());%0A        wd.findElement(By.name(%22group_header%22)).click();%0A        wd.findElement(By.name(%22group_header%22)).clear();%0A        wd.findElement(By.name(%22group_header%22)).sendKeys(groupData.getHeader());%0A        wd.findElement(By.name(%22group_footer%22)).click();%0A        wd.findElement(By.name(%22group_footer%22)).clear();%0A        wd.findElement(By.name(%22group_footer%22)).sendKeys(groupData.getFooter()
+typeGroupName();%0A        typeGroupHeader();%0A        typeGroupFooter();%0A        submit();%0A        backToGroups(
 );%0A 
@@ -853,40 +853,8 @@
 gin(
-String username, String password
 ) %7B%0A
@@ -1004,16 +1004,15 @@
 eys(
-username
+%22admin%22
 );%0A 
@@ -1161,16 +1161,16 @@
 eys(
-password
+%22secret%22
 );%0A 
@@ -1431,32 +1431,713 @@
 click();%0A    %7D%0A%0A
+    private void typeGroupFooter() %7B%0A        wd.findElement(By.name(%22group_footer%22)).click();%0A        wd.findElement(By.name(%22group_footer%22)).clear();%0A        wd.findElement(By.name(%22group_footer%22)).sendKeys(%22TestFooter%22);%0A    %7D%0A%0A    private void typeGroupHeader() %7B%0A        wd.findElement(By.name(%22group_header%22)).click();%0A        wd.findElement(By.name(%22group_header%22)).clear();%0A        wd.findElement(By.name(%22group_header%22)).sendKeys(%22TestHeader%22);%0A    %7D%0A%0A    private void typeGroupName() %7B%0A        wd.findElement(By.name(%22group_name%22)).click();%0A        wd.findElement(By.name(%22group_name%22)).clear();%0A        wd.findElement(By.name(%22group_name%22)).sendKeys(%22testGroup%22);%0A    %7D%0A%0A
     private void

Revert "Add parameter object class"