package ru.stqa.pft.addressbook;

import org.openqa.selenium.firefox.FirefoxOptions;
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 GroupCreationTest {
    FirefoxDriver wd;
    
    @BeforeMethod
    public void setUp() throws Exception {
        //File pathToBinary = new File("~/Документы/firefox/firefox");
        //wd = new FirefoxDriver();
        wd = new FirefoxDriver(new FirefoxOptions().setLegacy(true).setBinary("/home/user/Документы/firefox/firefox"));
        wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    }
    
    @Test
    public void GroupCreationTest() {
        wd.get("http://localhost/addressbook/index.php");
        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();
        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("group1");
        wd.findElement(By.name("group_header")).click();
        wd.findElement(By.name("group_header")).clear();
        wd.findElement(By.name("group_header")).sendKeys("group11");
        wd.findElement(By.name("group_footer")).click();
        wd.findElement(By.name("group_footer")).clear();
        wd.findElement(By.name("group_footer")).sendKeys("group111");
        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;
        }
    }
}

@@ -204,43 +204,8 @@
 est;
-%0Aimport static org.testng.Assert.*;
 %0A%0Aim
@@ -244,146 +244,8 @@
 it;%0A
-import java.util.Date;%0Aimport java.io.File;%0Aimport org.openqa.selenium.support.ui.Select;%0Aimport org.openqa.selenium.interactions.Actions;
 %0Aimp
@@ -324,56 +324,8 @@
 m.*;
-%0Aimport static org.openqa.selenium.OutputType.*;
 %0A%0Apu
@@ -447,115 +447,8 @@
 n %7B%0A
-        //File pathToBinary = new File(%22~/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%8B/firefox/firefox%22);%0A        //wd = new FirefoxDriver();%0A
     
@@ -640,120 +640,158 @@
     
-%7D%0A    %0A    @Test%0A    public void GroupCreationTest() %7B%0A        wd.get(%22http://localhost/addressbook/index.php%22);
+    wd.get(%22http://localhost/addressbook/index.php%22);%0A        login(%22admin%22, %22secret%22);%0A    %7D%0A%0A    private void login(String username, String passw) %7B
 %0A   
@@ -934,23 +934,24 @@
 endKeys(
-%22admin%22
+username
 );%0A     
@@ -1092,24 +1092,21 @@
 endKeys(
-%22secret%22
+passw
 );%0A     
@@ -1170,32 +1170,268 @@
 %5B3%5D%22)).click();%0A
+    %7D%0A%0A    @Test%0A    public void testGroupCreation() %7B%0A        gotoGroupPage();%0A        initGroupCreation();%0A        fillGroupForm();%0A        submitGroupCreation();%0A        returnGroupPage();%0A    %7D%0A%0A    private void returnGroupPage() %7B%0A
         wd.findE
@@ -1455,17 +1455,21 @@
 t(%22group
-s
+ page
 %22)).clic
@@ -1465,32 +1465,80 @@
 age%22)).click();%0A
+    %7D%0A%0A    private void submitGroupCreation() %7B%0A
         wd.findE
@@ -1553,19 +1553,22 @@
 y.name(%22
-new
+submit
 %22)).clic
@@ -1564,32 +1564,74 @@
 mit%22)).click();%0A
+    %7D%0A%0A    private void fillGroupForm() %7B%0A
         wd.findE
@@ -2153,24 +2153,70 @@
 group111%22);%0A
+    %7D%0A%0A    private void initGroupCreation() %7B%0A
         wd.f
@@ -2227,38 +2227,35 @@
 lement(By.name(%22
-submit
+new
 %22)).click();%0A   
@@ -2243,32 +2243,74 @@
 new%22)).click();%0A
+    %7D%0A%0A    private void gotoGroupPage() %7B%0A
         wd.findE
@@ -2326,37 +2326,33 @@
 .linkText(%22group
- page
+s
 %22)).click();%0A   
@@ -2350,28 +2350,24 @@
 ck();%0A    %7D%0A
-    
 %0A    @AfterM

refactor test group, extract metods