package ru.sfwt.mt.addressbook.appmanager;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.sfwt.mt.addressbook.model.GroupData;

public class GroupHelper extends HelperBase {

  public GroupHelper(WebDriver wd) {
    super(wd);
  }

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

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

  public void fillGroupForm(GroupData groupData) {
    type("group_name", groupData.getName());
    type("group_header", groupData.getHeader());
    type("group_footer", groupData.getFooter());
  }

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

  public void deleteSelectedGroups() {
    click(By.name("delete"));
  }

  public void selectGroup(int index) {
    wd.findElements(By.name("selected[]")).get(index).click();
  }

  public void initGroupModification() {
    click(By.name("edit"));
  }

  public void submitGroupModification() {
    click(By.name("update"));
  }

  public void createGroup(GroupData group) {
    initGroupCreation();
    fillGroupForm(group);
    submitGroupCreation();
    returnToGroupPage();

  }

  public boolean isThereAGroup() {
    return isElementPresent(By.name("selected[]"));
  }

  public int getGroupCount() {
    return wd.findElements(By.name("selected[]")).size();
  }
}

@@ -102,24 +102,63 @@
 .WebDriver;%0A
+import org.openqa.selenium.WebElement;%0A
 import org.o
@@ -243,16 +243,68 @@
 pData;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -1487,11 +1487,382 @@
 e();%0A  %7D
+%0A%0A  public List%3CGroupData%3E getGroupList() %7B%0A    List%3CGroupData%3E groups = new ArrayList%3CGroupData%3E();%0A    List%3CWebElement%3E elements = wd.findElements(By.cssSelector(%22span.group%22));%0A    for (WebElement element : elements) %7B%0A      String name = element.getText();%0A      GroupData group = new GroupData(name, null, null);%0A      groups.add(group);%0A    %7D%0A    return groups;%0A  %7D
 %0A%7D%0A

Create method List<GroupData> getGroupList() in GroupHelper