package com.example.fw;

import org.openqa.selenium.By;

import com.example.tests.ContactData;

public class ContactHelper extends HelperBase {

	public ContactHelper(ApplicationManager manager) {
		super(manager);
	}

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

	public void fillContactForm(ContactData contact) {
		// name
		type(By.name("firstname"), contact.firstName);
		type(By.name("lastname"), contact.lastName);
		// address
		type(By.name("address"), contact.address);
		// contacts
		type(By.name("home"), contact.homePhone);
	    type(By.name("mobile"), contact.mobilePhone);
	    type(By.name("work"), contact.workPhone);
	    type(By.name("email"), contact.email_1);
	    type(By.name("email2"), contact.email_2);
	    // birth date
		select(By.name("bday"), contact.birthDay);
	    select(By.name("bmonth"), contact.birthMonth);
	    type(By.name("byear"), contact.birthYear);
	    // group
	    select(By.name("new_group"), contact.contactGroup);
	    // extra address
	    type(By.name("address2"), contact.addressSecondary);
	    // extra contact
	    type(By.name("phone2"), contact.phoneSecondary);
	}

	public void returnToHomePage() {
		click(By.linkText("home page"));
	}

	public void initContactEdit(int index) {
		String locator = "//table[@id='maintable']//tr[" + (index + 1) + "]/td/a/img[@title='Edit']";
		click(By.xpath(locator));
	}

	public void submitDeleteContact() {
		click(By.xpath("//input[@value='Delete']"));
	}

	public void submitUpdate() {
		click(By.xpath("//input[@value='Update']"));
	}

}

@@ -29,30 +29,121 @@
 ort 
-org.openqa.selenium.By
+java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.openqa.selenium.By;%0Aimport org.openqa.selenium.WebElement
 ;%0A%0Ai
@@ -1642,10 +1642,805 @@
 ));%0A%09%7D%0A%0A
+%09public List%3CContactData%3E getContacts() %7B%0A%09%09List%3CContactData%3E contacts = new ArrayList%3CContactData%3E();%0A%09%09List%3CWebElement%3E tableRows = driver.findElements(By.xpath(%22//table%5B@id='maintable'%5D/tbody/tr%5B@name='entry'%5D%22));%0A%09%09for (WebElement tableRow : tableRows) %7B%0A%09%09%09ContactData contact = new ContactData();%0A%09%09%09contact.lastName = tableRow.findElement(By.xpath(%22td%5B2%5D%22)).getText();%0A%09%09%09contact.firstName = tableRow.findElement(By.xpath(%22td%5B3%5D%22)).getText();%0A%09%09%09String%5B%5D emails = tableRow.findElement(By.xpath(%22td/input%22)).getAttribute(%22accept%22).split(%22;%22);%0A%09%09%09contact.email_1 = emails.length == 1 ? emails%5B0%5D : null;%0A%09%09%09contact.email_2 = emails.length %3E 1 ? emails%5B1%5D : null;%0A%09%09%09contact.homePhone = tableRow.findElement(By.xpath(%22td%5B5%5D%22)).getText();%0A%09%09%09contacts.add(contact);%0A%09%09%7D%0A%09%09return contacts;%0A%09%7D%0A%0A
 %7D%0A

add method List<ContactData> getContacts()