package ru.stqa.sch.addressbook;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

import java.util.concurrent.TimeUnit;
import java.util.Date;
import java.io.File;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.*;
import static org.openqa.selenium.OutputType.*;

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/");
        wd.findElement(By.name("user")).click();
        wd.findElement(By.name("user")).clear();
        wd.findElement(By.name("user")).sendKeys("admin");
        wd.findElement(By.name("pass")).click();
        wd.findElement(By.name("pass")).clear();
        wd.findElement(By.name("pass")).sendKeys("secret");
        wd.findElement(By.xpath("//form[@id='LoginForm']/input[3]")).click();
    }
    
    @Test
    public void testGroupCreationTests() {
        wd.findElement(By.linkText("groups")).click();
        wd.findElement(By.name("new")).click();
        wd.findElement(By.name("group_name")).click();
        wd.findElement(By.name("group_name")).clear();
        wd.findElement(By.name("group_name")).sendKeys("test1");
        wd.findElement(By.name("group_header")).click();
        wd.findElement(By.name("group_header")).clear();
        wd.findElement(By.name("group_header")).sendKeys("header1");
        wd.findElement(By.name("group_footer")).click();
        wd.findElement(By.name("group_footer")).clear();
        wd.findElement(By.name("group_footer")).sendKeys("footer1");
        wd.findElement(By.name("submit")).click();
        wd.findElement(By.linkText("group page")).click();
    }
    
    @AfterMethod
    public void tearDown() {
        wd.quit();
    }
    
    public static boolean isAlertPresent(FirefoxDriver wd) {
        try {
            wd.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }
}

@@ -153,43 +153,8 @@
 est;
-%0Aimport static org.testng.Assert.*;
 %0A%0Aim
@@ -193,147 +193,9 @@
 it;%0A
-import java.util.Date;%0Aimport java.io.File;%0Aimport org.openqa.selenium.support.ui.Select;%0Aimport org.openqa.selenium.interactions.Actions;
 %0A
+
 impo
@@ -273,56 +273,8 @@
 m.*;
-%0Aimport static org.openqa.selenium.OutputType.*;
 %0A%0Apu
@@ -327,21 +327,17 @@
 ver wd;%0A
-    
 %0A
+
     @Bef
@@ -537,24 +537,75 @@
 essbook/%22);%0A
+        login();%0A    %7D%0A%0A    private void login() %7B%0A
         wd.f
@@ -987,29 +987,25 @@
 ck();%0A    %7D%0A
-    
 %0A
+
     @Test%0A  
@@ -1041,24 +1041,209 @@
 onTests() %7B%0A
+        gotoGroupPage();%0A        initGroupCreation();%0A        fillGroupForm();%0A        submitGroupCreation();%0A        returnToGroupPage();%0A    %7D%0A%0A    private void returnToGroupPage() %7B%0A
         wd.f
@@ -1271,17 +1271,21 @@
 t(%22group
-s
+ page
 %22)).clic
@@ -1281,32 +1281,80 @@
 age%22)).click();%0A
+    %7D%0A%0A    private void submitGroupCreation() %7B%0A
         wd.findE
@@ -1369,19 +1369,22 @@
 y.name(%22
-new
+submit
 %22)).clic
@@ -1380,32 +1380,74 @@
 mit%22)).click();%0A
+    %7D%0A%0A    private void fillGroupForm() %7B%0A
         wd.findE
@@ -1967,24 +1967,70 @@
 %22footer1%22);%0A
+    %7D%0A%0A    private void initGroupCreation() %7B%0A
         wd.f
@@ -2041,38 +2041,35 @@
 lement(By.name(%22
-submit
+new
 %22)).click();%0A   
@@ -2057,32 +2057,74 @@
 new%22)).click();%0A
+    %7D%0A%0A    private void gotoGroupPage() %7B%0A
         wd.findE
@@ -2140,37 +2140,33 @@
 .linkText(%22group
- page
+s
 %22)).click();%0A   
@@ -2164,29 +2164,25 @@
 ck();%0A    %7D%0A
-    
 %0A
+
     @AfterMe
@@ -2240,20 +2240,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub

refactor of "testGroupCreationTests " / metods extraction