package first.test;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.*;

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/group.php");
        login("admin", "secret");
    }

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

    @Test
    public void testGroupCreation() {
        gotoGroupPage();
        initGroupCreation();
        fillGroupForm(new GroupData("group1", "test1", "test2"));
        submitGroupCreation();
        returnToGroupPage();
    }

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

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

    private 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.getName1());
        wd.findElement(By.name("group_header")).click();
        wd.findElement(By.name("group_header")).clear();
        wd.findElement(By.name("group_header")).sendKeys(groupData.getName2());
        wd.findElement(By.name("group_footer")).click();
        wd.findElement(By.name("group_footer")).clear();
        wd.findElement(By.name("group_footer")).sendKeys(groupData.getName3());
    }

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

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

@@ -132,24 +132,59 @@
 ations.Test;
+%0Aimport static org.testng.Assert.*;
 %0A%0Aimport jav
@@ -211,16 +211,154 @@
 meUnit;%0A
+import java.util.Date;%0Aimport java.io.File;%0Aimport org.openqa.selenium.support.ui.Select;%0Aimport org.openqa.selenium.interactions.Actions;
 %0Aimport 
@@ -429,16 +429,64 @@
 enium.*;
+%0Aimport static org.openqa.selenium.OutputType.*;
 %0A%0Apublic
@@ -766,108 +766,8 @@
 %22);%0A
-        login(%22admin%22, %22secret%22);%0A    %7D%0A%0A    private void login(String username, String password) %7B%0A
     
@@ -913,16 +913,15 @@
 eys(
-username
+%22admin%22
 );%0A 
@@ -1070,16 +1070,16 @@
 eys(
-password
+%22secret%22
 );%0A 
@@ -1157,24 +1157,28 @@
 ck();%0A    %7D%0A
+    
 %0A    @Test%0A 
@@ -1218,452 +1218,56 @@
 ) %7B%0A
-        gotoGroupPage();%0A        initGroupCreation();%0A        fillGroupForm(new GroupData(%22group1%22, %22test1%22, %22test2%22));%0A        submitGroupCreation();%0A        returnToGroupPage();%0A    %7D%0A%0A    private void returnToGroupPage() %7B%0A        wd.findElement(By.linkText(%22group page%22)).click();%0A    %7D%0A%0A    private void submitGroupCreation() %7B%0A        wd.findElement(By.name(%22submit%22)).click();%0A    %7D%0A%0A    private void fillGroupForm(GroupData groupData) %7B
+%0A        wd.findElement(By.name(%22new%22)).click();
 %0A   
@@ -1432,28 +1432,16 @@
 eys(
+%22
 group
-Data.getName1()
+1%22
 );%0A 
@@ -1614,28 +1614,15 @@
 eys(
-groupData.getName2()
+%22test1%22
 );%0A 
@@ -1795,76 +1795,17 @@
 eys(
-groupData.getName3());%0A    %7D%0A%0A    private void initGroupCreation() %7B
+%22test2%22);
 %0A   
@@ -1825,35 +1825,38 @@
 lement(By.name(%22
-new
+submit
 %22)).click();%0A   
@@ -1856,50 +1856,8 @@
 ();%0A
-    %7D%0A%0A    private void gotoGroupPage() %7B%0A
     
@@ -1893,17 +1893,21 @@
 t(%22group
-s
+ page
 %22)).clic
@@ -1917,16 +1917,20 @@
 ;%0A    %7D%0A
+    
 %0A    @Af

Revert "GroupCreationTests refactored, methods, parameters, parameter object added"